Changeset 1102
- Timestamp:
- 05/10/18 16:04:51 (6 years ago)
- Location:
- trunk
- Files:
-
- 209 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/apollo/ApolloSystem.java
r1040 r1102 1 1 package org.apollo; 2 2 3 import java.awt.Image;4 import java.awt.Toolkit;5 import java.awt.event.WindowEvent;6 import java.awt.event.WindowListener;7 import java.net.URL;8 3 import java.util.Collection; 9 4 import java.util.HashSet; 10 5 import java.util.Set; 11 6 12 import javax.swing.SwingUtilities;13 7 import javax.swing.UIManager; 14 8 … … 29 23 import org.apollo.widgets.FramePlayer; 30 24 import org.expeditee.actions.Actions; 25 import org.expeditee.core.BlockingRunnable; 26 import org.expeditee.gio.EcosystemManager; 27 import org.expeditee.gio.EcosystemManager.Ecosystem; 28 import org.expeditee.gio.GraphicsManager; 29 import org.expeditee.gio.InputManager.WindowEventListener; 30 import org.expeditee.gio.InputManager.WindowEventType; 31 31 import org.expeditee.gui.Browser; 32 32 import org.expeditee.gui.Frame; 33 33 import org.expeditee.gui.FrameIO; 34 import org.expeditee.gui.FrameKeyboardActions;35 import org.expeditee.gui.FrameMouseActions;36 34 import org.expeditee.settings.UserSettings; 37 import org.expeditee.importer.FrameDNDTransferHandler;38 35 import org.expeditee.items.Item; 39 36 import org.expeditee.items.Text; … … 47 44 public final class ApolloSystem { 48 45 46 private static final String APOLLO_ICON = "org/apollo/icons/mainicon.png"; 47 49 48 // TODO: Create actual frames 50 49 public static final String SYSTEM_FRAMESET_NAME = "apollosystem"; 51 50 public static final String HELP_TOP_FRAMENAME = SYSTEM_FRAMESET_NAME + 2; 52 51 53 //TODO: How to get good results: collection (moteef) and querry52 // TODO: How to get good results: collection (moteef) and querry 54 53 // TODO: How to omit indexing on tracks 55 54 public static final String HELP_MELODYSEARCH_FRAMENAME = SYSTEM_FRAMESET_NAME + 3; … … 58 57 public static final String SETTINGS_NAME_TIMELINE_LMARGIN = "timelineleftmargin"; 59 58 60 61 62 59 public static boolean useQualityGraphics = true; 63 64 private ApolloSystem() {65 }66 60 67 61 private static boolean hasInitialized = false; 68 62 63 private ApolloSystem() 64 { 65 } 66 69 67 /** 70 68 * Initializes Apollo mod for expeditee - prepares all subsystems. 71 69 */ 72 public static void initialize() {73 70 public static void initialize() 71 { 74 72 if (hasInitialized) return; 75 73 76 74 ApolloSystemLog.println("Initializing..."); 77 78 SwingUtilities.invokeLater(new Runnable() { 79 public void run() { 80 81 try { 82 83 URL url = ClassLoader.getSystemResource("org/apollo/icons/mainicon.png"); 84 85 if (url != null) { 86 Image img = Toolkit.getDefaultToolkit().getImage(url); 87 Browser._theBrowser.setIconImage(img); 88 } 89 90 91 92 } catch (Exception e) { 93 e.printStackTrace(); 94 } 95 96 // Ensure that resources are released before the application is closed. 97 Browser._theBrowser.addWindowListener(new WindowListener() { 98 99 public void windowActivated(WindowEvent e) { 100 } 101 102 public void windowClosed(WindowEvent e) { 103 } 104 105 public void windowClosing(WindowEvent e) { 106 ApolloSystem.shutdown(); 107 } 108 109 public void windowDeactivated(WindowEvent e) { 110 } 111 112 public void windowDeiconified(WindowEvent e) { 113 } 114 115 public void windowIconified(WindowEvent e) { 116 } 117 118 public void windowOpened(WindowEvent e) { 119 } 120 121 }); 122 123 Browser._theBrowser.getContentPane().removeKeyListener(FrameKeyboardActions.getInstance()); 124 Browser._theBrowser.removeKeyListener(FrameKeyboardActions.getInstance()); 125 126 Browser._theBrowser.getContentPane().addKeyListener(new AudioFrameKeyboardActions()); 127 Browser._theBrowser.addKeyListener(new AudioFrameKeyboardActions()); 128 129 // Filter out some special mouse move cases 130 AudioFrameMouseActions apolloMouseFilter = new AudioFrameMouseActions(); 131 Browser._theBrowser.getMouseEventRouter().removeExpediteeMouseMotionListener( 132 FrameMouseActions.getInstance()); 133 Browser._theBrowser.getMouseEventRouter().addExpediteeMouseMotionListener(apolloMouseFilter); 134 135 Browser._theBrowser.getMouseEventRouter().removeExpediteeMouseListener( 136 FrameMouseActions.getInstance()); 137 Browser._theBrowser.getMouseEventRouter().addExpediteeMouseListener(apolloMouseFilter); 75 76 // Ensure that resources are released before the application is closed. 77 EcosystemManager.getInputManager().addWindowEventListener(new WindowEventListener() { 78 @Override 79 public void onWindowEvent(WindowEventType type) 80 { 81 if (type != WindowEventType.WINDOW_CLOSED) return; 82 ApolloSystem.shutdown(); 138 83 } 139 84 }); 85 86 EcosystemManager.getInputManager().registerGestureListener(ApolloGestureActions.getInstance()); 87 EcosystemManager.getInputManager().addInputEventToGestureTranslator(new ApolloKBMGestureTranslator()); 140 88 141 89 // Set title … … 161 109 162 110 // Setup for importing audio 163 FrameDNDTransferHandler.getInstance().addCustomFileImporter( 164 new SampledAudioFileImporter()); 111 EcosystemManager.getDragAndDropManager().addCustomFileImporter(new SampledAudioFileImporter()); 165 112 166 113 ApolloSystemLog.println(" Loading actions and agents..."); … … 202 149 * When invoked, the apollo setting frame is loaded and parsed... setting apollo-specific settings. 203 150 */ 204 public static void loadSettings() {205 151 public static void loadSettings() 152 { 206 153 // Load apollo settings frame from the default profile 207 154 Frame profile = FrameIO.LoadProfile(UserSettings.DEFAULT_PROFILE_NAME); … … 241 188 } 242 189 243 private static Mutable.Integer stripNameValueStringInteger(String namevalue) { 190 private static Mutable.Integer stripNameValueStringInteger(String namevalue) 191 { 244 192 assert (namevalue != null); 245 193 int valueIndex = namevalue.indexOf(':') + 1; … … 259 207 * Releases all resources currently used by the SampledAudioManager. 260 208 */ 261 public static void shutdown() {262 209 public static void shutdown() 210 { 263 211 ApolloSystemLog.println("Saving banks..."); 264 212 SoundDesk.getInstance().saveMasterMix(); … … 280 228 * True if has initialized. 281 229 */ 282 public static boolean isInitialized() { 230 public static boolean isInitialized() 231 { 283 232 return hasInitialized; 284 233 } … … 294 243 * @param args 295 244 */ 296 public static void main(String[] args) { 297 298 try { 299 UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); 300 } 301 catch (Exception e) { 302 e.printStackTrace(); 303 return; 304 } 245 public static void main(String[] args) 246 { 247 if (Browser.ECOSYSTEM_TYPE == Ecosystem.Swing) { 248 try { 249 UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); 250 } catch (Exception e) { 251 e.printStackTrace(); 252 return; 253 } 254 } 255 256 // Window icon must be set before initialisation 257 GraphicsManager.setWindowIcon(APOLLO_ICON); 305 258 306 259 // Run expeditee … … 308 261 309 262 // Initialize apollo 310 SwingUtilities.invokeLater(newRunnable() {311 public void run() {263 EcosystemManager.getMiscManager().runOnGIOThread(new BlockingRunnable() { 264 public void execute() { 312 265 ApolloSystem.initialize(); 313 266 } -
trunk/src/org/apollo/ApolloSystemApplet.java
r489 r1102 3 3 import java.io.File; 4 4 5 import java.awt.*;6 5 import java.awt.event.ActionEvent; 7 6 import java.awt.event.ActionListener; -
trunk/src/org/apollo/AudioFrameKeyboardActions.java
r489 r1102 25 25 import org.expeditee.items.Item; 26 26 import org.expeditee.items.Line; 27 import org.expeditee.items.Permission;28 27 import org.expeditee.items.Text; 29 28 import org.expeditee.items.Item.HighlightMode; -
trunk/src/org/apollo/AudioFrameMouseActions.java
r366 r1102 73 73 FrameMouseActions.MouseY = e.getY(); 74 74 75 } else if (isSnapOn() && 76 !FreeItems.getInstance().isEmpty()) { 75 } else if (isSnapOn() && !FreeItems.getInstance().isEmpty()) { 77 76 78 77 // Couse movement of free items: Restraining left-most pixel in items … … 222 221 223 222 if (firstInitTime == null) { 224 firstInitTime = Mutable.createMutableLong(it.value); // Important to cre wate new instance223 firstInitTime = Mutable.createMutableLong(it.value); // Important to create new instance 225 224 } else if (it.value < firstInitTime.value) { 226 firstInitTime = Mutable.createMutableLong(it.value); // Important to cre wate new instance225 firstInitTime = Mutable.createMutableLong(it.value); // Important to create new instance 227 226 } 228 227 } -
trunk/src/org/apollo/actions/ApolloActions.java
r363 r1102 4 4 import org.apollo.widgets.LinkedTrack; 5 5 import org.apollo.widgets.SampleRecorder; 6 import org.expeditee.gui.DisplayIO; 6 import org.expeditee.gio.gesture.StandardGestureActions; 7 import org.expeditee.gui.DisplayController; 7 8 import org.expeditee.gui.Frame; 8 import org.expeditee.gui.FrameMouseActions;9 9 import org.expeditee.items.Text; 10 10 … … 17 17 public class ApolloActions { 18 18 19 private ApolloActions() {} // Util construction 19 /** Static-only class. */ 20 private ApolloActions() 21 { 22 } 20 23 21 /** 22 * Attatches a new recorder to the cursor 23 */ 24 public static void spawnRecorder() { 25 26 Frame target = DisplayIO.getCurrentFrame(); 24 /** Attaches a new recorder to the cursor. */ 25 public static void spawnRecorder() 26 { 27 Frame target = DisplayController.getCurrentFrame(); 27 28 if (target == null) return; 28 29 … … 30 31 Text source = new Text(target.getNextItemID()); 31 32 source.setParent(target); 32 source.setPosition( FrameMouseActions.MouseX, FrameMouseActions.MouseY);33 source.setPosition(DisplayController.getMousePosition()); 33 34 SampleRecorder recWidget = new SampleRecorder(source, null); 34 35 35 36 // Pick it up 36 FrameMouseActions.pickup(recWidget.getItems());37 StandardGestureActions.pickup(recWidget.getItems()); 37 38 } 38 39 … … 42 43 public static void spawnLinkedTrack() { 43 44 44 Frame target = Display IO.getCurrentFrame();45 Frame target = DisplayController.getCurrentFrame(); 45 46 if (target == null) return; 46 47 … … 48 49 Text source = new Text(target.getNextItemID()); 49 50 source.setParent(target); 50 source.setPosition( FrameMouseActions.MouseX, FrameMouseActions.MouseY);51 source.setPosition(DisplayController.getMousePosition()); 51 52 52 53 LinkedTrack ltWidget = new LinkedTrack(source, null); 53 54 54 55 // Pick it up 55 FrameMouseActions.pickup(ltWidget.getItems());56 StandardGestureActions.pickup(ltWidget.getItems()); 56 57 } 57 58 … … 64 65 // Create the launcher 65 66 FramePlaybackLauncher launcher = new FramePlaybackLauncher(null); 66 launcher.setPosition( FrameMouseActions.MouseX, FrameMouseActions.MouseY);67 launcher.setPosition(DisplayController.getMousePosition()); 67 68 68 69 // Pick it up 69 FrameMouseActions.pickup(launcher);70 StandardGestureActions.pickup(launcher); 70 71 } 71 72 -
trunk/src/org/apollo/agents/MelodySearch.java
r903 r1102 1 1 package org.apollo.agents; 2 2 3 import java.awt.Color;4 3 import java.io.File; 5 4 import java.io.FileNotFoundException; … … 10 9 11 10 import javax.sound.sampled.AudioFormat; 12 import javax.swing.SwingUtilities;13 11 14 12 import org.apollo.ApolloSystem; … … 26 24 import org.apollo.widgets.TrackWidgetCommons; 27 25 import org.expeditee.agents.SearchAgent; 26 import org.expeditee.core.Colour; 27 import org.expeditee.gui.DisplayController; 28 28 import org.expeditee.gui.Frame; 29 import org.expeditee.gui.FrameGraphics;30 29 import org.expeditee.gui.FrameIO; 31 import org.expeditee.settings.UserSettings;32 30 import org.expeditee.settings.folders.FolderSettings; 33 31 import org.expeditee.items.Item; 34 32 import org.expeditee.items.ItemUtils; 35 import org.expeditee.items.widgets. InteractiveWidget;33 import org.expeditee.items.widgets.Widget; 36 34 import org.expeditee.items.widgets.WidgetCorner; 37 35 import org.expeditee.items.widgets.WidgetEdge; … … 42 40 * Uses meldex. Thanks David Bainbridge. 43 41 * 44 * The agent runs a quer ry on the given track widget that launched it.42 * The agent runs a query on the given track widget that launched it. 45 43 * If the track launches it it does a full search for all tracks on the current frameset. 46 44 * … … 96 94 */ 97 95 @Override 98 public boolean initialise(Frame frame, Item item) { 96 public boolean initialise(Frame frame, Item item) 97 { 99 98 if (!super.initialise(frame, item)) return false; 100 99 … … 104 103 if (item != null) { 105 104 106 InteractiveWidget iw = null;105 Widget iw = null; 107 106 108 107 if (item instanceof WidgetCorner) { … … 162 161 163 162 if (querryMelody == null) { // abort - failed to get audio 164 SwingUtilities.invokeLater(new ExpediteeMessageBayFeedback( 165 "Melody search aborted: Failed to load tracks audio")); 163 overwriteMessage("Melody search aborted: Failed to load tracks audio"); 166 164 _results.addText("Melody search aborted: querry data not good enough to search with", 167 Colo r.RED, null, null, false);165 Colour.RED, null, null, false); 168 166 _results.addText("Click here for help on melody searches", 169 new Color(0, 180, 0), ApolloSystem.HELP_MELODYSEARCH_FRAMENAME, null, false);167 Colour.FromRGB255(0, 180, 0), ApolloSystem.HELP_MELODYSEARCH_FRAMENAME, null, false); 170 168 171 169 _results.save(); … … 186 184 187 185 if (querryMelody == null) { // abort - failed to get audio 188 SwingUtilities.invokeLater(new ExpediteeMessageBayFeedback( 189 "Melody search aborted: Failed to proccess querry data")); 190 _results.addText("Melody search aborted: querry data not good enough to search with", Color.RED, null, null, false); 186 overwriteMessage("Melody search aborted: Failed to proccess querry data"); 187 _results.addText("Melody search aborted: querry data not good enough to search with", Colour.RED, null, null, false); 191 188 _results.addText("Click here for help on melody searches", 192 new Color(0, 180, 0), ApolloSystem.HELP_MELODYSEARCH_FRAMENAME, null, false);189 Colour.FromRGB255(0, 180, 0), ApolloSystem.HELP_MELODYSEARCH_FRAMENAME, null, false); 193 190 _results.save(); 194 191 return null; … … 240 237 if(!results.isEmpty()) { 241 238 _results.addText(frameName + "(" + results.size() + ")", null, frameName, null, false); 242 FrameGraphics.requestRefresh(true);239 DisplayController.requestRefresh(true); 243 240 } 244 241 … … 395 392 396 393 if (melodyScores.isEmpty() || melodyScores.get(0).getScore() > threshold) { 397 _results.addText("No matches", Colo r.RED, null, null, false);394 _results.addText("No matches", Colour.RED, null, null, false); 398 395 _results.addText("Click here to find out how to improve your melody searches", 399 new Color(0, 180, 0), ApolloSystem.HELP_MELODYSEARCH_FRAMENAME, null, false);396 Colour.FromRGB255(0, 180, 0), ApolloSystem.HELP_MELODYSEARCH_FRAMENAME, null, false); 400 397 } else { 401 398 … … 426 423 427 424 if (_stop) { 428 _results.addText("Search cancelled", Colo r.RED, null, null, false);425 _results.addText("Search cancelled", Colour.RED, null, null, false); 429 426 } 430 427 … … 444 441 445 442 } 446 447 448 449 443 450 444 /** … … 470 464 471 465 } 472 473 /**474 * Safely outputs a message on the messagebay .. if ran on swing thread.475 * @author Brook Novak476 *477 */478 private class ExpediteeMessageBayFeedback implements Runnable {479 480 String feedbackMessage;481 482 public ExpediteeMessageBayFeedback(String feedbackMessage) {483 assert(feedbackMessage != null);484 this.feedbackMessage = feedbackMessage;485 }486 487 488 public void run() {489 assert(feedbackMessage != null);490 overwriteMessage(feedbackMessage);491 }492 }493 494 495 466 } -
trunk/src/org/apollo/agents/MelodySearchResult.java
r315 r1102 1 1 package org.apollo.agents; 2 3 2 4 3 /** -
trunk/src/org/apollo/audio/ApolloSubjectChangedEvent.java
r367 r1102 9 9 public final class ApolloSubjectChangedEvent { 10 10 11 private ApolloSubjectChangedEvent() {} 11 private ApolloSubjectChangedEvent() 12 { 13 } 12 14 13 15 public static final int INPUT_MIXER = 1; -
trunk/src/org/apollo/audio/AudioFormatNotSupportedException.java
r315 r1102 6 6 * @author Brook Novak 7 7 */ 8 public class AudioFormatNotSupportedException extends Exception { 8 public class AudioFormatNotSupportedException extends Exception 9 { 9 10 protected static final long serialVersionUID = 0L; 10 11 11 public AudioFormatNotSupportedException() { 12 public AudioFormatNotSupportedException() 13 { 12 14 super(); 13 15 } 14 16 15 public AudioFormatNotSupportedException(String message) { 17 public AudioFormatNotSupportedException(String message) 18 { 16 19 super(message); 17 20 } 18 21 19 public AudioFormatNotSupportedException(String message, Exception inner) { 22 public AudioFormatNotSupportedException(String message, Exception inner) 23 { 20 24 super(message, inner); 21 25 } -
trunk/src/org/apollo/audio/Metronome.java
r332 r1102 20 20 * 21 21 */ 22 public class Metronome extends AbstractSubject { 22 public class Metronome extends AbstractSubject 23 { 23 24 24 25 private Receiver receiver = null; -
trunk/src/org/apollo/audio/RecordManager.java
r332 r1102 19 19 * 20 20 */ 21 public class RecordManager extends AbstractSubject {22 21 public class RecordManager extends AbstractSubject 22 { 23 23 private AudioCaptureThread captureThread = null; 24 24 -
trunk/src/org/apollo/audio/TrackSequence.java
r365 r1102 16 16 * 17 17 */ 18 public final class TrackSequence extends AbstractSubject implements Comparable {18 public final class TrackSequence extends AbstractSubject implements Comparable<TrackSequence> { 19 19 20 20 /** FRIENDLY: ONLY TO BE ACCESSED BY AUDIO MIXER. */ … … 159 159 * Order ascending by initiation frame 160 160 */ 161 public final int compareTo(Object o) { 162 TrackSequence other = (TrackSequence)o; // throws class cast exception 163 161 public final int compareTo(TrackSequence other) 162 { 164 163 int cmp = (new Long(initiationFrame)).compareTo(other.initiationFrame); 165 164 166 165 if (cmp == 0) { 167 168 166 return (new Integer(hashCode()).compareTo(other.hashCode())); 169 167 } -
trunk/src/org/apollo/audio/structure/AudioStructureModel.java
r903 r1102 3 3 import java.io.FileNotFoundException; 4 4 import java.io.IOException; 5 import java.lang.reflect.InvocationTargetException;6 5 import java.util.HashMap; 7 6 import java.util.HashSet; … … 14 13 15 14 import javax.sound.sampled.UnsupportedAudioFileException; 16 import javax.swing.SwingUtilities;17 15 18 16 import org.apollo.audio.ApolloSubjectChangedEvent; … … 27 25 import org.apollo.widgets.SampledTrack; 28 26 import org.apollo.widgets.TrackWidgetCommons; 29 import org.expeditee.gui.DisplayIO; 27 import org.expeditee.core.BlockingRunnable; 28 import org.expeditee.gio.EcosystemManager; 29 import org.expeditee.gui.DisplayController; 30 30 import org.expeditee.gui.Frame; 31 import org.expeditee.gui.FrameGraphics;32 31 import org.expeditee.gui.FrameIO; 33 import org.expeditee.settings.UserSettings;34 32 import org.expeditee.io.Conversion; 35 33 import org.expeditee.items.ItemUtils; 36 import org.expeditee.items.widgets. InteractiveWidget;34 import org.expeditee.items.widgets.Widget; 37 35 import org.expeditee.settings.folders.FolderSettings; 38 36 39 37 /** 40 * A thread safe model of the h eirarchical structure of a track graph...38 * A thread safe model of the hierarchical structure of a track graph... 41 39 * abstracted from Expeditee frames and audio widgets. 42 40 * 43 * The track widgets notif ty this model for keeping the structure consistent with44 * expeditees data.41 * The track widgets notify this model for keeping the structure consistent with 42 * Expeditee's data. 45 43 * 46 44 * … … 199 197 NewGraphCommitor commit = new NewGraphCommitor(rootODFrame, newGraph); 200 198 try { 201 SwingUtilities.invokeAndWait(commit);202 } catch ( InvocationTargetException e) {199 EcosystemManager.getMiscManager().runOnGIOThread(commit); 200 } catch (Exception e) { 203 201 e.printStackTrace(); 204 202 assert(false); … … 264 262 265 263 try { 266 SwingUtilities.invokeAndWait(cacheFetch);267 } catch ( InvocationTargetException e) {264 EcosystemManager.getMiscManager().runOnGIOThread(cacheFetch); 265 } catch (Exception e) { 268 266 e.printStackTrace(); 269 267 assert(false); … … 562 560 * 563 561 */ 564 private class ExpediteeCachedTrackInfoFetcher implementsRunnable562 private class ExpediteeCachedTrackInfoFetcher extends BlockingRunnable 565 563 { 566 564 private String rootFrameName; … … 578 576 } 579 577 580 public void run()578 public void execute() 581 579 { 582 580 assert(rootFrameName != null); … … 584 582 // Check if the current frame 585 583 Frame rootFrame = null; 586 if (Display IO.getCurrentFrame() != null && DisplayIO.getCurrentFrame().getName() != null587 && Display IO.getCurrentFrame().getName().equals(rootFrameName)) {588 rootFrame = Display IO.getCurrentFrame();584 if (DisplayController.getCurrentFrame() != null && DisplayController.getCurrentFrame().getName() != null 585 && DisplayController.getCurrentFrame().getName().equals(rootFrameName)) { 586 rootFrame = DisplayController.getCurrentFrame(); 589 587 } else { 590 588 // Check if in cache … … 597 595 linkedTracks = new HashMap<String, LinkedTrackModelData>(); 598 596 599 for ( InteractiveWidget iw : rootFrame.getInteractiveWidgets()) {597 for (Widget iw : rootFrame.getInteractiveWidgets()) { 600 598 601 599 if (iw instanceof SampledTrack) { … … 668 666 * 669 667 */ 670 private class NewGraphCommitor implementsRunnable668 private class NewGraphCommitor extends BlockingRunnable 671 669 { 672 670 private final OverdubbedFrame rootODFrame; … … 687 685 } 688 686 689 public void run()687 public void execute() 690 688 { 691 689 … … 1083 1081 synchronized(sharedResourceLocker) { // IMPORTANT: Must wait for new graphs to be added to the shared resources 1084 1082 1085 if ( FrameGraphics.isXRayMode()) { // discard whole model1083 if (DisplayController.isXRayMode()) { // discard whole model 1086 1084 1087 1085 // Neccessary because if the user goes into xray then moves to a new frame … … 1422 1420 1423 1421 1424 if ( FrameGraphics.isXRayMode()) { // discard whole model1422 if (DisplayController.isXRayMode()) { // discard whole model 1425 1423 1426 1424 // Neccessary because if the user goes into xray then moves to a new frame … … 1610 1608 1611 1609 try { 1612 SwingUtilities.invokeAndWait(newRunnable() {1610 EcosystemManager.getMiscManager().runOnGIOThread(new BlockingRunnable() { 1613 1611 1614 public void run() { // on swing thread1612 public void execute() { // on swing thread 1615 1613 1616 1614 synchronized(sharedResourceLocker) { … … 1672 1670 } 1673 1671 }); 1674 } catch ( InvocationTargetException e) {1672 } catch (Exception e) { 1675 1673 e.printStackTrace(); 1676 1674 assert(false); -
trunk/src/org/apollo/audio/util/MultiTrackPlaybackController.java
r367 r1102 9 9 10 10 import javax.sound.sampled.LineUnavailableException; 11 import javax.swing.SwingUtilities;12 11 13 12 import org.apollo.audio.ApolloPlaybackMixer; … … 31 30 import org.apollo.util.TrackModelHandler; 32 31 import org.apollo.util.TrackModelLoadManager; 33 import org.expeditee.gui.DisplayIO; 34 import org.expeditee.gui.DisplayIOObserver; 35 32 import org.expeditee.core.BlockingRunnable; 33 import org.expeditee.gio.EcosystemManager; 34 import org.expeditee.gui.DisplayController; 35 import org.expeditee.gui.DisplayObserver; 36 36 37 37 public class MultiTrackPlaybackController 38 38 extends AbstractSubject 39 implements TrackModelHandler, Observer, Display IOObserver {39 implements TrackModelHandler, Observer, DisplayObserver { 40 40 41 41 /** Can be a framename or virtual filename (e.g. from a linked track) */ … … 91 91 // After a certain amount of frame changes since the last multi playback has occured 92 92 // the cached track models are freed to stop consuming all the memory. 93 Display IO.addDisplayIOObserver(this);93 DisplayController.addDisplayObserver(this); 94 94 95 95 // For whenever a track sequence is created - must observe the created track sequences... … … 295 295 */ 296 296 public void frameChanged() { 297 if (hasTrackCacheExpired() || isPlaying() || isLoading() || Display IO.getCurrentFrame() == null) return; // already expired - or is playing - so don't expire!298 299 String currentFrameName = Display IO.getCurrentFrame().getName();297 if (hasTrackCacheExpired() || isPlaying() || isLoading() || DisplayController.getCurrentFrame() == null) return; // already expired - or is playing - so don't expire! 298 299 String currentFrameName = DisplayController.getCurrentFrame().getName(); 300 300 301 301 // Free track group every so often.. … … 785 785 final int id1 = id; 786 786 final Object state1 = state; 787 SwingUtilities.invokeLater(new Runnable() {787 EcosystemManager.getMiscManager().runOnGIOThread(new Runnable() { 788 788 public void run() { 789 789 synchronized(listeners1) { … … 919 919 920 920 try { 921 SwingUtilities.invokeAndWait(absTrackGraphRetreiver);921 EcosystemManager.getMiscManager().runOnGIOThread(absTrackGraphRetreiver); 922 922 } catch (Exception e) { 923 923 notifyListeners(loadListeners, MultitrackLoadListener.LOAD_FAILED_GENERIC, e, true); … … 1095 1095 1096 1096 // Must commence on the swing thread 1097 SwingUtilities.invokeLater(new MultiTrackPlaybackCommencer());1097 EcosystemManager.getMiscManager().runOnGIOThread(new MultiTrackPlaybackCommencer()); 1098 1098 } 1099 1099 … … 1154 1154 * @author Brook Novak 1155 1155 */ 1156 private class ABSTrackGraphRetreiver implementsRunnable {1156 private class ABSTrackGraphRetreiver extends BlockingRunnable { 1157 1157 1158 1158 private String masterMixID; … … 1165 1165 } 1166 1166 1167 public void run() {1167 public void execute() { 1168 1168 assert(rootODFrame != null); 1169 1169 assert(masterMixID != null); -
trunk/src/org/apollo/audio/util/PlaybackClock.java
r315 r1102 10 10 import org.apollo.mvc.SubjectChangedEvent; 11 11 import org.apollo.util.AudioMath; 12 import org.expeditee.gui. FrameGraphics;12 import org.expeditee.gui.DisplayController; 13 13 14 14 /** … … 161 161 // Do a repaint is something was listening 162 162 if (shouldRepaint) { 163 FrameGraphics.requestRefresh(true); // later - should not congest AWT queue163 DisplayController.requestRefresh(true); // later - should not congest AWT queue 164 164 } 165 165 -
trunk/src/org/apollo/audio/util/Timeline.java
r315 r1102 6 6 * 7 7 * <ul> 8 * <li>The init ation point: This is the smallest initiation time9 * <b>(not nec cessarily zero)</b> in the frame - at its X pixel.8 * <li>The initiation point: This is the smallest initiation time 9 * <b>(not necessarily zero)</b> in the frame - at its X pixel. 10 10 * <li>The end point: This is how long the frame runs for - and the 11 11 * x-pixel position of the last played track in the frame. 12 12 * </ul> 13 13 * 14 * They are simple im utable objects thus are not kept consistant with model.14 * They are simple immutable objects thus are not kept consistent with model. 15 15 * 16 16 * @author Brook Novak -
trunk/src/org/apollo/gui/ApolloColorIndexedModels.java
r315 r1102 1 1 package org.apollo.gui; 2 2 3 import java.awt.Color; 4 import java.awt.image.IndexColorModel; 3 import org.expeditee.core.Colour; 5 4 6 5 public class ApolloColorIndexedModels { 7 6 8 public static final Colo r KEY_COLOR = new Color(123,58,123,0);9 private static final int KEY_INDEX = 0;7 public static final Colour KEY_COLOR = Colour.FromRGBA255(123,58,123,0); 8 //private static final int KEY_INDEX = 0; 10 9 11 10 /** Color index model for the track graphs */ 12 public static final IndexColorModel graphIndexColorModel;11 //public static final IndexColorModel graphIndexColorModel; 13 12 13 public static final Colour WAVEFORM_COLOR = Colour.fromRGB24BitPacked(0x1C5BA3); 14 public static final Colour WAVEFORM_SELECTION_COLOR = Colour.YELLOW; 14 15 15 public static final Color WAVEFORM_COLOR = new Color(0x1C5BA3);16 public static final Color WAVEFORM_SELECTION_COLOR = Color.YELLOW;16 //private static final int WAVEFORM_INDEX = 1; 17 //private static final int WAVEFORM_SELECTION_INDEX = 2; 17 18 18 private static final int WAVEFORM_INDEX = 1; 19 private static final int WAVEFORM_SELECTION_INDEX = 2; 19 //public static final IndexColorModel linkedTrackIndexColorModel; 20 20 21 22 public static final IndexColorModel linkedTrackIndexColorModel; 23 24 public static final Color TRACK1_COLOR = new Color(0x1C5BA3); 25 public static final Color TRACK2_COLOR = new Color(0x3280B7); 21 public static final Colour TRACK1_COLOR = Colour.fromRGB24BitPacked(0x1C5BA3); 22 public static final Colour TRACK2_COLOR = Colour.fromRGB24BitPacked(0x3280B7); 26 23 27 24 public static final int TRACK1_INDEX = 1; 28 25 public static final int TRACK2_INDEX = 2; 29 26 30 static { // Prepare the global color index model for the graphs27 /*static { // Prepare the global color index model for the graphs 31 28 32 29 // For waveform graphs: … … 35 32 byte[] blues = new byte[256]; 36 33 37 reds[KEY_INDEX] = (byte)KEY_COLOR.getRed ();38 greens[KEY_INDEX] = (byte)KEY_COLOR.getGreen ();39 blues[KEY_INDEX] = (byte)KEY_COLOR.getBlue ();34 reds[KEY_INDEX] = (byte)KEY_COLOR.getRed255(); 35 greens[KEY_INDEX] = (byte)KEY_COLOR.getGreen255(); 36 blues[KEY_INDEX] = (byte)KEY_COLOR.getBlue255(); 40 37 41 reds[WAVEFORM_INDEX] = (byte)WAVEFORM_COLOR.getRed ();42 greens[WAVEFORM_INDEX] = (byte)WAVEFORM_COLOR.getGreen ();43 blues[WAVEFORM_INDEX] = (byte)WAVEFORM_COLOR.getBlue ();38 reds[WAVEFORM_INDEX] = (byte)WAVEFORM_COLOR.getRed255(); 39 greens[WAVEFORM_INDEX] = (byte)WAVEFORM_COLOR.getGreen255(); 40 blues[WAVEFORM_INDEX] = (byte)WAVEFORM_COLOR.getBlue255(); 44 41 45 reds[WAVEFORM_SELECTION_INDEX] = (byte)WAVEFORM_SELECTION_COLOR.getRed ();46 greens[WAVEFORM_SELECTION_INDEX] = (byte)WAVEFORM_SELECTION_COLOR.getGreen ();47 blues[WAVEFORM_SELECTION_INDEX] = (byte)WAVEFORM_SELECTION_COLOR.getBlue ();42 reds[WAVEFORM_SELECTION_INDEX] = (byte)WAVEFORM_SELECTION_COLOR.getRed255(); 43 greens[WAVEFORM_SELECTION_INDEX] = (byte)WAVEFORM_SELECTION_COLOR.getGreen255(); 44 blues[WAVEFORM_SELECTION_INDEX] = (byte)WAVEFORM_SELECTION_COLOR.getBlue255(); 48 45 49 46 graphIndexColorModel = new IndexColorModel(8, 256, reds, greens, blues, KEY_INDEX); … … 55 52 blues = new byte[256]; 56 53 57 reds[KEY_INDEX] = (byte)KEY_COLOR.getRed ();58 greens[KEY_INDEX] = (byte)KEY_COLOR.getGreen ();59 blues[KEY_INDEX] = (byte)KEY_COLOR.getBlue ();54 reds[KEY_INDEX] = (byte)KEY_COLOR.getRed255(); 55 greens[KEY_INDEX] = (byte)KEY_COLOR.getGreen255(); 56 blues[KEY_INDEX] = (byte)KEY_COLOR.getBlue255(); 60 57 61 reds[TRACK1_INDEX] = (byte)TRACK1_COLOR.getRed ();62 greens[TRACK1_INDEX] = (byte)TRACK1_COLOR.getGreen ();63 blues[TRACK1_INDEX] = (byte)TRACK1_COLOR.getBlue ();58 reds[TRACK1_INDEX] = (byte)TRACK1_COLOR.getRed255(); 59 greens[TRACK1_INDEX] = (byte)TRACK1_COLOR.getGreen255(); 60 blues[TRACK1_INDEX] = (byte)TRACK1_COLOR.getBlue255(); 64 61 65 reds[TRACK2_INDEX] = (byte)TRACK2_COLOR.getRed ();66 greens[TRACK2_INDEX] = (byte)TRACK2_COLOR.getGreen ();67 blues[TRACK2_INDEX] = (byte)TRACK2_COLOR.getBlue ();62 reds[TRACK2_INDEX] = (byte)TRACK2_COLOR.getRed255(); 63 greens[TRACK2_INDEX] = (byte)TRACK2_COLOR.getGreen255(); 64 blues[TRACK2_INDEX] = (byte)TRACK2_COLOR.getBlue255(); 68 65 69 66 linkedTrackIndexColorModel = new IndexColorModel(8, 256, reds, greens, blues, KEY_INDEX); 70 67 71 } 72 73 74 75 68 }*/ 76 69 } -
trunk/src/org/apollo/gui/DualPeakTroughWaveFormRenderer.java
r1007 r1102 30 30 * If audioformat is not supported. See SampledAudioManager.isFormatSupportedForPlayback 31 31 */ 32 public DualPeakTroughWaveFormRenderer(AudioFormat audioFormat) { 32 public DualPeakTroughWaveFormRenderer(AudioFormat audioFormat) 33 { 33 34 if (audioFormat == null) throw new NullPointerException("audioFormat"); 34 35 35 if (!SampledAudioManager.getInstance().isFormatSupportedForPlayback(audioFormat)) 36 throw new IllegalArgumentException(); 36 if (!SampledAudioManager.getInstance().isFormatSupportedForPlayback(audioFormat)) throw new IllegalArgumentException(); 37 37 38 38 sampleSize = audioFormat.getSampleSizeInBits(); … … 70 70 * interleaves in rendering order) 71 71 */ 72 public float[] getSampleAmplitudes(byte[] audioBytes, int startFrame, int frameLength, int aggregationSize) { 72 public float[] getSampleAmplitudes(byte[] audioBytes, int startFrame, int frameLength, int aggregationSize) 73 { 73 74 assert(audioBytes != null); 74 75 assert(startFrame >= 0); … … 77 78 int aggregationCount = frameLength / aggregationSize; 78 79 79 float[] amplitudes = (aggregationSize == 1) ? 80 new float[aggregationCount] : 81 new float[aggregationCount * 2]; 80 float[] amplitudes = (aggregationSize == 1) ? new float[aggregationCount] : new float[aggregationCount * 2]; 82 81 83 82 if (sampleSize == 16) { -
trunk/src/org/apollo/gui/EditableSampledTrackGraphView.java
r355 r1102 1 1 package org.apollo.gui; 2 2 3 import java.awt.Color;4 3 import java.awt.Graphics; 5 4 import java.awt.Graphics2D; 6 5 import java.awt.Point; 7 import java.awt.Rectangle;8 6 import java.awt.event.KeyEvent; 9 7 import java.awt.event.KeyListener; … … 23 21 import org.apollo.util.TrackNameCreator; 24 22 import org.apollo.widgets.SampledTrack; 23 import org.expeditee.core.Colour; 24 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 25 import org.expeditee.gio.gesture.StandardGestureActions; 26 import org.expeditee.gio.swing.SwingConversions; 27 import org.expeditee.gio.swing.SwingMiscManager; 25 28 import org.expeditee.gui.Browser; 26 import org.expeditee.gui.Display IO;29 import org.expeditee.gui.DisplayController; 27 30 import org.expeditee.gui.Frame; 28 import org.expeditee.gui.FrameGraphics;29 import org.expeditee.gui.FrameMouseActions;30 31 import org.expeditee.gui.FreeItems; 31 32 import org.expeditee.items.Item; … … 52 53 private boolean selectAllOnDoubleClick = false; 53 54 54 public static final Colo r SELECTION_BACKING_COLOR_SELECT_ONLY = Color.BLACK;55 private static final Colo r SELECTION_BACKING_COLOR_SELECT_AND_COPY = Color.GREEN;55 public static final Colour SELECTION_BACKING_COLOR_SELECT_ONLY = Colour.BLACK; 56 private static final Colour SELECTION_BACKING_COLOR_SELECT_AND_COPY = Colour.GREEN; 56 57 57 58 private static final int SELECTION_MODE_SELECT_ONLY = 1; … … 215 216 } 216 217 217 FrameGraphics.refresh(true);218 DisplayController.requestRefresh(true); 218 219 219 220 } … … 289 290 assert(copiedAudioRegion != null); 290 291 291 Frame targetFrame = Display IO.getCurrentFrame();292 Frame targetFrame = DisplayController.getCurrentFrame(); 292 293 if (targetFrame != null) { 293 294 … … 307 308 assert(Browser._theBrowser != null); 308 309 309 // A work round for getting the widget into fre space centered on cursor310 // A workaround for getting the widget into free space centred on cursor 310 311 Point p = e.getLocationOnScreen(); 311 SwingUtilities.convertPointFromScreen(p, Browser._theBrowser.getContentPane());312 SwingUtilities.convertPointFromScreen(p, SwingMiscManager.getIfUsingSwingGraphicsManager().getContentPane()); 312 313 twidget.setPosition(p.x - (twidget.getWidth() / 2), p.y - (twidget.getHeight() / 2)); 313 314 314 315 for (Item i : twidget.getItems()) { 315 i.setOffset( new Point(316 (i.getX() - Display IO.getMouseX()) + (twidget.getWidth() / 2),317 (i.getY() - FrameMouseActions.getY()) + (twidget.getHeight() / 2)318 )) ;316 i.setOffset(SwingConversions.fromSwingPoint(new Point( 317 (i.getX() - DisplayController.getMouseX()) + (twidget.getWidth() / 2), 318 (i.getY() - DisplayController.getMouseY()) + (twidget.getHeight() / 2) 319 ))); 319 320 } 320 321 321 322 // Put the new widget into free space 322 FrameMouseActions.pickup(twidget.getItems());323 StandardGestureActions.pickup(twidget.getItems()); 323 324 324 325 } … … 399 400 400 401 @Override 401 public void paint(Graphics g) { 402 public void paint(Graphics g) 403 { 402 404 super.paint(g); 403 405 … … 416 418 } 417 419 418 g.setColor(Color.RED); 419 g.drawLine( 420 x, 421 0, 422 x, 423 getHeight()); 420 g.setColor(SwingConversions.toSwingColor(Colour.RED)); 421 g.drawLine(x, 0, x, getHeight()); 424 422 425 423 } … … 432 430 private void paintLock(Graphics g) { 433 431 if (isPlaying()) { 434 IconRepository.getIcon("lock.png").paintIcon(null,432 /*IconRepository.getIcon("lock.png").paintIcon(null, 435 433 g, 436 434 getWidth() - LOCK_ICON_CORNER_OFFSET, 437 LOCK_ICON_CORNER_OFFSET - 16); 435 LOCK_ICON_CORNER_OFFSET - 16);*/ 436 437 g.drawImage(SwingMiscManager.getIfUsingSwingImageManager().getInternalImage(IconRepository.getIcon("lock.png")), 438 getWidth() - LOCK_ICON_CORNER_OFFSET, 439 LOCK_ICON_CORNER_OFFSET - 16, 440 null); 438 441 } 439 442 } … … 442 445 Point exp = getExpediteePoint(); 443 446 if (exp != null) { 444 FrameGraphics.invalidateArea(new Rectangle(447 DisplayController.invalidateArea(new AxisAlignedBoxBounds( 445 448 exp.x + getWidth() - LOCK_ICON_CORNER_OFFSET, 446 449 exp.y + LOCK_ICON_CORNER_OFFSET - 16, … … 505 508 506 509 color = (selectionMode == SELECTION_MODE_SELECT_ONLY) ? 507 SELECTION_BACKING_COLOR_SELECT_ONLY : SELECTION_BACKING_COLOR_SELECT_AND_COPY; 510 SwingConversions.toSwingColor(SELECTION_BACKING_COLOR_SELECT_ONLY) : 511 SwingConversions.toSwingColor(SELECTION_BACKING_COLOR_SELECT_AND_COPY); 508 512 super.paint(g); 509 513 } -
trunk/src/org/apollo/gui/ExpandedTrackManager.java
r315 r1102 2 2 3 3 import java.awt.Dimension; 4 import java.awt.Graphics2D; 4 5 import java.awt.GridBagConstraints; 5 6 import java.awt.GridBagLayout; 6 import java.awt.Rectangle;7 7 import java.awt.event.ActionEvent; 8 8 import java.awt.event.ActionListener; 9 import java.awt.event.ComponentEvent;10 import java.awt.event.ComponentListener;11 9 import java.util.LinkedList; 12 10 13 11 import javax.swing.JButton; 14 12 import javax.swing.JLabel; 15 import javax.swing. SwingUtilities;13 import javax.swing.JPanel; 16 14 17 15 import org.apollo.audio.SampledTrackModel; … … 22 20 import org.apollo.util.TrackModelHandler; 23 21 import org.apollo.util.TrackModelLoadManager; 22 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 23 import org.expeditee.gio.EcosystemManager; 24 import org.expeditee.gio.InputManager.WindowEventListener; 25 import org.expeditee.gio.InputManager.WindowEventType; 26 import org.expeditee.gio.swing.SwingConversions; 27 import org.expeditee.gio.swing.SwingMiscManager; 24 28 import org.expeditee.gui.Browser; 25 import org.expeditee.gui.FrameGraphics; 26 import org.expeditee.gui.MessageBay; 29 import org.expeditee.gui.DisplayController; 27 30 import org.expeditee.gui.Popup; 28 31 import org.expeditee.gui.PopupManager; 32 import org.expeditee.gui.PopupManager.ExpandShrinkAnimator; 29 33 30 34 /** … … 40 44 41 45 /** All epxanded tracks ... either in all in view or all selected ... to be viewed */ 42 private LinkedList<ExpandedTrackPopup> expandedTracks = new LinkedList<ExpandedTrackPopup> 46 private LinkedList<ExpandedTrackPopup> expandedTracks = new LinkedList<ExpandedTrackPopup>(); // SHARED Model data 43 47 44 48 private MultiTrackExpansionPopup trackSelectionPopup = new MultiTrackExpansionPopup(); 45 49 46 50 private static ExpandedTrackManager instance = new ExpandedTrackManager(); 47 private ExpandedTrackManager() { 48 51 52 private ExpandedTrackManager() 53 { 49 54 // Keep view centered to browser size 50 SwingUtilities.invokeLater(new Runnable() { 51 public void run() { 52 53 // Keep expanded view centered to the browser window 54 if (Browser._theBrowser != null) { 55 Browser._theBrowser.addComponentListener(new ComponentListener() { 56 57 public void componentHidden(ComponentEvent e) { 58 } 59 60 public void componentMoved(ComponentEvent e) { 61 } 62 63 public void componentResized(ComponentEvent e) { 64 65 if (PopupManager.getInstance().isShowing(trackSelectionPopup)) { 66 // User currently selecting.. 67 trackSelectionPopup.setLocation( 68 (Browser._theBrowser.getWidth() / 2) - (trackSelectionPopup.getWidth() / 2), 0); 69 70 } else { // expanded views might be showing 71 72 // Fails with Maximizing of window on some systems... swing 73 // bug!! really anoying 74 updateLayout(); 75 76 } 77 78 } 79 80 public void componentShown(ComponentEvent e) { 81 } 82 83 }); 55 EcosystemManager.getInputManager().addWindowEventListener(new WindowEventListener() 56 { 57 @Override 58 public void onWindowEvent(WindowEventType type) 59 { 60 if (type != WindowEventType.WINDOW_RESIZED) return; 61 if (PopupManager.getInstance().isShowing(trackSelectionPopup)) { 62 // User currently selecting.. 63 trackSelectionPopup.setLocation((EcosystemManager.getGraphicsManager().getWindowSize().getWidth() - trackSelectionPopup.getFullBounds().getWidth()) / 2, 0); 64 65 } else { // expanded views might be showing 66 67 // Fails with maximising of window on some systems... swing 68 // bug!! really annoying 69 updateLayout(); 70 84 71 } 85 86 }72 } 73 87 74 }); 88 75 89 // Registe wr for (indirectly) handling track models76 // Register for (indirectly) handling track models 90 77 TrackModelLoadManager.getInstance().addTrackModelHandler(this); 91 78 79 PopupManager.getInstance().add(trackSelectionPopup); 92 80 } 93 81 … … 162 150 * If trackModel or trackMix or trackSourceFrameName or localFilename is null. 163 151 */ 164 public boolean addTrackToSelection( 165 SampledTrackModel track, 166 String trackSourceFrameName, 167 Rectangle animationSource, 168 TrackMixSubject mix) { 169 152 public boolean addTrackToSelection(SampledTrackModel track, String trackSourceFrameName, AxisAlignedBoxBounds animationSource, TrackMixSubject mix) 153 { 170 154 assert(track != null); 171 155 assert(Browser._theBrowser != null); … … 174 158 synchronized(expandedTracks) { 175 159 176 if (expandedTracks.size() < MAX_EXPANDED_TRACK_SIZE 177 && !isTrackInExpansionSelection(track)) { 160 if (expandedTracks.size() < MAX_EXPANDED_TRACK_SIZE && !isTrackInExpansionSelection(track)) { 178 161 179 162 ExpandedTrackPopup.giveToExpandedTrackManager( … … 183 166 0, 184 167 track.getFrameCount()); /** @see #receiveExpandedTrackPopup */ 185 186 Rectangle trackSelectionPopupBounds = null;187 168 188 169 // Ensure that the trackSelectionPopup is not already showing / animated to show 189 170 if (!PopupManager.getInstance().isShowing(trackSelectionPopup)) { 190 171 191 trackSelectionPopupBounds = new Rectangle( 192 (Browser._theBrowser.getWidth() / 2 ) - (trackSelectionPopup.getWidth() / 2), 193 0, 194 trackSelectionPopup.getWidth(), 195 trackSelectionPopup.getHeight()); 172 trackSelectionPopup.setLocation((DisplayController.getFramePaintArea().getWidth() - trackSelectionPopup.getFullBounds().getWidth()) / 2, 0); 196 173 197 174 // Creep from above 198 PopupManager.getInstance().showPopup( 199 trackSelectionPopup, 200 trackSelectionPopupBounds.getLocation(), 201 null, 202 PopupManager.getInstance().new ExpandShrinkAnimator( 203 trackSelectionPopupBounds, 204 null)); 205 206 } else { 207 trackSelectionPopup.repaint(); 175 trackSelectionPopup.show(); 208 176 } 209 177 210 178 // Animate a fake popup expanding into the trackSelectionPopup from the given source if not null 211 179 if (animationSource != null) { 212 213 PopupManager.getInstance().doPureAnimation(PopupManager.getInstance().new ExpandShrinkAnimator( 214 animationSource, null), 215 (trackSelectionPopupBounds == null) ? 216 trackSelectionPopup.getBounds() : trackSelectionPopupBounds); 180 ((ExpandShrinkAnimator) trackSelectionPopup.getAnimator()).setInitialBounds(animationSource); 217 181 } 218 182 … … 253 217 * 254 218 */ 255 public void expandSingleTrack( 256 SampledTrackModel track, 257 Rectangle animationSource, 258 TrackMixSubject mix, 259 String trackSourceFrameName, 260 int frameStart, 261 int frameLength) { 219 public void expandSingleTrack(SampledTrackModel track, AxisAlignedBoxBounds animationSource, TrackMixSubject mix, String trackSourceFrameName, int frameStart, int frameLength) 220 { 262 221 assert(animationSource != null); 263 222 assert(track != null); … … 265 224 synchronized(expandedTracks) { 266 225 // Hide all expandedTracks that are currently showing 267 while (!expandedTracks.isEmpty()) 268 PopupManager.getInstance().hidePopup(expandedTracks.getFirst()); 226 for (ExpandedTrackPopup expandedTrack : expandedTracks) { 227 expandedTrack.hide(); 228 } 269 229 } 270 230 … … 315 275 } 316 276 317 private void cancelSelection() {318 277 private void cancelSelection() 278 { 319 279 hideTrackSelectionPopup(); 320 280 321 281 // Remove from selection 322 LinkedList<? extends ExpandedTrackPopup> old = (LinkedList<? extends ExpandedTrackPopup>) expandedTracks.clone();282 LinkedList<? extends ExpandedTrackPopup> old = (LinkedList<? extends ExpandedTrackPopup>) expandedTracks.clone(); 323 283 324 284 synchronized(expandedTracks) { … … 341 301 * A tracks ExpandedTrackPopup if one exists. 342 302 */ 343 private ExpandedTrackPopup getExpandedTrackPopup(SampledTrackModel track) { 303 private ExpandedTrackPopup getExpandedTrackPopup(SampledTrackModel track) 304 { 344 305 assert(track != null); 345 306 … … 362 323 * True if the track is expanded - or is selected to be expanded.. 363 324 */ 364 public boolean isTrackInExpansionSelection(SampledTrackModel track) { 325 public boolean isTrackInExpansionSelection(SampledTrackModel track) 326 { 365 327 assert(track != null); 366 328 return getExpandedTrackPopup(track) != null; … … 371 333 * True if at least 1 expanded track is showing - or is selected to show. 372 334 */ 373 public boolean doesExpandedTrackExist() { 335 public boolean doesExpandedTrackExist() 336 { 374 337 synchronized(expandedTracks) { 375 338 return expandedTracks.size() > 0; … … 377 340 } 378 341 379 public boolean isAnyExpandedTrackVisible() { 342 public boolean isAnyExpandedTrackVisible() 343 { 380 344 for (ExpandedTrackPopup xtp : expandedTracks) { 381 345 if (PopupManager.getInstance().isShowing(xtp)) return true; … … 389 353 * 390 354 */ 391 public void showSelection() { 355 public void showSelection() 356 { 392 357 expandTracks(null); 393 358 } 394 359 395 360 /** 396 * Returns immediat ly if there are no tracks selected. Only expands if the popup is not already expanded.361 * Returns immediately if there are no tracks selected. Only expands if the popup is not already expanded. 397 362 * 398 363 * @param directAnimSource … … 401 366 * a widget). 402 367 */ 403 private void expandTracks( Rectangle directAnimSource) {404 368 private void expandTracks(AxisAlignedBoxBounds directAnimSource) 369 { 405 370 synchronized(expandedTracks) { 406 371 … … 418 383 for (ExpandedTrackPopup xtp : expandedTracks) { 419 384 420 // Note: returns immediatly if already showing 421 PopupManager.getInstance().showPopup( 422 xtp, 423 xtp.getLocation(), 424 null, 425 PopupManager.getInstance().new ExpandShrinkAnimator( 426 directAnimSource, 427 null)); 385 // Note: returns immediately if already showing 386 ((ExpandShrinkAnimator) xtp.getAnimator()).setInitialBounds(directAnimSource); 387 xtp.show(); 428 388 429 389 } … … 435 395 } 436 396 437 private void hideTrackSelectionPopup() { 438 PopupManager.getInstance().hidePopup( 439 trackSelectionPopup, PopupManager.getInstance().new ExpandShrinkAnimator( 440 new Rectangle((Browser._theBrowser.getWidth() / 2 ) - (trackSelectionPopup.getWidth() / 2), 441 0, trackSelectionPopup.getWidth(), trackSelectionPopup.getHeight()), null)); 397 private void hideTrackSelectionPopup() 398 { 399 trackSelectionPopup.hide(); 442 400 } 443 401 … … 446 404 * current state of the window. 447 405 */ 448 private void updateLayout() { 449 450 synchronized(expandedTracks) { 451 452 406 private void updateLayout() 407 { 408 synchronized(expandedTracks) { 409 453 410 if (expandedTracks.isEmpty()) return; 454 411 … … 456 413 assert(Browser._theBrowser != null); 457 414 458 int cpWidth = Browser._theBrowser.getContentPane().getWidth();459 int cpHeight = Browser._theBrowser.getContentPane().getHeight();460 if (! FrameGraphics.isAudienceMode()) { // if message bay is showing - the remove the height461 462 cpHeight -= MessageBay.MESSAGE_BUFFER_HEIGHT;415 int cpWidth = DisplayController.getFramePaintArea().getWidth(); 416 int cpHeight = DisplayController.getFramePaintArea().getHeight(); 417 if (!DisplayController.isAudienceMode()) { // if message bay is showing - the remove the height 418 419 cpHeight -= DisplayController.getMessageBayPaintArea().getHeight(); 463 420 464 421 } … … 504 461 * Global Track model re-use .... can be called from any thread 505 462 */ 506 public SampledTrackModel getSharedSampledTrackModel(String localfilename) { 463 public SampledTrackModel getSharedSampledTrackModel(String localfilename) 464 { 507 465 synchronized(expandedTracks) { 508 466 for (ExpandedTrackPopup xtp : expandedTracks) { … … 521 479 * 522 480 */ 523 private class MultiTrackExpansionPopup extends Popup implements ActionListener { 524 481 private class MultiTrackExpansionPopup extends Popup implements ActionListener 482 { 483 private JPanel panel; 525 484 private JButton expandButton; 526 485 private JButton cancelButton; … … 528 487 private JLabel selected2; 529 488 private JLabel selectedMore; 530 531 private static final long serialVersionUID = 1L; 489 532 490 //private final Color BACK_COLOR = SampledTrackGraphViewPort.ZOOM_BACKING_COLOR_NORMAL; 533 491 534 MultiTrackExpansionPopup() { 535 super(new GridBagLayout()); 536 setSize(260, 80); 537 super.setAudoHide(false); 538 539 expandButton = new JButton(IconRepository.getIcon("expand.png")); 492 MultiTrackExpansionPopup() 493 { 494 super(new ExpandShrinkAnimator()); 495 496 panel = new JPanel(new GridBagLayout()); 497 panel.setSize(260, 80); 498 499 expandButton = new JButton(); 500 SwingMiscManager.setJButtonIcon(expandButton, IconRepository.getIcon("expand.png")); 540 501 expandButton.addActionListener(this); 541 502 expandButton.setPreferredSize(new Dimension(40, 40)); 542 503 expandButton.setToolTipText("Expand selection"); 543 504 544 cancelButton = new JButton(IconRepository.getIcon("close.png")); 505 cancelButton = new JButton(); 506 SwingMiscManager.setJButtonIcon(cancelButton, IconRepository.getIcon("close.png")); 545 507 cancelButton.addActionListener(this); 546 508 cancelButton.setPreferredSize(new Dimension(40, 40)); … … 563 525 c.gridy = 0; 564 526 c.fill = GridBagConstraints.CENTER; 565 add(expandButton, c);527 panel.add(expandButton, c); 566 528 567 529 c = new GridBagConstraints(); … … 569 531 c.gridy = 0; 570 532 c.fill = GridBagConstraints.CENTER; 571 add(cancelButton, c);533 panel.add(cancelButton, c); 572 534 573 535 c = new GridBagConstraints(); … … 576 538 c.gridwidth = 2; 577 539 c.fill = GridBagConstraints.CENTER; 578 add(selected1, c);540 panel.add(selected1, c); 579 541 580 542 c = new GridBagConstraints(); … … 583 545 c.gridwidth = 2; 584 546 c.fill = GridBagConstraints.CENTER; 585 add(selected2, c);547 panel.add(selected2, c); 586 548 587 549 c = new GridBagConstraints(); … … 591 553 c.gridheight = 2; 592 554 c.fill = GridBagConstraints.CENTER; 593 add(selectedMore, c); 594 595 } 596 597 public void onTrackSelectionChanged() { 598 555 panel.add(selectedMore, c); 556 } 557 558 public void setLocation(int x, int y) 559 { 560 panel.setLocation(x, y); 561 } 562 563 public void onTrackSelectionChanged() 564 { 599 565 synchronized(expandedTracks) { 600 566 … … 628 594 } 629 595 630 public void actionPerformed(ActionEvent e) { 596 public void actionPerformed(ActionEvent e) 597 { 631 598 if (e.getSource() == expandButton) { 632 599 showSelection(); … … 635 602 } 636 603 } 637 638 639 640 } 641 642 604 605 @Override 606 protected void paintInternal() 607 { 608 Graphics2D g = SwingMiscManager.getIfUsingSwingGraphicsManager().getCurrentSurface(); 609 610 panel.paint(g); 611 } 612 613 @Override 614 public AxisAlignedBoxBounds getFullBounds() 615 { 616 return SwingConversions.fromSwingRectangle(panel.getBounds()); 617 } 618 619 @Override 620 public void onHide() 621 { 622 } 623 624 @Override 625 public void onShow() 626 { 627 } 628 } 643 629 } -
trunk/src/org/apollo/gui/ExpandedTrackPopup.java
r315 r1102 2 2 3 3 import java.awt.BorderLayout; 4 import java.awt.Color;5 4 import java.awt.Dimension; 6 5 import java.awt.Event; 7 6 import java.awt.Font; 8 import java.awt.Graphics ;7 import java.awt.Graphics2D; 9 8 import java.awt.GridBagConstraints; 10 9 import java.awt.GridBagLayout; 11 10 import java.awt.Insets; 12 11 import java.awt.Point; 13 import java.awt.Rectangle;14 12 import java.awt.event.ActionEvent; 15 13 import java.awt.event.ActionListener; 16 import java.awt.event.KeyEvent;17 import java.awt.event.KeyListener;18 import java.awt.event.MouseEvent;19 import java.awt.event.MouseListener;20 import java.awt.event.MouseMotionListener;21 14 22 15 import javax.sound.sampled.LineUnavailableException; 23 import javax.swing.Icon;24 16 import javax.swing.JButton; 25 17 import javax.swing.JPanel; … … 45 37 import org.apollo.util.AudioMath; 46 38 import org.apollo.widgets.TrackWidgetCommons; 39 import org.expeditee.core.Colour; 40 import org.expeditee.core.Image; 41 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 42 import org.expeditee.gio.EcosystemManager; 43 import org.expeditee.gio.input.InputEvent; 44 import org.expeditee.gio.input.InputEventListener; 45 import org.expeditee.gio.swing.SwingConversions; 46 import org.expeditee.gio.swing.SwingMiscManager; 47 47 import org.expeditee.gui.Browser; 48 import org.expeditee.gui. FrameGraphics;48 import org.expeditee.gui.DisplayController; 49 49 import org.expeditee.gui.Popup; 50 import org.expeditee.gui.PopupManager; 51 52 public class ExpandedTrackPopup extends Popup implements ActionListener, Observer { 53 54 private static final long serialVersionUID = 1L; 55 50 import org.expeditee.gui.PopupManager.ExpandShrinkAnimator; 51 52 public class ExpandedTrackPopup extends Popup implements ActionListener, Observer 53 { 56 54 /** The observed subject. Can never be null */ 57 55 private SampledTrackModel trackModel; // immutable … … 61 59 private TrackMixSubject trackMix; // immutable 62 60 61 private JPanel panel; 63 62 private JButton playPauseButton; 64 63 private JButton stopButton; … … 106 105 String trackSourceFrameName, 107 106 int frameStart, 108 int frameLength) { 109 super(new BorderLayout()); 107 int frameLength) 108 { 109 super(new ExpandShrinkAnimator()); 110 110 super.setConsumeBackClick(true); 111 112 panel = new JPanel(new BorderLayout()); 111 113 112 114 if (trackModel == null) throw new NullPointerException("trackModel"); … … 121 123 playPauseButton = new JButton(); 122 124 playPauseButton.addActionListener(this); 123 playPauseButton.setIcon(IconRepository.getIcon("play.png"));125 SwingMiscManager.setJButtonIcon(playPauseButton, IconRepository.getIcon("play.png")); 124 126 playPauseButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE)); 125 127 playPauseButton.setToolTipText("Play selection / Pause"); … … 128 130 stopButton.setEnabled(false); 129 131 stopButton.addActionListener(this); 130 stopButton.setIcon(IconRepository.getIcon("stop.png"));132 SwingMiscManager.setJButtonIcon(stopButton, IconRepository.getIcon("stop.png")); 131 133 stopButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE)); 132 134 stopButton.setToolTipText("Stop playback"); … … 134 136 rewindButton = new JButton(); 135 137 rewindButton.addActionListener(this); 136 rewindButton.setIcon(IconRepository.getIcon("rewind.png"));138 SwingMiscManager.setJButtonIcon(rewindButton, IconRepository.getIcon("rewind.png")); 137 139 rewindButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE)); 138 140 rewindButton.setToolTipText("Rewind to start"); … … 140 142 // Icon changes 141 143 muteButton = new JToggleButton(); 142 muteButton.setSelectedIcon(IconRepository.getIcon("volmute.png"));144 SwingMiscManager.setJButtonIcon(muteButton, IconRepository.getIcon("volmute.png")); 143 145 muteButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE)); 144 146 muteButton.setToolTipText("Toggle mute"); … … 153 155 154 156 soloButton = new JToggleButton(); 155 soloButton.setIcon(IconRepository.getIcon("solo.png"));156 soloButton.setSelectedIcon(IconRepository.getIcon("soloon.png"));157 SwingMiscManager.setJButtonIcon(soloButton, IconRepository.getIcon("solo.png")); 158 SwingMiscManager.setJButtonSelectedIcon(soloButton, IconRepository.getIcon("soloon.png")); 157 159 soloButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE)); 158 160 soloButton.setToolTipText("Toggle solo"); … … 170 172 closeButton = new JButton(); 171 173 closeButton.addActionListener(this); 172 closeButton.setIcon(IconRepository.getIcon("close.png"));174 SwingMiscManager.setJButtonIcon(closeButton, IconRepository.getIcon("close.png")); 173 175 closeButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE)); 174 176 closeButton.setToolTipText("Close"); … … 216 218 nameLabelParent = new JPanel(); 217 219 218 nameLabelParent.addMouseListener(new MouseListener() { 219 220 public void mouseClicked(MouseEvent e) { 221 if (nameLabel != null) { 222 if (nameLabel.onMouseClicked(e)) { 223 e.consume(); 224 return; 225 } 226 } 227 } 228 229 public void mouseEntered(MouseEvent e) { 230 } 231 232 public void mouseExited(MouseEvent e) { 233 } 234 235 public void mousePressed(MouseEvent e) { 236 if (nameLabel != null) { 237 if (nameLabel.onMousePressed(e)) { 238 e.consume(); 239 } 240 } 241 } 242 243 public void mouseReleased(MouseEvent e) { 244 if (nameLabel != null) { 245 if (nameLabel.onMouseReleased(e)) { 246 e.consume(); 247 } 248 } 249 } 250 251 }); 252 253 nameLabelParent.addMouseMotionListener(new MouseMotionListener() { 254 255 public void mouseDragged(MouseEvent e) { 256 if (nameLabel != null) { 257 if (nameLabel.onMouseDragged(e)) { 258 e.consume(); 259 } 260 } 261 } 262 263 public void mouseMoved(MouseEvent e) { 264 if (nameLabel != null) { 265 nameLabel.onMouseMoved(e, nameLabelParent); 266 } 267 } 268 269 }); 270 271 nameLabelParent.addKeyListener(new KeyListener() { 272 273 public void keyPressed(KeyEvent e) { 274 if (nameLabel != null) { 275 if (nameLabel.onKeyPressed(e, nameLabelParent)) { 276 e.consume(); 277 } 278 } 279 } 280 281 public void keyReleased(KeyEvent e) { 282 if (nameLabel != null) { 283 if (nameLabel.onKeyReleased(e, nameLabelParent)) { 284 e.consume(); 285 } 286 } 287 288 } 289 290 public void keyTyped(KeyEvent e) { 291 } 292 293 }); 294 295 nameLabel = new EmulatedTextItem(nameLabelParent, new Point(10, 25)); 296 nameLabel.setFontStyle(Font.BOLD); 220 nameLabel = new EmulatedTextItem(trackModel.getName(), SwingConversions.fromSwingPoint(new Point(10, 25))); 221 nameLabel.setFontStyle(SwingConversions.fromSwingFontStyle(Font.BOLD)); 297 222 nameLabel.setFontSize(16); 298 nameLabel.setBackgroundColor(Colo r.WHITE);299 nameLabel. setText(trackModel.getName());223 nameLabel.setBackgroundColor(Colour.WHITE); 224 nameLabel.gainFocus(); 300 225 301 226 nameLabel.addTextChangeListener(new TextChangeListener() { // a little bit loopy! … … 373 298 toolBarPanel.add(closeButton, c); 374 299 375 this.add(toolBarPanel, BorderLayout.NORTH);376 this.add(splitPane, BorderLayout.CENTER);300 panel.add(toolBarPanel, BorderLayout.NORTH); 301 panel.add(splitPane, BorderLayout.CENTER); 377 302 378 303 // Observe track model … … 430 355 ExpandedTrackManager.getInstance().receiveExpandedTrackPopup(xtp); 431 356 } 432 357 433 358 @Override 434 public void onShowing() { 435 436 } 437 438 @Override 439 public void onShow() { 440 359 public void onShow() 360 { 441 361 if (splitPane.getHeight() < 140) { 442 362 splitPane.setDividerLocation(splitPane.getHeight() - 30); … … 456 376 // Invalidate full frame for shading 457 377 if (Browser._theBrowser != null) { 458 FrameGraphics.refresh(false);378 DisplayController.requestRefresh(false); 459 379 } 460 380 } 461 381 462 382 @Override 463 public void onHide() { 383 public void onHide() 384 { 464 385 ExpandedTrackManager.getInstance().expandedTrackPopupHidden(this); 465 386 releaseMemory(); // get rid of buffer etc.. … … 470 391 // Invalidate full frame for shading 471 392 if (Browser._theBrowser != null) { 472 FrameGraphics.refresh(false);393 DisplayController.requestRefresh(false); 473 394 } 474 395 } 475 396 476 477 478 479 397 @Override 480 public void paint(Graphics g) { 481 super.paint(g); 482 483 g.translate(-getX(), -getY()); 484 nameLabel.paint(g); 485 g.translate(getX(), getY()); 486 487 } 488 489 public void actionPerformed(ActionEvent e) { 398 public void paintInternal() 399 { 400 Graphics2D g = SwingMiscManager.getIfUsingSwingGraphicsManager().getCurrentSurface(); 401 402 panel.paint(g); 403 404 g.translate(-getFullBounds().getMinX(), -getFullBounds().getMinY()); 405 nameLabel.paint(); 406 g.translate(getFullBounds().getMinX(), getFullBounds().getMinY()); 407 } 408 409 public void actionPerformed(ActionEvent e) 410 { 490 411 if (trackModel == null) return; 491 412 … … 587 508 // If there are more expanded tracks showing then the ExpandedTrackManager 588 509 // will automatically re-layout the remaing views. 589 PopupManager.getInstance().hidePopup(this, 590 PopupManager.getInstance().new ExpandShrinkAnimator( 591 new Rectangle(0, getY(), 1, getHeight()), 592 Color.LIGHT_GRAY)); 510 hide(); 593 511 594 512 } … … 660 578 stopButton.setEnabled(true); 661 579 rewindButton.setEnabled(false); 662 playPauseButton.setIcon(IconRepository.getIcon("pause.png"));580 SwingMiscManager.setJButtonIcon(playPauseButton, IconRepository.getIcon("pause.png")); 663 581 664 582 setBorderThickness(TrackWidgetCommons.PLAYING_TRACK_EDGE_THICKNESS); … … 670 588 rewindButton.setEnabled(true); 671 589 stopButton.setEnabled(false); 672 playPauseButton.setIcon(IconRepository.getIcon("play.png"));590 SwingMiscManager.setJButtonIcon(playPauseButton, IconRepository.getIcon("play.png")); 673 591 674 592 // Note: … … 810 728 811 729 // Get border color currently used 812 Colo r oldC = getBorderColor();813 814 Colo r newC = TrackWidgetCommons.getBorderColor(730 Colour oldC = getBorderColor(); 731 732 Colour newC = TrackWidgetCommons.getBorderColor( 815 733 SoundDesk.getInstance().isSolo(trackMix.getChannelID()), 816 734 trackMix.isMuted()); … … 828 746 private void updateButtonGUI() { 829 747 830 I connewIcon = null;748 Image newIcon = null; 831 749 if (volumeSlider.getValue() <= 25) 832 750 newIcon = IconRepository.getIcon("vol25.png"); … … 838 756 newIcon = IconRepository.getIcon("vol100.png"); 839 757 840 muteButton.setIcon(newIcon);758 SwingMiscManager.setJButtonIcon(muteButton, newIcon); 841 759 } 842 760 … … 846 764 * Never null. 847 765 */ 848 public String getTrackSourceFrameName() { 766 public String getTrackSourceFrameName() 767 { 849 768 return trackSourceFrameName; 850 769 } 851 770 771 public void setBounds(int x, int y, int width, int height) 772 { 773 panel.setBounds(x, y, width, height); 774 } 775 776 @Override 777 public AxisAlignedBoxBounds getFullBounds() 778 { 779 return SwingConversions.fromSwingRectangle(panel.getBounds()); 780 } 781 852 782 853 783 } -
trunk/src/org/apollo/gui/FastAlphaEffect.java
r315 r1102 60 60 int x, int y, 61 61 int width, int height, 62 int rgb) { 62 int rgb) 63 { 63 64 64 if (raster == null) 65 if (raster == null) { 65 66 throw new NullPointerException("raster"); 66 else if (colorModel == null)67 } else if (colorModel == null) { 67 68 throw new NullPointerException("raster"); 69 } 68 70 69 71 int endcol = x + width; -
trunk/src/org/apollo/gui/FrameLayoutDaemon.java
r1061 r1102 1 1 package org.apollo.gui; 2 2 3 import java.awt.Point;4 import java.awt.event.ComponentEvent;5 import java.awt.event.ComponentListener;6 import java.awt.event.MouseEvent;7 3 import java.io.File; 8 import java.lang.reflect.InvocationTargetException;9 4 import java.util.Collection; 10 5 import java.util.HashMap; 11 6 import java.util.Map; 12 13 import javax.swing.SwingUtilities;14 7 15 8 import org.apollo.audio.ApolloSubjectChangedEvent; … … 30 23 import org.apollo.widgets.LinkedTrack; 31 24 import org.apollo.widgets.SampledTrack; 32 import org.expeditee.gui.Browser; 33 import org.expeditee.gui.DisplayIO; 34 import org.expeditee.gui.DisplayIOObserver; 25 import org.expeditee.core.Point; 26 import org.expeditee.gio.EcosystemManager; 27 import org.expeditee.gio.InputManager.WindowEventListener; 28 import org.expeditee.gio.InputManager.WindowEventType; 29 import org.expeditee.gio.gesture.StandardGestureActions; 30 import org.expeditee.gui.DisplayController; 31 import org.expeditee.gui.DisplayObserver; 35 32 import org.expeditee.gui.Frame; 36 import org.expeditee.gui.FrameMouseActions;37 33 import org.expeditee.gui.FreeItems; 38 import org.expeditee.gui.MouseEventRouter;39 34 import org.expeditee.items.Item; 40 35 import org.expeditee.items.ItemUtils; 41 import org.expeditee.items.widgets. InteractiveWidget;36 import org.expeditee.items.widgets.Widget; 42 37 import org.expeditee.items.widgets.WidgetCorner; 43 38 import org.expeditee.items.widgets.WidgetEdge; … … 46 41 * A daemon that lays out overdubbed frames. 47 42 * 48 * It is a singleton e. Also it is a subject which raises empty events whenever43 * It is a singleton. Also it is a subject which raises empty events whenever 49 44 * a new timeline is created. 50 45 * … … 52 47 * 53 48 */ 54 public class FrameLayoutDaemon extends AbstractSubject implements Observer, Display IOObserver {49 public class FrameLayoutDaemon extends AbstractSubject implements Observer, DisplayObserver { 55 50 56 51 /** The frame that should not be layout out at any point in time. */ … … 98 93 daemon.start(); 99 94 AudioStructureModel.getInstance().addObserver(this); 100 DisplayIO.addDisplayIOObserver(this); 101 102 // Listen for resize events 103 SwingUtilities.invokeLater(new Runnable() { 104 public void run() { 105 106 // Keep expanded view centered to the browser window 107 if (Browser._theBrowser != null) { 108 Browser._theBrowser.addComponentListener(new ComponentListener() { 109 110 public void componentHidden(ComponentEvent e) { 111 } 112 113 public void componentMoved(ComponentEvent e) { 114 } 115 116 public void componentResized(ComponentEvent e) { 117 forceRecheck(); 118 } 119 120 public void componentShown(ComponentEvent e) { 121 } 122 123 }); 124 } 125 95 DisplayController.addDisplayObserver(this); 96 97 EcosystemManager.getInputManager().addWindowEventListener(new WindowEventListener() 98 { 99 @Override 100 public void onWindowEvent(WindowEventType type) 101 { 102 if (type == WindowEventType.WINDOW_RESIZED) forceRecheck(); 126 103 } 127 104 }); … … 321 298 // Note that accessing expeditee model in another thread -- 322 299 // Being real careful not to do anything unsafe 323 Frame currentFrame = Display IO.getCurrentFrame();300 Frame currentFrame = DisplayController.getCurrentFrame(); 324 301 if (currentFrame == null) continue; 325 302 … … 340 317 341 318 try { 342 SwingUtilities.invokeAndWait(trackFormatter);343 } catch ( InterruptedExceptione) {319 EcosystemManager.getMiscManager().runOnGIOThread(trackFormatter); 320 } catch (Throwable e) { 344 321 e.printStackTrace(); 345 } catch (InvocationTargetException e) {346 e.printStackTrace();347 322 } 348 323 … … 359 334 assert(toFormat != null); 360 335 361 // To late?362 if (toFormat != Display IO.getCurrentFrame()) return;336 // Too late? 337 if (toFormat != DisplayController.getCurrentFrame()) return; 363 338 364 339 boolean supressSpatialLayout = suspendedFrame == toFormat; … … 370 345 boolean hasRunningTime = false; // A flag set to true if there is actual audio to [lay 371 346 372 Map< InteractiveWidget, AbstractTrackGraphNode> widgetsToFormat = new HashMap<InteractiveWidget, AbstractTrackGraphNode>();373 374 for ( InteractiveWidget iw : toFormat.getInteractiveWidgets()) {347 Map<Widget, AbstractTrackGraphNode> widgetsToFormat = new HashMap<Widget, AbstractTrackGraphNode>(); 348 349 for (Widget iw : toFormat.getInteractiveWidgets()) { 375 350 376 351 AbstractTrackGraphNode abinf = null; … … 429 404 430 405 // Anything to format? 431 if (!hasRunningTime || 432 widgetsToFormat.isEmpty() || 433 longestEndTime == firstInitiationTime) { 406 if (!hasRunningTime || widgetsToFormat.isEmpty() || longestEndTime == firstInitiationTime) { 434 407 435 408 // NOTE: longestEndTime == firstInitiationTime indicates linked tracks … … 450 423 // Ensure that left most pixel is at a reasonable position 451 424 if (!supressSpatialLayout && (initiationXPixel < 0 || 452 (initiationXPixel > Browser._theBrowser.getWidth() && Browser._theBrowser.getWidth() > leftMargin))) {425 (initiationXPixel > DisplayController.getFramePaintArea().getWidth() && DisplayController.getFramePaintArea().getWidth() > leftMargin))) { 453 426 initiationXPixel = leftMargin; 454 427 } else if (!supressSpatialLayout && initiationXPixel > LAYOUT_MAX_INITIATION_PIXEL) { … … 459 432 timelineWidth = rightMostPixel - initiationXPixel; 460 433 } else { 461 timelineWidth = Browser._theBrowser.getWidth() - initiationXPixel - rightMargin;434 timelineWidth = DisplayController.getFramePaintArea().getWidth() - initiationXPixel - rightMargin; 462 435 } 463 436 … … 483 456 if (!supressSpatialLayout) { 484 457 485 for ( InteractiveWidget iw : widgetsToFormat.keySet()) {458 for (Widget iw : widgetsToFormat.keySet()) { 486 459 487 460 AbstractTrackGraphNode atgi = widgetsToFormat.get(iw); … … 545 518 546 519 Item i = FreeItems.getItemAttachedToCursor(); 547 InteractiveWidget freespaceTrackToFormat = null;520 Widget freespaceTrackToFormat = null; 548 521 if (i != null && i instanceof WidgetEdge) { 549 522 freespaceTrackToFormat = ((WidgetEdge)i).getWidgetSource(); … … 573 546 if (width > 0) { 574 547 575 if (width > (Browser._theBrowser.getWidth() - (2 * FREE_SPACE_MARGINS))) 576 width = Browser._theBrowser.getWidth() - (2 * FREE_SPACE_MARGINS); 548 if (width > (DisplayController.getFramePaintArea().getWidth() - (2 * FREE_SPACE_MARGINS))) { 549 width = DisplayController.getFramePaintArea().getWidth() - (2 * FREE_SPACE_MARGINS); 550 } 577 551 578 552 freespaceTrackToFormat.setSize( … … 582 556 583 557 // Keep the floating track on the cursor 584 MouseEvent me = MouseEventRouter.getCurrentMouseEvent();585 Point containerPoint = SwingUtilities.convertPoint(me.getComponent(), me.getPoint(), Browser._theBrowser.getContentPane());586 558 Point containerPoint = EcosystemManager.getInputManager().getCursorPosition(); 559 560 // If due to resize the track is not longer over the cursor then just center it. 587 561 if (!ItemUtils.expandRectangle(freespaceTrackToFormat.getBounds(), 20).contains(containerPoint)) { 588 // If due to resize the track is not longer over the cursor then just center it.589 562 int offsetX = width / 2; 590 563 int offsetY = freespaceTrackToFormat.getHeight() / 2; 591 freespaceTrackToFormat.setPosition( 592 containerPoint.x - offsetX, 593 containerPoint.y - offsetY); 594 FrameMouseActions.resetOffset(); 595 564 freespaceTrackToFormat.setPosition(containerPoint.x - offsetX, containerPoint.y - offsetY); 565 StandardGestureActions.resetOffset(); 596 566 } 597 567 … … 756 726 757 727 // Look for all track widgets 758 for ( InteractiveWidget iw : frame.getInteractiveWidgets()) {728 for (Widget iw : frame.getInteractiveWidgets()) { 759 729 760 730 if (iw instanceof SampledTrack) { … … 928 898 public static long inferCurrentTotalMSTime() { 929 899 930 Frame currentFrame = Display IO.getCurrentFrame();900 Frame currentFrame = DisplayController.getCurrentFrame(); 931 901 String currentFrameName = (currentFrame != null) ? currentFrame.getName() : null; 932 902 -
trunk/src/org/apollo/gui/FramePlaybackBarRenderer.java
r372 r1102 1 1 package org.apollo.gui; 2 2 3 import java.awt.BasicStroke;4 import java.awt.Color;5 import java.awt.Graphics2D;6 import java.awt.Rectangle;7 import java.awt.Stroke;8 3 import java.util.LinkedList; 9 4 import java.util.List; 10 11 import javax.swing.SwingUtilities;12 5 13 6 import org.apollo.audio.ApolloPlaybackMixer; … … 23 16 import org.apollo.util.AudioMath; 24 17 import org.apollo.widgets.FramePlayer; 18 import org.expeditee.core.Colour; 19 import org.expeditee.core.Stroke; 20 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 21 import org.expeditee.gio.EcosystemManager; 22 import org.expeditee.gio.GraphicsManager; 25 23 import org.expeditee.gui.Browser; 26 import org.expeditee.gui.Display IO;24 import org.expeditee.gui.DisplayController; 27 25 import org.expeditee.gui.Frame; 28 import org.expeditee.gui.FrameGraphics;29 26 30 27 /** … … 50 47 51 48 private static final int BAR_STROKE_THICKNESS = 2; 52 private static final Stroke BAR_STROKE = new BasicStroke(BAR_STROKE_THICKNESS);53 private static final Colo r BAR_COLOR = Color.DARK_GRAY;49 private static final Stroke BAR_STROKE = new Stroke(BAR_STROKE_THICKNESS); 50 private static final Colour BAR_COLOR = Colour.DARK_GREY; 54 51 55 52 private static FramePlaybackBarRenderer instance = new FramePlaybackBarRenderer(); … … 121 118 } 122 119 123 FrameGraphics.refresh(true);120 DisplayController.requestRefresh(true); 124 121 125 122 … … 132 129 currentMSPosition = -1; 133 130 pixelPositions.clear(); 134 FrameGraphics.refresh(true);131 DisplayController.requestRefresh(true); 135 132 136 133 break; … … 140 137 } 141 138 142 private void invalidate() { 139 private void invalidate() 140 { 143 141 if (Browser._theBrowser == null) return; 144 142 145 int height = Browser._theBrowser.getHeight();143 int height = EcosystemManager.getGraphicsManager().getWindowSize().getHeight(); 146 144 147 145 for (Integer n : pixelPositions) { 148 FrameGraphics.invalidateArea(new Rectangle(n - 1, 0, BAR_STROKE_THICKNESS + 2, height)); 149 } 150 } 151 152 public void paint(Graphics2D g) { 146 DisplayController.invalidateArea(new AxisAlignedBoxBounds(n - 1, 0, BAR_STROKE_THICKNESS + 2, height)); 147 } 148 } 149 150 public void paint() 151 { 153 152 if (Browser._theBrowser == null) return; 154 153 155 Frame currentFrame = Display IO.getCurrentFrame();154 Frame currentFrame = DisplayController.getCurrentFrame(); 156 155 157 156 if (currentFrame == null || currentFrame.getName() == null || pixelPositionsParent == null || 158 157 !currentFrame.getName().equals(pixelPositionsParent)) return; 159 158 160 int height = Browser._theBrowser.getHeight(); 161 162 g.setColor(BAR_COLOR); 163 g.setStroke(BAR_STROKE); 159 int height = EcosystemManager.getGraphicsManager().getWindowSize().getHeight(); 160 161 GraphicsManager gm = EcosystemManager.getGraphicsManager(); 164 162 165 163 for (Integer n : pixelPositions) { 166 g .drawLine(n, 0, n, height);164 gm.drawLine(n, 0, n, height, BAR_COLOR, BAR_STROKE); 167 165 } 168 166 } … … 193 191 // Notes: the clock will queue a refresh for the frame after this 194 192 // event proccesses ... 195 SwingUtilities.invokeLater(updator);193 EcosystemManager.getMiscManager().runOnGIOThread(updator); 196 194 } 197 195 … … 201 199 * @author Brook Novak 202 200 */ 203 private class PlaybackFrameBarUpdator implements Runnable { 201 private class PlaybackFrameBarUpdator implements Runnable 202 { 204 203 public void run() { 205 204 206 205 if (currentMSPosition == -1 || currentTimeline == null) return; 207 206 208 Frame currentFrame = Display IO.getCurrentFrame();207 Frame currentFrame = DisplayController.getCurrentFrame(); 209 208 210 209 if (currentFrame == null || currentFrame.getName() == null) return; -
trunk/src/org/apollo/gui/FrameRenderPasses.java
r355 r1102 1 1 package org.apollo.gui; 2 2 3 import java.awt.Color;4 import java.awt.FontMetrics;5 import java.awt.Graphics;6 import java.awt.Graphics2D;7 import java.awt.Rectangle;8 import java.awt.Stroke;9 import java.awt.geom.Area;10 import java.awt.geom.Rectangle2D;11 3 import java.util.LinkedList; 12 4 13 import org.apollo.AudioFrameKeyboardActions; 14 import org.apollo.AudioFrameMouseActions; 5 import org.apollo.ApolloGestureActions; 15 6 import org.apollo.audio.util.Timeline; 16 7 import org.apollo.items.FramePlaybackLauncher; … … 19 10 import org.apollo.widgets.LinkedTrack; 20 11 import org.apollo.widgets.SampledTrack; 12 import org.expeditee.core.Clip; 13 import org.expeditee.core.Colour; 14 import org.expeditee.core.Dimension; 15 import org.expeditee.core.Fill; 16 import org.expeditee.core.Point; 17 import org.expeditee.core.Stroke; 18 import org.expeditee.core.TextLayout; 19 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 20 import org.expeditee.gio.EcosystemManager; 21 import org.expeditee.gio.GraphicsManager; 22 import org.expeditee.gio.gesture.StandardGestureActions; 23 import org.expeditee.gio.input.KBMInputEvent.Key; 24 import org.expeditee.gio.input.StandardInputEventListeners; 21 25 import org.expeditee.gui.Browser; 22 26 import org.expeditee.gui.FrameGraphics; 23 import org.expeditee.gui.FrameMouseActions;24 27 import org.expeditee.gui.FreeItems; 25 28 import org.expeditee.gui.FrameGraphics.FrameRenderPass; 26 29 import org.expeditee.items.Item; 27 import org.expeditee.items.widgets. InteractiveWidget;30 import org.expeditee.items.widgets.Widget; 28 31 import org.expeditee.items.widgets.WidgetCorner; 29 32 import org.expeditee.items.widgets.WidgetEdge; … … 31 34 /** 32 35 * All final effects rendered here - to give extra feedback to the user and simply to make 33 * it more ap ealing.36 * it more appealing. 34 37 * @author Brook Novak 35 38 * … … 37 40 public class FrameRenderPasses implements FrameRenderPass { 38 41 39 private static final Colo r SHADED_EXPANDED_BACKING_COLOR = new Color(80, 80, 80, 140);40 private static final Colo r Y_HELPER_LINES_COLOR = Color.DARK_GRAY;42 private static final Colour SHADED_EXPANDED_BACKING_COLOR = Colour.FromRGBA255(80, 80, 80, 140); 43 private static final Colour Y_HELPER_LINES_COLOR = Colour.DARK_GREY; 41 44 private static final Stroke Y_HELPER_LINES_STROKE = OverdubbedFrameTimeAxis.TRACK_TIMELINE_STROKE; 42 45 … … 48 51 private boolean shouldDrawFullscreenHelpers = false; 49 52 50 private FrameRenderPasses() { 53 private FrameRenderPasses() 54 { 51 55 FrameGraphics.addFrameRenderPass(this); 52 56 } 53 57 54 public static FrameRenderPasses getInstance() { 58 public static FrameRenderPasses getInstance() 59 { 55 60 return instance; 56 61 } 57 62 58 public void paintFinalPass(Graphics g) { 63 public void paintFinalPass() 64 { 59 65 if (Browser._theBrowser == null) return; 60 int frameHeight = Browser._theBrowser.getContentPane().getHeight(); 66 67 GraphicsManager gm = EcosystemManager.getGraphicsManager(); 68 69 int frameHeight = EcosystemManager.getGraphicsManager().getWindowSize().getHeight(); 61 70 if (ExpandedTrackManager.getInstance().isAnyExpandedTrackVisible() 62 71 && !FreeItems.getInstance().isEmpty()) { … … 67 76 for (Item i : FreeItems.getInstance()) { 68 77 if (i instanceof WidgetCorner) { 69 InteractiveWidget iw = ((WidgetCorner)i).getWidgetSource();78 Widget iw = ((WidgetCorner)i).getWidgetSource(); 70 79 71 80 if (iw != null && iw instanceof SampledTrack) { … … 84 93 if (toPaint != null) { 85 94 for (SampledTrack trackWidget : toPaint) { 86 if (g.getClip() == null 87 || g.getClip().intersects(trackWidget.getComponant().getBounds())) 88 trackWidget.paintInFreeSpace(g, true); 89 95 if (gm.peekClip() == null || gm.peekClip().isNotClipped() || (!gm.peekClip().isFullyClipped() && gm.peekClip().getBounds().intersects(trackWidget.getBounds()))) { 96 trackWidget.paintInFreeSpace(true); 97 } 90 98 } 91 99 } … … 93 101 } 94 102 95 OverdubbedFrameTimeAxis.getInstance().paint( g);103 OverdubbedFrameTimeAxis.getInstance().paint(); 96 104 97 105 TimeAxis timeAxis = OverdubbedFrameTimeAxis.getInstance().getTimeAxis(); 98 106 Timeline lastTimeline = OverdubbedFrameTimeAxis.getInstance().getLastTimeline(); 99 107 100 FramePlaybackBarRenderer.getInstance().paint( (Graphics2D)g);108 FramePlaybackBarRenderer.getInstance().paint(); 101 109 102 110 if (timeHelperLinesToPaint != null && timeAxis != null && lastTimeline != null) { 103 111 104 Rectangler = OverdubbedFrameTimeAxis.getInstance().getCurrentTimelineArea();112 AxisAlignedBoxBounds r = OverdubbedFrameTimeAxis.getInstance().getCurrentTimelineArea(); 105 113 106 114 // Draw helper bar and text 107 115 for (Integer x : timeHelperLinesToPaint) { 108 116 109 ((Graphics2D)g).setStroke(OverdubbedFrameTimeAxis.TRACK_TIMELINE_STROKE); 110 g.setColor(Color.RED); 111 112 if (shouldDrawFullscreenHelpers) 113 g.drawLine(x, 0, x, frameHeight); 114 else 115 g.drawLine(x, r.y, x, r.y + r.height); 116 117 if (shouldDrawFullscreenHelpers) { 118 gm.drawLine(new Point(x, 0), new Point(x, frameHeight), Colour.RED, OverdubbedFrameTimeAxis.TRACK_TIMELINE_STROKE); 119 } else { 120 gm.drawLine(new Point(x, r.getMinY()), new Point(x, r.getMinY() + r.getHeight()), Colour.RED, OverdubbedFrameTimeAxis.TRACK_TIMELINE_STROKE); 121 } 122 117 123 long ms = lastTimeline.getMSTimeAtX(x) - lastTimeline.getFirstInitiationTime(); 118 124 … … 120 126 if (ms < 0) label = "-" + label; 121 127 122 FontMetrics fm = g.getFontMetrics(SampledTrackGraphViewPort.TIME_HELPER_FONT); 123 Rectangle2D rect = fm.getStringBounds(label, g); 128 //FontMetrics fm = g.getFontMetrics(SampledTrackGraphViewPort.TIME_HELPER_FONT); 129 //Rectangle2D rect = fm.getStringBounds(label, g); 130 TextLayout layout = EcosystemManager.getTextLayoutManager().layoutStringSimple(label, SampledTrackGraphViewPort.TIME_HELPER_FONT); 131 AxisAlignedBoxBounds rect = layout.getPixelBounds(0, 0); 124 132 int labelWidth = (int)(rect.getWidth()); 125 133 int labelHeight = (int)(rect.getHeight()); 126 134 127 int y = r.y + (r.height / 2) - ((labelHeight + 4) / 2); 128 129 130 g.setColor(SampledTrackGraphViewPort.TIME_HELPER_COLOR); 131 g.fillRect(x + 2, y, labelWidth + 3, labelHeight + 4); 132 133 g.setColor(SampledTrackGraphViewPort.TIME_HELPER_BORDERCOLOR); 134 ((Graphics2D)g).setStroke(SampledTrackGraphViewPort.ZOOM_BACKING_BORDER_STROKE); 135 g.fillRect(x + 2, y, labelWidth + 3, labelHeight + 4); 136 137 g.setFont(SampledTrackGraphViewPort.TIME_HELPER_FONT); 138 g.setColor(Color.BLACK); 139 g.drawString(label, x + 4, y + labelHeight); 140 141 135 int y = r.getMinY() + (r.getHeight() / 2) - ((labelHeight + 4) / 2); 136 137 gm.drawRectangle(new Point(x + 2, y), new Dimension(labelWidth + 3, labelHeight + 4), 0.0, new Fill(SampledTrackGraphViewPort.TIME_HELPER_COLOR), SampledTrackGraphViewPort.TIME_HELPER_BORDERCOLOR, SampledTrackGraphViewPort.ZOOM_BACKING_BORDER_STROKE, null); 138 139 gm.drawTextLayout(layout, new Point(x + 4, y + labelHeight), Colour.BLACK); 142 140 } 143 141 … … 146 144 // Draw Y helper 147 145 if (yAxisTimelineHelperToPaint != null) { 148 149 ((Graphics2D)g).setStroke(Y_HELPER_LINES_STROKE); 150 g.setColor(Y_HELPER_LINES_COLOR); 151 152 g.drawLine( 153 0, 154 yAxisTimelineHelperToPaint.value, 155 Browser._theBrowser.getContentPane().getWidth(), 156 yAxisTimelineHelperToPaint.value); 157 158 } 159 160 161 } 162 163 public void paintPreLayeredPanePass(Graphics g) { 146 gm.drawLine(0, yAxisTimelineHelperToPaint.value, EcosystemManager.getGraphicsManager().getWindowSize().getWidth(), yAxisTimelineHelperToPaint.value, Y_HELPER_LINES_COLOR, Y_HELPER_LINES_STROKE); 147 } 148 149 150 } 151 152 public void paintPreLayeredPanePass() 153 { 164 154 if (Browser._theBrowser == null) return; 165 155 166 156 if (ExpandedTrackManager.getInstance().isAnyExpandedTrackVisible()) { 167 168 g.setColor(SHADED_EXPANDED_BACKING_COLOR); 169 g.fillRect(0, 0, 170 Browser._theBrowser.getContentPane().getWidth(), 171 Browser._theBrowser.getContentPane().getHeight()); 172 } 173 174 } 175 176 public Area paintStarted(Area currentClip) { 157 Dimension windowSize = EcosystemManager.getGraphicsManager().getWindowSize(); 158 EcosystemManager.getGraphicsManager().drawRectangle(Point.ORIGIN, windowSize, 0.0, new Fill(SHADED_EXPANDED_BACKING_COLOR), null, null, null); 159 } 160 161 } 162 163 public Clip paintStarted(Clip currentClip) 164 { 177 165 if (Browser._theBrowser == null) return currentClip; 178 166 179 LinkedList< InteractiveWidget> seen = null;167 LinkedList<Widget> seen = null; 180 168 181 169 //boolean idDirty = false; … … 189 177 timeHelperLinesToPaint = null; 190 178 yAxisTimelineHelperToPaint = null; 191 shouldDrawFullscreenHelpers = AudioFrameKeyboardActions.isControlDown() ||192 ( AudioFrameKeyboardActions.isShiftDown() && !FreeItems.getInstance().isEmpty());179 shouldDrawFullscreenHelpers = StandardInputEventListeners.kbmStateListener.isKeyDown(Key.CTRL) || 180 (StandardInputEventListeners.kbmStateListener.isKeyDown(Key.SHIFT) && !FreeItems.getInstance().isEmpty()); 193 181 194 182 // Get free tracks and paint line helpers 195 if (!FreeItems.getInstance().isEmpty() || FrameMouseActions.getlastHighlightedItem() != null) {183 if (!FreeItems.getInstance().isEmpty() || StandardGestureActions.getlastHighlightedItem() != null) { 196 184 197 185 LinkedList<Item> possibles = new LinkedList<Item>(FreeItems.getInstance()); 198 if (FreeItems.getInstance().isEmpty() && 199 FrameMouseActions.getlastHighlightedItem() != null)200 possibles.add(FrameMouseActions.getlastHighlightedItem());186 if (FreeItems.getInstance().isEmpty() && StandardGestureActions.getlastHighlightedItem() != null) { 187 possibles.add(StandardGestureActions.getlastHighlightedItem()); 188 } 201 189 202 190 for (Item i : possibles) { 203 191 204 InteractiveWidget iw = null;192 Widget iw = null; 205 193 206 194 if (i instanceof WidgetCorner) { … … 216 204 217 205 if (seen == null) { 218 seen = new LinkedList< InteractiveWidget>();206 seen = new LinkedList<Widget>(); 219 207 } else if (seen.contains(iw)) { 220 208 continue; … … 235 223 } 236 224 237 if ((A udioFrameMouseActions.isYAxisRestictionOn() || AudioFrameMouseActions.isSnapOn())225 if ((ApolloGestureActions.isYAxisRestictionOn() || ApolloGestureActions.isSnapOn()) 238 226 && !FreeItems.getInstance().isEmpty()) { 239 227 … … 255 243 } 256 244 257 private void invalidateHelperLines(Area currentClip) { 258 if (currentClip != null) { 259 260 if (timeHelperLinesToPaint != null && !timeHelperLinesToPaint.isEmpty()) { 261 currentClip.add(new Area(OverdubbedFrameTimeAxis.getInstance().getCurrentTimelineArea())); 262 if (shouldDrawFullscreenHelpers) { 263 int fsHeight = Browser._theBrowser.getContentPane().getHeight(); 264 for (Integer n : timeHelperLinesToPaint) { 265 currentClip.add(new Area(new Rectangle(n - 1, 0, 3, fsHeight))); 266 } 267 } 268 } 269 270 if (yAxisTimelineHelperToPaint != null && shouldDrawFullscreenHelpers) { 271 272 currentClip.add(new Area(new Rectangle( 273 0, 274 yAxisTimelineHelperToPaint.value - 1, 275 Browser._theBrowser.getContentPane().getWidth(), 276 3))); 277 278 } 279 } 280 } 281 282 283 284 245 private void invalidateHelperLines(Clip currentClip) 246 { 247 if (currentClip == null) return; 248 249 if (timeHelperLinesToPaint != null && !timeHelperLinesToPaint.isEmpty()) { 250 currentClip.includeBounds(OverdubbedFrameTimeAxis.getInstance().getCurrentTimelineArea().clone()); 251 if (shouldDrawFullscreenHelpers) { 252 int fsHeight = EcosystemManager.getGraphicsManager().getWindowSize().getHeight(); 253 for (Integer n : timeHelperLinesToPaint) { 254 currentClip.includeBounds(new AxisAlignedBoxBounds(n - 1, 0, 3, fsHeight)); 255 } 256 } 257 } 258 259 if (yAxisTimelineHelperToPaint != null && shouldDrawFullscreenHelpers) { 260 261 currentClip.includeBounds(new AxisAlignedBoxBounds( 262 0, 263 yAxisTimelineHelperToPaint.value - 1, 264 EcosystemManager.getGraphicsManager().getWindowSize().getWidth(), 265 3)); 266 267 } 268 } 285 269 } -
trunk/src/org/apollo/gui/OverdubbedFrameTimeAxis.java
r1059 r1102 1 1 package org.apollo.gui; 2 3 import java.awt.BasicStroke;4 import java.awt.Color;5 import java.awt.Graphics;6 import java.awt.Graphics2D;7 import java.awt.Rectangle;8 import java.awt.Stroke;9 import java.awt.event.ComponentEvent;10 import java.awt.event.ComponentListener;11 12 import javax.swing.SwingUtilities;13 2 14 3 import org.apollo.audio.util.Timeline; … … 16 5 import org.apollo.mvc.Subject; 17 6 import org.apollo.mvc.SubjectChangedEvent; 7 import org.expeditee.core.Colour; 8 import org.expeditee.core.Dimension; 9 import org.expeditee.core.Fill; 10 import org.expeditee.core.Point; 11 import org.expeditee.core.Stroke; 12 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 13 import org.expeditee.gio.EcosystemManager; 14 import org.expeditee.gio.GraphicsManager; 15 import org.expeditee.gio.InputManager.WindowEventListener; 16 import org.expeditee.gio.InputManager.WindowEventType; 18 17 import org.expeditee.gui.Browser; 19 import org.expeditee.gui.DisplayIO; 20 import org.expeditee.gui.FrameGraphics; 21 import org.expeditee.gui.MessageBay; 18 import org.expeditee.gui.DisplayController; 22 19 23 20 /** … … 30 27 31 28 private TimeAxis timeAxis = null; 32 private RectanglelastInvalidated;29 private AxisAlignedBoxBounds lastInvalidated; 33 30 private Timeline lastTimeline = null; 34 31 … … 36 33 37 34 private static final int GLOBAL_TIMELINE_HEIGHT = 30; 38 private static final Colo r GLOBAL_TIMELINE_BACKCOLOR = new Color(220, 220, 220, 100);39 private static final Colo r GLOBAL_EMPTY_TIMELINE_BACKCOLOR = new Color(240, 240, 240, 100);35 private static final Colour GLOBAL_TIMELINE_BACKCOLOR = Colour.FromRGBA255(220, 220, 220, 100); 36 private static final Colour GLOBAL_EMPTY_TIMELINE_BACKCOLOR = Colour.FromRGBA255(240, 240, 240, 100); 40 37 41 public static final Stroke TRACK_TIMELINE_STROKE = new BasicStroke( 42 1.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 0.0f, new float[] { 5.0f, 5.0f }, 0.0f); 38 public static final Stroke TRACK_TIMELINE_STROKE = new Stroke(1.0f, Stroke.CAP.SQUARE, Stroke.JOIN.BEVEL, new float[] { 5.0f, 5.0f }, 0.0f); 43 39 44 private static final Stroke TIMELINE_BORDER_STROKE = new BasicStroke(1.0f);40 private static final Stroke TIMELINE_BORDER_STROKE = new Stroke(1.0f); 45 41 46 42 /** … … 54 50 55 51 // Listen for resize events 56 SwingUtilities.invokeLater(new Runnable() { 57 public void run() { 58 59 // Keep expanded view centered to the browser window 60 if (Browser._theBrowser != null) { 61 Browser._theBrowser.addComponentListener(new ComponentListener() { 62 63 public void componentHidden(ComponentEvent e) { 64 } 65 66 public void componentMoved(ComponentEvent e) { 67 } 68 69 public void componentResized(ComponentEvent e) { 70 updateAxis(); 71 } 72 73 public void componentShown(ComponentEvent e) { 74 } 75 76 }); 77 } 78 52 EcosystemManager.getInputManager().addWindowEventListener(new WindowEventListener() 53 { 54 @Override 55 public void onWindowEvent(WindowEventType type) 56 { 57 if (type == WindowEventType.WINDOW_RESIZED) updateAxis(); 79 58 } 80 59 }); … … 113 92 lastTimeline = FrameLayoutDaemon.getInstance().getLastComputedTimeline(); 114 93 if (lastTimeline == null || 115 FrameLayoutDaemon.getInstance().getTimelineOwner() != Display IO.getCurrentFrame()) {94 FrameLayoutDaemon.getInstance().getTimelineOwner() != DisplayController.getCurrentFrame()) { 116 95 117 96 // The frame layout daemon only lays out frames once - unless the user rearranges tracks 118 97 // on a frame then the daemon we re-calc the timeline... thus a timeline must be infferred 119 98 120 lastTimeline = FrameLayoutDaemon.inferTimeline(Display IO.getCurrentFrame());99 lastTimeline = FrameLayoutDaemon.inferTimeline(DisplayController.getCurrentFrame()); 121 100 122 101 if (lastTimeline == null) { // no widgets 123 102 if (timeAxis != null && lastInvalidated != null) { 124 FrameGraphics.invalidateArea(lastInvalidated); // old position103 DisplayController.invalidateArea(lastInvalidated); // old position 125 104 } 126 105 … … 141 120 142 121 143 RectanglenewBounds = getCurrentTimelineArea();122 AxisAlignedBoxBounds newBounds = getCurrentTimelineArea(); 144 123 if (lastInvalidated != null && !lastInvalidated.equals(newBounds)) { 145 FrameGraphics.invalidateArea(lastInvalidated); // old position124 DisplayController.invalidateArea(lastInvalidated); // old position 146 125 } 147 126 148 FrameGraphics.invalidateArea(newBounds);127 DisplayController.invalidateArea(newBounds); 149 128 150 129 lastInvalidated = newBounds; 151 130 152 FrameGraphics.refresh(true);131 DisplayController.requestRefresh(true); 153 132 154 133 } 155 134 156 public Rectangle getCurrentTimelineArea() { 135 public AxisAlignedBoxBounds getCurrentTimelineArea() 136 { 157 137 assert(Browser._theBrowser != null); 158 int y = Browser._theBrowser.getContentPane().getHeight() - GLOBAL_TIMELINE_HEIGHT;159 if (! FrameGraphics.isAudienceMode()) {160 y -= MessageBay.MESSAGE_BUFFER_HEIGHT;138 int y = EcosystemManager.getGraphicsManager().getWindowSize().getHeight() - GLOBAL_TIMELINE_HEIGHT; 139 if (!DisplayController.isAudienceMode()) { 140 y -= DisplayController.getMessageBayPaintArea().getHeight(); 161 141 } 162 142 163 143 if (y < 0) y = 0; 164 144 165 return new Rectangle(0, y, Browser._theBrowser.getContentPane().getWidth(), GLOBAL_TIMELINE_HEIGHT);145 return new AxisAlignedBoxBounds(0, y, EcosystemManager.getGraphicsManager().getWindowSize().getWidth(), GLOBAL_TIMELINE_HEIGHT); 166 146 } 167 147 168 148 169 public void paint(Graphics g) { 149 public void paint() 150 { 170 151 if (Browser._theBrowser == null) return; 171 152 172 153 if (timeAxis != null && lastTimeline != null) { 173 154 174 Rectangle r = getCurrentTimelineArea(); 175 176 g.setColor(GLOBAL_EMPTY_TIMELINE_BACKCOLOR); 177 g.fillRect(0, r.y, Browser._theBrowser.getContentPane().getWidth(), r.height); 155 GraphicsManager gm = EcosystemManager.getGraphicsManager(); 178 156 179 timeAxis.paint(g, 157 AxisAlignedBoxBounds r = getCurrentTimelineArea(); 158 gm.drawRectangle(new Point(0, r.getMinY()), new Dimension(EcosystemManager.getGraphicsManager().getWindowSize().getWidth(), r.getHeight()), 0.0, new Fill(GLOBAL_EMPTY_TIMELINE_BACKCOLOR), null, null, null); 159 160 timeAxis.paint( 180 161 lastTimeline.getInitiationXPixel(), 181 r. y,182 r. height,162 r.getMinY(), 163 r.getHeight(), 183 164 GLOBAL_TIMELINE_BACKCOLOR); 184 165 185 186 g.setColor(Color.DARK_GRAY); 187 188 ((Graphics2D)g).setStroke(TIMELINE_BORDER_STROKE); 189 g.drawLine(0, r.y, Browser._theBrowser.getContentPane().getWidth(), r.y); 166 gm.drawLine(new Point(0, r.getMinY()), new Point(EcosystemManager.getGraphicsManager().getWindowSize().getWidth(), r.getMinY()), Colour.DARK_GREY, TIMELINE_BORDER_STROKE); 190 167 191 168 } -
trunk/src/org/apollo/gui/PlaybackControlPopup.java
r315 r1102 2 2 3 3 import java.awt.Dimension; 4 import java.awt.Graphics2D; 4 5 import java.awt.GridBagConstraints; 5 6 import java.awt.GridBagLayout; … … 8 9 import java.awt.event.ActionListener; 9 10 10 import javax.swing.Icon;11 11 import javax.swing.JButton; 12 import javax.swing.JPanel; 12 13 import javax.swing.JSlider; 13 14 import javax.swing.JToggleButton; … … 16 17 17 18 import org.apollo.io.IconRepository; 19 import org.expeditee.core.Image; 20 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 21 import org.expeditee.gio.swing.SwingConversions; 22 import org.expeditee.gio.swing.SwingMiscManager; 18 23 import org.expeditee.gui.Popup; 24 import org.expeditee.gui.PopupManager.ExpandShrinkAnimator; 19 25 20 26 /** … … 25 31 * 26 32 */ 27 public abstract class PlaybackControlPopup extends Popup implements ActionListener { 28 33 public abstract class PlaybackControlPopup extends Popup implements ActionListener 34 { 35 public JPanel panel; 29 36 public JButton playPauseButton; 30 37 public JButton stopButton; … … 39 46 private static final int BUTTON_SIZE = 40; 40 47 41 protected PlaybackControlPopup() { 42 super(new GridBagLayout()); 48 protected PlaybackControlPopup() 49 { 50 super(new ExpandShrinkAnimator()); 51 52 panel = new JPanel(new GridBagLayout()); 43 53 44 54 playPauseButton = new JButton(); 45 55 playPauseButton.setActionCommand("playpause"); 46 56 playPauseButton.addActionListener(this); 47 playPauseButton.setIcon(IconRepository.getIcon("play.png"));57 SwingMiscManager.setJButtonIcon(playPauseButton, IconRepository.getIcon("play.png")); 48 58 playPauseButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE)); 49 59 playPauseButton.setToolTipText("Play selection / Pause"); … … 53 63 stopButton.addActionListener(this); 54 64 stopButton.setActionCommand("stop"); 55 stopButton.setIcon(IconRepository.getIcon("stop.png"));65 SwingMiscManager.setJButtonIcon(stopButton, IconRepository.getIcon("stop.png")); 56 66 stopButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE)); 57 67 stopButton.setToolTipText("Stop playback"); … … 60 70 rewindButton.addActionListener(this); 61 71 rewindButton.setActionCommand("rewind"); 62 rewindButton.setIcon(IconRepository.getIcon("rewind.png"));72 SwingMiscManager.setJButtonIcon(rewindButton, IconRepository.getIcon("rewind.png")); 63 73 rewindButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE)); 64 74 rewindButton.setToolTipText("Rewind to start"); … … 66 76 // Icon changes 67 77 muteButton = new JToggleButton(); 68 muteButton.setSelectedIcon(IconRepository.getIcon("volmute.png"));78 SwingMiscManager.setJButtonSelectedIcon(muteButton, IconRepository.getIcon("volmute.png")); 69 79 muteButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE)); 70 80 muteButton.setToolTipText("Toggle mute"); … … 78 88 79 89 soloButton = new JToggleButton(); 80 soloButton.setIcon(IconRepository.getIcon("solo.png"));81 soloButton.setSelectedIcon(IconRepository.getIcon("soloon.png"));90 SwingMiscManager.setJButtonIcon(soloButton, IconRepository.getIcon("solo.png")); 91 SwingMiscManager.setJButtonSelectedIcon(soloButton, IconRepository.getIcon("soloon.png")); 82 92 soloButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE)); 83 93 soloButton.setToolTipText("Toggle solo"); … … 115 125 c.gridy = 0; 116 126 c.fill = GridBagConstraints.BOTH; 117 add(playPauseButton, c);127 panel.add(playPauseButton, c); 118 128 119 129 c = new GridBagConstraints(); … … 121 131 c.gridy = 0; 122 132 c.fill = GridBagConstraints.BOTH; 123 add(stopButton, c);133 panel.add(stopButton, c); 124 134 125 135 c = new GridBagConstraints(); … … 127 137 c.gridy = 0; 128 138 c.fill = GridBagConstraints.BOTH; 129 add(rewindButton, c);139 panel.add(rewindButton, c); 130 140 131 141 c = new GridBagConstraints(); … … 133 143 c.gridy = 0; 134 144 c.fill = GridBagConstraints.BOTH; 135 add(soloButton, c);145 panel.add(soloButton, c); 136 146 137 147 c = new GridBagConstraints(); … … 139 149 c.gridy = 0; 140 150 c.fill = GridBagConstraints.BOTH; 141 add(muteButton, c);151 panel.add(muteButton, c); 142 152 143 153 c = new GridBagConstraints(); … … 146 156 c.fill = GridBagConstraints.BOTH; 147 157 c.insets = new Insets(0,VOLUME_SPACING,0,VOLUME_SPACING); 148 add(volumeSlider, c);158 panel.add(volumeSlider, c); 149 159 150 160 c = new GridBagConstraints(); … … 152 162 c.gridy = 0; 153 163 c.fill = GridBagConstraints.BOTH; 154 add(miscButton, c);164 panel.add(miscButton, c); 155 165 156 166 // … … 201 211 // this.setSize(BUTTON_SIZE * 4, BUTTON_SIZE * 2); 202 212 203 this.setSize(BUTTON_SIZE * 8, BUTTON_SIZE);204 205 this.doLayout();213 panel.setSize(BUTTON_SIZE * 8, BUTTON_SIZE); 214 215 panel.doLayout(); 206 216 207 217 } … … 213 223 private void updateButtonGUI() { 214 224 215 I connewIcon = null;225 Image newIcon = null; 216 226 if (volumeSlider.getValue() <= 25) 217 227 newIcon = IconRepository.getIcon("vol25.png"); … … 223 233 newIcon = IconRepository.getIcon("vol100.png"); 224 234 225 muteButton.setIcon(newIcon); 226 } 227 228 235 SwingMiscManager.setJButtonIcon(muteButton, newIcon); 236 } 237 238 @Override 239 protected void paintInternal() 240 { 241 Graphics2D g = SwingMiscManager.getIfUsingSwingGraphicsManager().getCurrentSurface(); 242 AxisAlignedBoxBounds bounds = getBounds(); 243 244 g.translate(bounds.getMinX(), bounds.getMinY()); 245 panel.paint(g); 246 g.translate(-bounds.getMinX(), -bounds.getMinY()); 247 } 248 249 @Override 250 public AxisAlignedBoxBounds getFullBounds() 251 { 252 return SwingConversions.fromSwingRectangle(panel.getBounds()); 253 } 254 229 255 public abstract void actionPerformed(ActionEvent e); 230 256 -
trunk/src/org/apollo/gui/SampledTrackGraphView.java
r1007 r1102 1 1 package org.apollo.gui; 2 2 3 import java.awt.BasicStroke; 3 4 import java.awt.Color; 4 5 import java.awt.Event; … … 10 11 import java.awt.Point; 11 12 import java.awt.Rectangle; 12 import java.awt.Stroke;13 13 import java.awt.event.ComponentEvent; 14 14 import java.awt.event.ComponentListener; 15 import java.awt.image.BufferedImage;16 15 import java.util.LinkedList; 17 16 import java.util.List; … … 31 30 import org.apollo.mvc.Subject; 32 31 import org.apollo.mvc.SubjectChangedEvent; 32 import org.expeditee.core.Image; 33 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 34 import org.expeditee.gio.swing.SwingConversions; 35 import org.expeditee.gio.swing.SwingMiscManager; 33 36 import org.expeditee.gui.Browser; 34 import org.expeditee.gui. FrameGraphics;37 import org.expeditee.gui.DisplayController; 35 38 36 39 /** … … 59 62 60 63 private WaveFormRenderProccessingUnit.WaveFormRenderTask renderTask = null; 61 private BufferedImage backBuffer = null; // Shared resource64 private Image backBuffer = null; // Shared resource 62 65 private int bufferWidth = -1; // cached from backBuffer - so don't have to lock 63 66 private int bufferHeight = -1; // cached from backBuffer - so don't have to lock … … 67 70 private int timescaleFrameLength = 0; // in frames 68 71 69 private final Font RENDER_MESSAGE_FONT = new Font("Arial", Font. ITALIC | Font.BOLD, 14);72 private final Font RENDER_MESSAGE_FONT = new Font("Arial", Font.BOLD | Font.ITALIC, 14); 70 73 71 74 private boolean alwaysFullViewOn = false; … … 80 83 81 84 /** The stroke used for drawing graph bars. E.G: The selection Start bar. */ 82 public static final Stroke GRAPH_BAR_STROKE = Strokes.SOLID_1;85 public static final BasicStroke GRAPH_BAR_STROKE = SwingConversions.toSwingStroke(Strokes.SOLID_1); 83 86 public static final int GRAPH_BAR_NWIDTH = 1; 84 87 … … 139 142 this, 140 143 0, 0, 141 Browser._theBrowser.getContentPane());144 SwingMiscManager.getIfUsingSwingGraphicsManager().getContentPane()); 142 145 } 143 146 … … 339 342 340 343 if (x >= 0 && x <= viewWidth) { // is the playback position in view? 341 FrameGraphics.invalidateArea(new Rectangle(344 DisplayController.invalidateArea(new AxisAlignedBoxBounds( 342 345 x + expediteePosition.x, 343 346 expediteePosition.y, … … 356 359 357 360 if (x >= 0 && x <= viewWidth) { // is the playback position in view? 358 FrameGraphics.invalidateArea(new Rectangle(361 DisplayController.invalidateArea(new AxisAlignedBoxBounds( 359 362 x + expediteePosition.x , 360 363 expediteePosition.y, … … 565 568 566 569 renderTask = null; // must be on swing thread because could be painting 567 if (backBuffer != null) backBuffer. flush();570 if (backBuffer != null) backBuffer.releaseImage(); 568 571 backBuffer = null; // must be on swing thread because could be painting 569 572 } … … 605 608 606 609 // Create new sized buffer 607 backBuffer = new BufferedImage( 610 backBuffer = Image.createImage(width, height); 611 /* backBuffer = new BufferedImage( 608 612 width, 609 613 height, 610 614 BufferedImage.TYPE_BYTE_INDEXED, 611 ApolloColorIndexedModels.graphIndexColorModel); 615 ApolloColorIndexedModels.graphIndexColorModel);*/ 612 616 } 613 617 } … … 624 628 ); 625 629 626 // Wait for invalidation recom endation messages630 // Wait for invalidation recommendation messages 627 631 renderTask.addObserver(this); 628 632 … … 693 697 synchronized(backBuffer) { 694 698 695 g.drawImage( backBuffer,699 g.drawImage(SwingMiscManager.getIfUsingSwingImageManager().getInternalImage(backBuffer), 696 700 0, 697 701 0, 698 702 getWidth(), 699 getHeight(), 703 getHeight(), 700 704 null); 701 705 … … 709 713 // No need to synchronize waveformBuffer because there is no thread accessing it, 710 714 // and a new render thread is always created on this thread. 711 g.drawImage( backBuffer,715 g.drawImage(SwingMiscManager.getIfUsingSwingImageManager().getInternalImage(backBuffer), 712 716 0, 713 717 0, 714 718 getWidth(), 715 getHeight(), 719 getHeight(), 716 720 null); 717 721 … … 919 923 * 920 924 */ 921 public interface EffecientInvalidator { 925 public interface EffecientInvalidator 926 { 922 927 public void onGraphDirty(SampledTrackGraphView graph, Rectangle dirty); 923 928 } 924 929 925 public Color getBackColor() { 930 public Color getBackColor() 931 { 926 932 return backColor; 927 933 } … … 935 941 * 936 942 */ 937 public void setBackColor(Color backColor, Color highlights) { 943 public void setBackColor(Color backColor, Color highlights) 944 { 938 945 setBackColor(backColor, highlights, true); 939 946 } … … 949 956 * Doesnt invalidate if the color has not changed. 950 957 */ 951 public void setBackColor(Color backColor, Color highlights, boolean invalidate) { 958 public void setBackColor(Color backColor, Color highlights, boolean invalidate) 959 { 952 960 if (backColor == null) throw new NullPointerException("backColor"); 953 961 if (this.backColor != backColor || backColorHighlights != highlights) { -
trunk/src/org/apollo/gui/SampledTrackGraphViewPort.java
r356 r1102 1 1 package org.apollo.gui; 2 2 3 import java.awt.Color;4 3 import java.awt.Event; 5 import java.awt.Font;6 import java.awt.FontMetrics;7 4 import java.awt.Graphics; 8 5 import java.awt.Graphics2D; 9 import java.awt.Stroke;10 6 import java.awt.event.ComponentEvent; 11 7 import java.awt.event.ComponentListener; … … 17 13 import java.awt.event.MouseWheelEvent; 18 14 import java.awt.event.MouseWheelListener; 19 import java.awt.geom.Rectangle2D;20 import java.awt.image.BufferedImage;21 15 import java.util.LinkedList; 22 16 import java.util.List; … … 27 21 import org.apollo.mvc.SubjectChangedEvent; 28 22 import org.apollo.util.AudioMath; 29 import org.expeditee.gui.Browser; 23 import org.expeditee.core.Colour; 24 import org.expeditee.core.Font; 25 import org.expeditee.core.Stroke; 26 import org.expeditee.core.TextLayout; 27 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 28 import org.expeditee.gio.EcosystemManager; 29 import org.expeditee.gio.swing.SwingConversions; 30 import org.expeditee.gio.swing.SwingMiscManager; 30 31 31 32 public class SampledTrackGraphViewPort extends SampledTrackGraphView … … 43 44 private static final int ZOOM_ADJUSTMENT_MODE_MODIFYZOOM = 3; 44 45 45 public static final Colo r ZOOM_BACKING_COLOR_NORMAL = new Color(251, 255, 168);46 private static final Colo r ZOOM_BACKING_COLOR_HIGHLIGHT = new Color(255, 255, 224);47 private static final Colo r ZOOM_BACKING_BORDER_COLOR = new Color(215, 219, 144);46 public static final Colour ZOOM_BACKING_COLOR_NORMAL = Colour.FromRGB255(251, 255, 168); 47 private static final Colour ZOOM_BACKING_COLOR_HIGHLIGHT = Colour.FromRGB255(255, 255, 224); 48 private static final Colour ZOOM_BACKING_BORDER_COLOR = Colour.FromRGB255(215, 219, 144); 48 49 public static final Stroke ZOOM_BACKING_BORDER_STROKE = Strokes.SOLID_1; 49 50 50 public static final Font TIME_HELPER_FONT = new Font("Arial", Font. PLAIN, 12);51 public static final Colo r TIME_HELPER_COLOR = new Color(132, 175, 201);52 public static final Colo r TIME_HELPER_BORDERCOLOR = new Color(111, 146, 168);51 public static final Font TIME_HELPER_FONT = new Font("Arial", Font.Style.PLAIN, 12); 52 public static final Colour TIME_HELPER_COLOR = Colour.FromRGB255(132, 175, 201); 53 public static final Colour TIME_HELPER_BORDERCOLOR = Colour.FromRGB255(111, 146, 168); 53 54 54 55 // displays the current zoom or the new zoom-selection … … 67 68 private List<ZoomChangeListener> zoomChangeListeners = new LinkedList<ZoomChangeListener>(); 68 69 69 public SampledTrackGraphViewPort() { 70 public SampledTrackGraphViewPort() 71 { 70 72 super(); 71 73 72 setBackColor( new Color(250, 250, 250), new Color(230, 230, 230));74 setBackColor(SwingConversions.toSwingColor(Colour.FromRGB255(250, 250, 250)), SwingConversions.toSwingColor(Colour.FromRGB255(230, 230, 230))); 73 75 setAlwaysFullView(true); 74 76 … … 531 533 void paint(Graphics g) { 532 534 533 color = (zoomAdjustmentMode == ZOOM_ADJUSTMENT_MODE_NONE) ? 534 ZOOM_BACKING_COLOR_NORMAL : ZOOM_BACKING_COLOR_HIGHLIGHT; 535 color = SwingConversions.toSwingColor((zoomAdjustmentMode == ZOOM_ADJUSTMENT_MODE_NONE) ? ZOOM_BACKING_COLOR_NORMAL : ZOOM_BACKING_COLOR_HIGHLIGHT); 535 536 super.paint(g); 536 537 537 g.setColor( ZOOM_BACKING_BORDER_COLOR);538 ((Graphics2D)g).setStroke( ZOOM_BACKING_BORDER_STROKE);538 g.setColor(SwingConversions.toSwingColor(ZOOM_BACKING_BORDER_COLOR)); 539 ((Graphics2D)g).setStroke(SwingConversions.toSwingStroke(ZOOM_BACKING_BORDER_STROKE)); 539 540 g.drawLine(left, 0, left, getHeight()); 540 541 g.drawLine(left + width, 0, left + width, getHeight()); … … 542 543 } 543 544 544 void postPaint(Graphics g) {545 // Paint little helper labels when ajusting view port546 if (startTimeHelpLabel != null && endTimeHelpLabel != null &&547 548 549 g.setColor( TIME_HELPER_COLOR);545 void postPaint(Graphics g) 546 { 547 // Paint little helper labels when adjusting view port 548 if (startTimeHelpLabel != null && endTimeHelpLabel != null && zoomAdjustmentMode != ZOOM_ADJUSTMENT_MODE_NONE) { 549 550 g.setColor(SwingConversions.toSwingColor(TIME_HELPER_COLOR)); 550 551 g.fillRect(labelStartX - 2, labelStartY - labelHeight + 2, labelWidth + 3, labelHeight); 551 552 g.fillRect(labelEndX - 2, labelEndY - labelHeight + 2, labelWidth + 3, labelHeight); 552 553 553 g.setColor( TIME_HELPER_BORDERCOLOR);554 ((Graphics2D)g).setStroke( ZOOM_BACKING_BORDER_STROKE);554 g.setColor(SwingConversions.toSwingColor(TIME_HELPER_BORDERCOLOR)); 555 ((Graphics2D)g).setStroke(SwingConversions.toSwingStroke(ZOOM_BACKING_BORDER_STROKE)); 555 556 g.drawRect(labelStartX - 2, labelStartY - labelHeight + 2, labelWidth + 3, labelHeight); 556 557 g.drawRect(labelEndX - 2, labelEndY - labelHeight + 2, labelWidth + 3, labelHeight); 557 558 558 g.setFont( TIME_HELPER_FONT);559 g.setColor( Color.BLACK);559 g.setFont(SwingMiscManager.getIfUsingSwingFontManager().getInternalFont(TIME_HELPER_FONT)); 560 g.setColor(SwingConversions.toSwingColor(Colour.BLACK)); 560 561 g.drawString(startTimeHelpLabel, labelStartX, labelStartY); 561 562 g.drawString(endTimeHelpLabel, labelEndX, labelEndY); … … 603 604 604 605 // Create a temp graphics for centered label positioning 605 if (Browser._theBrowser != null && Browser._theBrowser.g != null) {606 /*if (Browser._theBrowser != null && Browser._theBrowser.g != null) { 606 607 g = Browser._theBrowser.g.create(); 607 608 } else { 608 609 g = new BufferedImage(1,1,BufferedImage.TYPE_BYTE_INDEXED).getGraphics(); 609 } 610 }*/ 610 611 611 612 // Position labels 612 FontMetrics fm = g.getFontMetrics(TIME_HELPER_FONT); 613 Rectangle2D rect = fm.getStringBounds(startTimeHelpLabel, g); 613 //FontMetrics fm = g.getFontMetrics(TIME_HELPER_FONT); 614 //Rectangle2D rect = fm.getStringBounds(startTimeHelpLabel, g); 615 TextLayout layout = EcosystemManager.getTextLayoutManager().layoutStringSimple(startTimeHelpLabel, TIME_HELPER_FONT); 616 AxisAlignedBoxBounds rect = layout.getPixelBounds(0, 0); 614 617 615 618 labelWidth = (int)rect.getWidth(); -
trunk/src/org/apollo/gui/Strokes.java
r356 r1102 1 1 package org.apollo.gui; 2 2 3 import java.awt.BasicStroke; 4 import java.awt.Stroke; 3 import org.expeditee.core.Stroke; 5 4 6 5 public class Strokes { … … 9 8 } 10 9 11 public static final Stroke SOLID_1 = new BasicStroke(1.0f);12 public static final Stroke SOLID_2 = new BasicStroke(2.0f);10 public static final Stroke SOLID_1 = new Stroke(1.0f); 11 public static final Stroke SOLID_2 = new Stroke(2.0f); 13 12 14 13 } -
trunk/src/org/apollo/gui/TimeAxis.java
r375 r1102 1 1 package org.apollo.gui; 2 2 3 import java.awt.Color;4 import java.awt.Font;5 import java.awt.FontMetrics;6 import java.awt.GradientPaint;7 import java.awt.Graphics;8 import java.awt.Graphics2D;9 import java.awt.Stroke;10 import java.awt.geom.Rectangle2D;11 import java.awt.image.BufferedImage;12 3 import java.util.LinkedList; 13 4 14 5 import org.apollo.ApolloSystem; 15 import org.expeditee.gui.Browser; 6 import org.expeditee.core.Colour; 7 import org.expeditee.core.Dimension; 8 import org.expeditee.core.Fill; 9 import org.expeditee.core.Font; 10 import org.expeditee.core.GradientFill; 11 import org.expeditee.core.Point; 12 import org.expeditee.core.Stroke; 13 import org.expeditee.core.TextLayout; 14 import org.expeditee.gio.EcosystemManager; 15 import org.expeditee.gio.GraphicsManager; 16 import org.expeditee.gio.swing.SwingConversions; 16 17 17 18 /** … … 23 24 public class TimeAxis { 24 25 25 private static final long serialVersionUID = 1L; 26 27 public static final Font TIME_BAR_FONT = new Font("Arial", Font.PLAIN, 14); 26 public static final Font TIME_BAR_FONT = new Font("Arial", Font.Style.PLAIN, 14); 28 27 private static final Stroke TICK_STROKE = Strokes.SOLID_1; 29 28 30 private static final Colo r MAJOR_TICK_COLOR = Color.BLACK;31 private static final Colo r MINOR_TICK_COLOR = new Color(0.4f, 0.4f, 0.4f);29 private static final Colour MAJOR_TICK_COLOR = Colour.BLACK; 30 private static final Colour MINOR_TICK_COLOR = new Colour(0.4f, 0.4f, 0.4f); 32 31 33 32 private static final int DESIRED_MAJOR_TICK_PIXEL_SPACING = 100; … … 43 42 private long totalTrackMSLength = 0; 44 43 45 public TimeAxis() { 44 public TimeAxis() 45 { 46 46 } 47 47 … … 51 51 long timeLengthSamples, 52 52 long totalTrackMSLength, 53 int width) { 53 int width) 54 { 54 55 55 56 assert(width > 0); … … 146 147 LinkedList<Integer> majorTickLabelPositions = new LinkedList<Integer>(); 147 148 148 Graphics g = null; 149 try { 150 151 152 // Create a temp graphics for centered label positioning 153 if (Browser._theBrowser != null && Browser._theBrowser.g != null) { 154 g = Browser._theBrowser.g.create(); 155 } else { 156 g = new BufferedImage(1,1,BufferedImage.TYPE_BYTE_INDEXED).getGraphics(); 157 } 158 159 do { 160 161 majorTickPositions.add(new Integer((int)currentTickX)); 162 163 String label = createSpecificTimeLabel((long)currentTickTime, timeAggregation); 164 165 majorTickLabels.add(label); 166 167 // Center label 168 FontMetrics fm = g.getFontMetrics(TIME_BAR_FONT); 169 Rectangle2D rect = fm.getStringBounds(label, g); 170 int textWidth = (int)(rect.getWidth()); 171 172 majorTickLabelPositions.add(new Integer((int)currentTickX - (textWidth >> 1))); 173 174 currentTickX += majorTickPixelSpacing; 175 currentTickTime += timeAggregation; 176 177 } while (currentTickX < width); 178 179 180 } finally { 181 if (g != null) 182 g.dispose(); 183 } 149 do { 150 majorTickPositions.add(new Integer((int)currentTickX)); 151 152 String label = createSpecificTimeLabel((long)currentTickTime, timeAggregation); 153 154 majorTickLabels.add(label); 155 156 // Center label 157 int textWidth = EcosystemManager.getTextLayoutManager().layoutStringSimple(label, TIME_BAR_FONT).getPixelBounds(0, 0).getWidth(); 158 159 majorTickLabelPositions.add(new Integer((int)currentTickX - (textWidth >> 1))); 160 161 currentTickX += majorTickPixelSpacing; 162 currentTickTime += timeAggregation; 163 164 } while (currentTickX < width); 184 165 185 166 this.majorTickLabels = majorTickLabels.toArray(new String[0]); … … 227 208 228 209 229 public String createSpecificTimeLabel(long atTime, double timeAggregation) {230 210 public String createSpecificTimeLabel(long atTime, double timeAggregation) 211 { 231 212 Long min = null; 232 213 Long sec = null; … … 261 242 } 262 243 263 public static String createTimeLabel(Long min, Long sec, Long ms) {264 244 public static String createTimeLabel(Long min, Long sec, Long ms) 245 { 265 246 if (min == null && sec == null && ms != null) { 266 247 return ms + "ms"; … … 314 295 } 315 296 316 public void paint( Graphics g, int x, int y, int height, Color backgroundColor) {297 public void paint(int x, int y, int height, Colour backgroundColor) { 317 298 318 299 int majorTickHeight = height / 2; … … 320 301 321 302 // Draw backing 303 Fill backingFill; 322 304 if (ApolloSystem.useQualityGraphics) { 323 324 GradientPaint gp = new GradientPaint( 325 x + (width / 2), y + (int)(height * 0.5), backgroundColor, 326 x + (width / 2), y, SampledTrackGraphView.DEFAULT_BACKGROUND_HIGHTLIGHTS_COLOR); 327 ((Graphics2D)g).setPaint(gp); 328 305 backingFill = new GradientFill(backgroundColor, new Point(x + (width / 2), y + (int)(height * 0.5)), SwingConversions.fromSwingColor(SampledTrackGraphView.DEFAULT_BACKGROUND_HIGHTLIGHTS_COLOR), new Point(x + (width / 2), y)); 329 306 } else { 330 g.setColor(backgroundColor);331 } 332 333 g.fillRect(x, y, width, height);334 335 g .setFont(TIME_BAR_FONT);307 backingFill = new Fill(backgroundColor); 308 } 309 310 GraphicsManager gm = EcosystemManager.getGraphicsManager(); 311 312 gm.drawRectangle(new Point(x, y), new Dimension(width, height), 0.0, backingFill, null, null, null); 336 313 337 314 if (majorTickXPositions != null) { 338 339 ((Graphics2D)g).setStroke(TICK_STROKE);340 341 g.setColor(MAJOR_TICK_COLOR);342 315 // Draw Major ticks and labels 343 316 for (int i = 0; i < majorTickLabels.length; i++) { 344 317 345 318 // Label 346 g .drawString(319 gm.drawString( 347 320 majorTickLabels[i], 348 x + majorTickLabelXPositions[i], 349 y + height - 2); 321 new Point(x + majorTickLabelXPositions[i], y + height - 2), 322 TIME_BAR_FONT, 323 MAJOR_TICK_COLOR); 350 324 351 325 // Tick 352 g.drawLine( 353 x + majorTickXPositions[i], 326 gm.drawLine(x + majorTickXPositions[i], 354 327 y, 355 328 x + majorTickXPositions[i], 356 y + majorTickHeight );329 y + majorTickHeight, MAJOR_TICK_COLOR, TICK_STROKE); 357 330 358 331 } 359 360 g.setColor(MINOR_TICK_COLOR);361 332 362 333 // Draw minor ticks 363 334 if (minorTickXPositions != null) { 364 335 for (int tx : minorTickXPositions) { 365 g .drawLine(336 gm.drawLine( 366 337 x + tx, 367 338 y, 368 339 x + tx, 369 y + minorTickHeight );340 y + minorTickHeight, MINOR_TICK_COLOR, TICK_STROKE); 370 341 } 371 342 } … … 373 344 } else if (alternateLabel != null) { 374 345 375 g.setColor(Color.BLACK); 376 377 FontMetrics fm = g.getFontMetrics(TIME_BAR_FONT); 378 Rectangle2D rect = fm.getStringBounds(alternateLabel, g); 379 int textWidth = (int)(rect.getWidth()); 380 381 g.drawString( 382 alternateLabel, 383 x + ((width >> 1) - (textWidth >> 1)), 384 y + (height - 2)); 385 386 } 387 388 } 389 390 public int getWidth() { 346 TextLayout layout = EcosystemManager.getTextLayoutManager().layoutStringSimple(alternateLabel, TIME_BAR_FONT); 347 348 int textWidth = layout.getPixelBounds(0, 0).getWidth(); 349 gm.drawTextLayout(layout, new Point(x + ((width >> 1) - (textWidth >> 1)), y + (height - 2)), Colour.BLACK); 350 351 } 352 353 } 354 355 public int getWidth() 356 { 391 357 return width; 392 358 } -
trunk/src/org/apollo/gui/TimeAxisPanel.java
r315 r1102 12 12 13 13 import org.apollo.util.AudioMath; 14 import org.expeditee.gio.swing.SwingConversions; 14 15 15 16 /** … … 30 31 private TimeAxis timeAxis = new TimeAxis(); 31 32 32 public TimeAxisPanel(SampledTrackGraphView graph) { 33 public TimeAxisPanel(SampledTrackGraphView graph) 34 { 33 35 assert (graph != null); 34 36 … … 37 39 38 40 // Auto-adjust scale when component resizes. 39 this.addComponentListener(new ComponentListener() { 40 41 public void componentHidden(ComponentEvent e) { 41 this.addComponentListener(new ComponentListener() 42 { 43 public void componentHidden(ComponentEvent e) 44 { 42 45 } 43 46 44 public void componentMoved(ComponentEvent e) { 47 public void componentMoved(ComponentEvent e) 48 { 45 49 } 46 50 47 public void componentResized(ComponentEvent e) { 51 public void componentResized(ComponentEvent e) 52 { 48 53 updateAxis(); 49 54 } 50 55 51 public void componentShown(ComponentEvent e) { 56 public void componentShown(ComponentEvent e) 57 { 52 58 } 53 54 59 }); 55 60 … … 58 63 59 64 60 public void timelineChanged(Event e) { 65 public void timelineChanged(Event e) 66 { 61 67 updateAxis(); 62 68 } 63 69 64 70 65 private void updateAxis() {66 71 private void updateAxis() 72 { 67 73 // Is track model even set yet? 68 if (observedSubject.getSampledTrackModel() == null || 69 getWidth() == 0) return; 74 if (observedSubject.getSampledTrackModel() == null || getWidth() == 0) return; 70 75 71 76 AudioFormat format = observedSubject.getSampledTrackModel().getFormat(); 72 77 73 long startTimeMS = AudioMath.framesToMilliseconds( 74 observedSubject.getTimeScaleStart(), format); 78 long startTimeMS = AudioMath.framesToMilliseconds(observedSubject.getTimeScaleStart(), format); 75 79 76 long timeLengthMS = AudioMath.framesToMilliseconds( 77 observedSubject.getTimeScaleLength(), format); 80 long timeLengthMS = AudioMath.framesToMilliseconds(observedSubject.getTimeScaleLength(), format); 78 81 79 long totalTrackMSLength = AudioMath.framesToMilliseconds( 80 observedSubject.getSampledTrackModel().getFrameCount(), format); 82 long totalTrackMSLength = AudioMath.framesToMilliseconds(observedSubject.getSampledTrackModel().getFrameCount(), format); 81 83 82 84 timeAxis.setAxis( … … 92 94 93 95 @Override 94 public void paint(Graphics g) { 95 timeAxis.paint(g, 0, 0, getHeight(), getBackground()); 96 public void paint(Graphics g) 97 { 98 timeAxis.paint(0, 0, getHeight(), SwingConversions.fromSwingColor(getBackground())); 96 99 } 97 100 -
trunk/src/org/apollo/gui/TimelineChangeListener.java
r315 r1102 3 3 import java.awt.Event; 4 4 5 public interface TimelineChangeListener { 5 public interface TimelineChangeListener 6 { 6 7 void timelineChanged(Event e); 7 8 } -
trunk/src/org/apollo/gui/VolumeControlButton.java
r343 r1102 1 1 package org.apollo.gui; 2 2 3 import java.awt.Color;4 3 import java.awt.Dimension; 5 4 import java.awt.GridBagConstraints; 6 5 import java.awt.GridBagLayout; 7 6 import java.awt.Insets; 8 import java.awt.Point;9 7 import java.awt.event.ActionEvent; 10 8 import java.awt.event.ActionListener; … … 12 10 import java.util.List; 13 11 14 import javax.swing.Icon;15 12 import javax.swing.JButton; 13 import javax.swing.JPanel; 16 14 import javax.swing.JSlider; 17 15 import javax.swing.event.ChangeEvent; … … 19 17 20 18 import org.apollo.io.IconRepository; 19 import org.expeditee.core.Colour; 20 import org.expeditee.core.Image; 21 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 22 import org.expeditee.gio.swing.SwingConversions; 23 import org.expeditee.gio.swing.SwingMiscManager; 21 24 import org.expeditee.gui.Popup; 22 25 import org.expeditee.gui.PopupManager; 26 import org.expeditee.gui.PopupManager.ExpandShrinkAnimator; 23 27 24 28 /** … … 40 44 private String volumeTag; 41 45 42 private Colo r SELECTED_BACKCOLOR = Color.GRAY;43 private Colo r UNSELECTED_BACKCOLOR = null;46 private Colour SELECTED_BACKCOLOR = Colour.GRAY; 47 private Colour UNSELECTED_BACKCOLOR = null; 44 48 45 49 private static final int VOL_ADJUSTMENT = 10; … … 52 56 * E.G. "Master Volume". 53 57 */ 54 public VolumeControlButton(String volumeTag) { 58 public VolumeControlButton(String volumeTag) 59 { 55 60 super(); 56 UNSELECTED_BACKCOLOR = getBackground();61 UNSELECTED_BACKCOLOR = SwingConversions.fromSwingColor(getBackground()); 57 62 vcPopup = new VolumeControlPopup(); 58 vcPopup.setVisible(false);63 PopupManager.getInstance().add(vcPopup); 59 64 this.volumeTag = volumeTag; 60 65 toggleSelectionState(false); … … 68 73 * @param listener 69 74 */ 70 public void addVolumeChangeListener(ChangeListener listener) { 75 public void addVolumeChangeListener(ChangeListener listener) 76 { 71 77 assert(listener != null); 72 78 changeListeners.add(listener); 73 79 } 74 80 75 private void fireVolumeChanged() { 81 private void fireVolumeChanged() 82 { 76 83 for (ChangeListener a : changeListeners) { 77 84 a.stateChanged(new ChangeEvent(this)); … … 79 86 } 80 87 81 private void toggleSelectionState(boolean selected) { 82 if (selected) setBackground(SELECTED_BACKCOLOR); 83 else setBackground(UNSELECTED_BACKCOLOR); 88 private void toggleSelectionState(boolean selected) 89 { 90 if (selected) { 91 setBackground(SwingConversions.toSwingColor(SELECTED_BACKCOLOR)); 92 } else { 93 setBackground(SwingConversions.toSwingColor(UNSELECTED_BACKCOLOR)); 94 } 84 95 } 85 96 … … 89 100 */ 90 101 @Override 91 protected void fireActionPerformed(ActionEvent event) { 102 protected void fireActionPerformed(ActionEvent event) 103 { 92 104 super.fireActionPerformed(event); 93 105 94 if (!vcPopup.isVisible()) { // show popup 95 106 if (!vcPopup.isShowing()) { // show popup 96 107 vcPopup.showPopup(); 97 98 108 } else { // hide popup 99 100 PopupManager.getInstance().hidePopup(vcPopup, 101 PopupManager.getInstance().new ExpandShrinkAnimator( 102 VolumeControlButton.this.getBounds(), 103 Color.LIGHT_GRAY)); 109 vcPopup.hide(); 104 110 } 105 111 } … … 133 139 * @return 134 140 */ 135 public void setMuted(boolean mute) { 141 public void setMuted(boolean mute) 142 { 136 143 muted = mute; 137 144 updateButtonGUI(); … … 139 146 140 147 141 private void updateButtonGUI() {142 143 I connewIcon;148 private void updateButtonGUI() 149 { 150 Image newIcon; 144 151 if(muted) 145 152 newIcon = IconRepository.getIcon("volmute.png"); … … 153 160 newIcon = IconRepository.getIcon("vol100.png"); 154 161 155 if (newIcon != getIcon()) setIcon(newIcon);162 if (newIcon != getIcon()) SwingMiscManager.setJButtonIcon(this, newIcon); 156 163 157 164 if (muted) { 158 if (volumeTag != null) setToolTipText(volumeTag + ": Muted"); 159 else setToolTipText("Muted"); 160 } 161 else { 162 if (volumeTag != null) setToolTipText(volumeTag + ": " + volumeValue + "%"); 163 else setToolTipText(volumeValue + "%"); 165 if (volumeTag != null) { 166 setToolTipText(volumeTag + ": Muted"); 167 } else { 168 setToolTipText("Muted"); 169 } 170 } else { 171 if (volumeTag != null) { 172 setToolTipText(volumeTag + ": " + volumeValue + "%"); 173 } else { 174 setToolTipText(volumeValue + "%"); 175 } 164 176 } 165 177 } … … 169 181 * @return The volume value of the gui 170 182 */ 171 public int getVolumeValue() { 183 public int getVolumeValue() 184 { 172 185 return volumeValue; 173 186 } … … 178 191 * @return The mute value of the gui 179 192 */ 180 public boolean getMuteValue() { 193 public boolean getMuteValue() 194 { 181 195 return muted; 182 196 } 183 197 184 private class VolumeControlPopup extends Popup { 185 186 private static final long serialVersionUID = 1L; 187 198 private class VolumeControlPopup extends Popup 199 { 200 private JPanel panel; 188 201 private JSlider volumeSlider; 189 202 private JButton increaseButton; … … 193 206 * Constructor. 194 207 */ 195 public VolumeControlPopup() { 196 super(); 208 public VolumeControlPopup() 209 { 210 super(new ExpandShrinkAnimator()); 211 212 panel = new JPanel(); 197 213 198 214 volumeSlider = new JSlider(JSlider.VERTICAL); … … 226 242 } 227 243 228 private void onIncrementVolume() { 244 private void onIncrementVolume() 245 { 229 246 if (setVolumeValue(volumeValue + VOL_ADJUSTMENT)) { 230 247 fireVolumeChanged(); … … 232 249 } 233 250 234 private void onDeincrementVolume() { 251 private void onDeincrementVolume() 252 { 235 253 if (setVolumeValue(volumeValue - VOL_ADJUSTMENT)) { 236 254 fireVolumeChanged(); … … 238 256 } 239 257 240 private void onVolumeSliderChanged() { 258 private void onVolumeSliderChanged() 259 { 241 260 if (setVolumeValue(volumeSlider.getValue())) { 242 261 fireVolumeChanged(); … … 244 263 } 245 264 246 private void updatePopupGUI() { 265 private void updatePopupGUI() 266 { 247 267 volumeSlider.setValue(volumeValue); 248 268 increaseButton.setEnabled(volumeValue < 100); … … 250 270 } 251 271 252 private void prepLayout() {253 254 if ( this.getComponents().length == 0) {272 private void prepLayout() 273 { 274 if (panel.getComponents().length == 0) { 255 275 256 276 final int INNER_SPACING = 0; … … 286 306 c.insets = new Insets(OUTER_SPACING,OUTER_SPACING,INNER_SPACING,OUTER_SPACING); 287 307 c.ipady = YPAD; 288 this.add(increaseButton, c);308 panel.add(increaseButton, c); 289 309 290 310 c = new GridBagConstraints(); … … 294 314 c.insets = new Insets(INNER_SPACING,OUTER_SPACING,INNER_SPACING,OUTER_SPACING); 295 315 c.ipady = YPAD; 296 this.add(volumeSlider, c);316 panel.add(volumeSlider, c); 297 317 298 318 c = new GridBagConstraints(); … … 302 322 c.insets = new Insets(INNER_SPACING,OUTER_SPACING,OUTER_SPACING,OUTER_SPACING); 303 323 c.ipady = YPAD; 304 this.add(decreaseButton, c);305 306 setSize(targetWidth, volumeSlider.getHeight() + (2 * buttonSizes.height) 307 + (2 * OUTER_SPACING));308 this.doLayout();309 } 310 311 }312 313 private void showPopup(){324 panel.add(decreaseButton, c); 325 326 setSize(targetWidth, volumeSlider.getHeight() + (2 * buttonSizes.height) + (2 * OUTER_SPACING)); 327 panel.doLayout(); 328 } 329 330 } 331 332 private void showPopup() 333 { 314 334 prepLayout(); 315 335 show(); 336 } 337 338 @Override 339 public void onHide() { 340 // Toggle state = volume popup showing 341 toggleSelectionState(false); 342 } 343 344 @Override 345 public void onShow() { 346 // Toggle state = volume popup showing 347 toggleSelectionState(true); 348 } 349 350 @Override 351 public boolean shouldConsumeBackClick() 352 { 353 return true; 354 } 355 356 @Override 357 protected void paintInternal() 358 { 359 // TODO Auto-generated method stub 360 361 } 362 363 @Override 364 public AxisAlignedBoxBounds getFullBounds() 365 { 316 366 // Determine where popup should show 317 367 int x = VolumeControlButton.this.getX(); … … 321 371 y = VolumeControlButton.this.getY() + VolumeControlButton.this.getHeight() + 2; 322 372 } 323 324 PopupManager.getInstance().showPopup( 325 this, 326 new Point(x, y), 327 VolumeControlButton.this, 328 PopupManager.getInstance().new ExpandShrinkAnimator( 329 VolumeControlButton.this.getBounds(), 330 Color.LIGHT_GRAY)); 331 } 332 333 @Override 334 public void onHide() { 335 // Toggle state = volume popup showing 336 toggleSelectionState(false); 337 } 338 339 @Override 340 public void onShow() { 341 // Toggle state = volume popup showing 342 toggleSelectionState(true); 343 } 344 345 @Override 346 public boolean shouldConsumeBackClick() { 347 return true; 348 } 349 350 351 352 } 353 373 374 return new AxisAlignedBoxBounds(x, y, VolumeControlButton.this.getBounds().width, VolumeControlButton.this.getBounds().height); 375 } 376 } 354 377 } -
trunk/src/org/apollo/gui/WaveFormRenderProccessingUnit.java
r355 r1102 2 2 3 3 import java.awt.Graphics2D; 4 import java.awt.image.BufferedImage;5 4 import java.util.LinkedList; 6 5 … … 10 9 import org.apollo.mvc.AbstractSubject; 11 10 import org.apollo.mvc.SubjectChangedEvent; 11 import org.expeditee.core.Image; 12 import org.expeditee.gio.swing.SwingConversions; 13 import org.expeditee.gio.swing.SwingMiscManager; 12 14 13 15 public class WaveFormRenderProccessingUnit { … … 176 178 bufferWidth = currentTask.imageBuffer.getWidth(); 177 179 178 g = currentTask.imageBuffer.createGraphics();179 180 g.setStroke(S trokes.SOLID_1);180 g = SwingMiscManager.getIfUsingSwingImageManager().getImageGraphics(currentTask.imageBuffer); 181 182 g.setStroke(SwingConversions.toSwingStroke(Strokes.SOLID_1)); 181 183 182 184 // Clear the buffer with transparent pixels 183 g.setBackground( ApolloColorIndexedModels.KEY_COLOR);185 g.setBackground(SwingConversions.toSwingColor(ApolloColorIndexedModels.KEY_COLOR)); 184 186 g.clearRect(0, 0, bufferWidth, currentTask.imageBuffer.getHeight()); 185 187 … … 233 235 synchronized(currentTask.imageBuffer) { 234 236 235 g.setColor( ApolloColorIndexedModels.WAVEFORM_COLOR);237 g.setColor(SwingConversions.toSwingColor(ApolloColorIndexedModels.WAVEFORM_COLOR)); 236 238 237 239 if (aggregationSize == 1) { … … 344 346 private static final int STATE_STOPPED = 3; 345 347 346 private BufferedImage imageBuffer; // nullified when stopped.348 private Image imageBuffer; // nullified when stopped. 347 349 private byte[] audioBytes; // nullified when stopped. - Arrays (not contents) are immutable so no need to worry about threading issues with indexes 348 350 private final int startFrame; … … 352 354 353 355 public WaveFormRenderTask( 354 BufferedImage imageBuffer,356 Image imageBuffer, 355 357 byte[] audioBytes, 356 358 AudioFormat format, -
trunk/src/org/apollo/gui/WaveFormRenderer.java
r315 r1102 13 13 * 14 14 * A single height is calculated for one or more frames, which is specified by the 15 * aggregationSize. The way in which waveforms are rendered is implementation depend ant.15 * aggregationSize. The way in which waveforms are rendered is implementation dependent. 16 16 * 17 17 * @param audioBytes … … 22 22 * 23 23 * @param frameLength 24 * The amountof frames to consider for rendering.24 * The number of frames to consider for rendering. 25 25 * 26 26 * @param aggregationSize 27 * The amou t of frames to aggregate.27 * The amount of frames to aggregate. 28 28 * 29 29 * @return -
trunk/src/org/apollo/gui/ZoomChangeListener.java
r315 r1102 3 3 import java.awt.Event; 4 4 5 public interface ZoomChangeListener { 5 public interface ZoomChangeListener 6 { 6 7 void zoomChanged(Event e); 7 8 } -
trunk/src/org/apollo/io/AudioIO.java
r1007 r1102 167 167 if (!sourceFormat.getEncoding().toString().startsWith("PCM")) { 168 168 169 AudioFormat.Encoding conversionEncoding = 170 (sourceFormat.getSampleSizeInBits() == 8) ? 171 AudioFormat.Encoding.PCM_UNSIGNED : 172 AudioFormat.Encoding.PCM_SIGNED; 169 AudioFormat.Encoding conversionEncoding = (sourceFormat.getSampleSizeInBits() == 8) ? AudioFormat.Encoding.PCM_UNSIGNED : AudioFormat.Encoding.PCM_SIGNED; 173 170 174 171 aisConverter = AudioSystem.getAudioInputStream(conversionEncoding, aisConverter); -
trunk/src/org/apollo/io/IconRepository.java
r759 r1102 1 1 package org.apollo.io; 2 2 3 import java.awt.Color;4 import java.awt.Graphics2D;5 import java.awt.Image;6 import java.awt.image.BufferedImage;7 3 import java.net.URL; 8 4 import java.util.HashMap; 9 5 10 import javax.swing.Icon;11 import javax.swing.ImageIcon;12 13 6 import org.apollo.gui.Strokes; 7 import org.expeditee.core.Colour; 8 import org.expeditee.core.Image; 9 import org.expeditee.core.Line; 10 import org.expeditee.gio.EcosystemManager; 11 import org.expeditee.gio.GraphicsManager; 14 12 15 13 /** 16 * An icon provider. Only loads icons once and when they are requested (s omple proxy approach).14 * An icon provider. Only loads icons once and when they are requested (simple proxy approach). 17 15 * 18 16 * @author Brook Novak … … 21 19 public final class IconRepository { 22 20 23 private static HashMap<String, Icon> _loadedIcons = new HashMap<String, Icon>(); 24 private static Icon missingIcon = null; 21 private static HashMap<String, Image> _loadedIcons = new HashMap<String, Image>(); 22 23 private static Image missingIcon = null; 25 24 26 private IconRepository() {} 25 private IconRepository() 26 { 27 } 27 28 28 private static I con getMissingIcon() {29 29 private static Image getMissingIcon() 30 { 30 31 if (missingIcon == null) { 31 32 32 Image image = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB); 33 Graphics2D g = (Graphics2D)image.getGraphics(); 33 Image image = EcosystemManager.getImageManager().createImage(16, 16, false); 34 34 35 g.setStroke(Strokes.SOLID_2);35 GraphicsManager g = EcosystemManager.getGraphicsManager(); 36 36 37 // White square with X 38 g.setColor(Color.WHITE); 39 g.fillRect(0, 0, 16, 16); 37 g.pushDrawingSurface(image); 40 38 41 g.setColor(Color.RED); 42 g.drawLine(0, 0, 16, 16); 43 g.drawLine(0, 16, 16, 0); 39 g.clear(Colour.WHITE); 40 41 Line l1 = new Line(0, 0, 16, 16); 42 Line l2 = new Line(0, 16, 16, 0); 43 44 g.drawLine(l1, Colour.RED, Strokes.SOLID_2); 45 g.drawLine(l2, Colour.RED, Strokes.SOLID_2); 44 46 45 missingIcon = new ImageIcon(image); 47 g.popDrawingSurface(); 48 49 missingIcon = image; 46 50 } 47 51 … … 54 58 * @return 55 59 */ 56 public static Icon getIcon(String name) { 57 Icon icon = _loadedIcons.get(name); 60 public static Image getIcon(String name) 61 { 62 Image icon = _loadedIcons.get(name); 58 63 59 64 if (icon == null) { 60 65 try { 61 66 URL url; 62 67 ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 63 68 if (classLoader!=null) { 64 69 // Applet friendly 65 70 url = classLoader.getResource("org/apollo/assets/icons/" + name); 66 } 67 else { 71 } else { 68 72 url = ClassLoader.getSystemResource("org/apollo/assets/icons/" + name); 69 73 } 70 74 71 if (url != null) { 72 icon = new ImageIcon(url); 73 } 74 75 if (url != null) icon = Image.getImage(url); 75 76 } catch (Exception e) { 76 77 e.printStackTrace(); -
trunk/src/org/apollo/io/SampledAudioFileImporter.java
r318 r1102 1 1 package org.apollo.io; 2 2 3 import java.awt.Point;4 3 import java.io.File; 5 4 import java.io.IOException; 6 5 7 6 import org.apollo.widgets.SampledTrack; 8 import org.expeditee.gui.DisplayIO; 7 import org.expeditee.core.Point; 8 import org.expeditee.gui.DisplayController; 9 9 import org.expeditee.importer.FileImporter; 10 10 import org.expeditee.items.Item; … … 18 18 public class SampledAudioFileImporter implements FileImporter { 19 19 20 public Item importFile(File f, Point location) throws IOException { 21 22 if (location == null || !AudioIO.canImportFile(f) || 23 DisplayIO.getCurrentFrame() == null) return null; 20 public Item importFile(File f, Point location) throws IOException 21 { 22 if (location == null || !AudioIO.canImportFile(f) || DisplayController.getCurrentFrame() == null) return null; 24 23 25 24 SampledTrack trackWidget = SampledTrack.createFromFile( 26 25 f, 27 Display IO.getCurrentFrame(),26 DisplayController.getCurrentFrame(), 28 27 location.x, 29 28 location.y); 30 29 31 30 // Add the sampled track widget to the current frame 32 Display IO.getCurrentFrame().addAllItems(trackWidget.getItems());31 DisplayController.getCurrentFrame().addAllItems(trackWidget.getItems()); 33 32 34 33 return trackWidget.getSource(); // Don't allow for other importers to deal with this file -
trunk/src/org/apollo/items/EmulatedTextItem.java
r489 r1102 1 1 package org.apollo.items; 2 2 3 import java.awt.AWTException;4 import java.awt.Color;5 import java.awt.Component;6 import java.awt.Cursor;7 import java.awt.Font;8 import java.awt.Graphics;9 import java.awt.Graphics2D;10 import java.awt.IllegalComponentStateException;11 import java.awt.Point;12 import java.awt.Rectangle;13 import java.awt.Robot;14 import java.awt.Shape;15 3 import java.awt.event.KeyEvent; 16 4 import java.awt.event.KeyListener; … … 18 6 import java.awt.event.MouseListener; 19 7 import java.awt.event.MouseMotionListener; 20 import java.awt.geom.Area;21 import java.awt.geom.Point2D;22 8 import java.util.LinkedList; 23 9 import java.util.List; 24 10 25 import javax.swing.JComponent; 26 import javax.swing.SwingUtilities; 27 28 import org.expeditee.gui.Browser; 29 import org.expeditee.gui.DisplayIO; 11 import org.expeditee.core.Clip; 12 import org.expeditee.core.Colour; 13 import org.expeditee.core.Cursor; 14 import org.expeditee.core.Font; 15 import org.expeditee.core.Point; 16 import org.expeditee.core.EnforcedClipStack.EnforcedClipKey; 17 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 18 import org.expeditee.gio.EcosystemManager; 19 import org.expeditee.gio.GraphicsManager; 20 import org.expeditee.gio.gesture.StandardGestureActions; 21 import org.expeditee.gui.DisplayController; 30 22 import org.expeditee.gui.Frame; 31 import org.expeditee.gui.FrameGraphics;32 import org.expeditee.gui.FrameMouseActions;33 import org.expeditee.gui.MouseEventRouter;34 23 import org.expeditee.gui.Popup; 35 24 import org.expeditee.gui.PopupManager; … … 38 27 39 28 /** 40 *41 29 * Its a terrible hack - but it will do. 42 30 * … … 44 32 * 45 33 */ 46 public class EmulatedTextItem { 47 48 private static final long serialVersionUID = 1L; 49 50 private static Robot robot; 51 34 public class EmulatedTextItem 35 { 52 36 private List<TextChangeListener> textChangeListeners = new LinkedList<TextChangeListener>(); 53 37 54 38 private RestrictedTextItem emulatedSource; 55 39 private LabelEditPopup popup = null; 56 private JComponent parentComponant = null; 57 private Point masterOffset; 58 59 private static final Font DEFAULT_FONT = new Font("Serif-Plain", Font.PLAIN, 12); 60 61 static { 62 try { 63 robot = new Robot(); 64 } catch (AWTException e) { 65 e.printStackTrace(); 66 } 67 } 40 41 private static final Font DEFAULT_FONT = new Font("Serif-Plain", Font.Style.PLAIN, 12); 68 42 69 43 /** … … 77 51 * Must not be null. 78 52 */ 79 public EmulatedTextItem(JComponent parent, Point offset) { 80 assert(parent != null); 81 assert(offset != null); 82 83 parentComponant = parent; 84 masterOffset = offset; 53 public EmulatedTextItem(String text, Point position) 54 { 55 assert(position != null); 56 85 57 emulatedSource = new RestrictedTextItem(); 86 emulatedSource.setPosition(p arent.getX() + offset.x, parent.getY() + offset.y);58 emulatedSource.setPosition(position); 87 59 emulatedSource.setFont(DEFAULT_FONT); 88 89 } 90 91 92 public void setFontStyle(int style) { 93 emulatedSource.setFont(emulatedSource.getFont().deriveFont(style)); 94 } 95 96 public void setFontSize(float size) { 60 emulatedSource.setText(text); 61 62 popup = new LabelEditPopup(); 63 PopupManager.getInstance().add(popup); 64 } 65 66 @Override 67 public void finalize() 68 { 69 PopupManager.getInstance().remove(popup); 70 } 71 72 public void setFontStyle(Font.Style style) 73 { 74 emulatedSource.setFont(emulatedSource.getFont().clone().setStyle(style)); 75 } 76 77 public void setFontSize(float size) 78 { 97 79 emulatedSource.setSize(size); 98 80 } 99 81 82 public void setPosition(Point position) 83 { 84 emulatedSource.setPosition(position); 85 } 100 86 101 87 /** … … 107 93 * True if the event is over the emulated item. 108 94 */ 109 private boolean isOnEmulatedText(MouseEvent swingME) { 110 if (swingME == null) return false; 111 Point p = convertToExpediteeSpace(swingME.getLocationOnScreen()); 95 private boolean isOnEmulatedText() 96 { 97 Point p = EcosystemManager.getInputManager().getCursorPosition(); 98 112 99 return isOnEmulatedText(p.x, p.y); 113 100 } 114 101 115 private boolean isOnEmulatedText(int expX, int expY) { 102 private boolean isOnEmulatedText(int expX, int expY) 103 { 116 104 return emulatedSource.contains(expX, expY); 117 }118 119 private Point convertToExpediteeSpace(Point screenPos) {120 assert(screenPos != null);121 122 Point expPoint = new Point(0, 0);123 SwingUtilities.convertPointToScreen(expPoint, Browser._theBrowser.getContentPane());124 125 return new Point(screenPos.x - expPoint.x, screenPos.y - expPoint.y);126 105 } 127 106 … … 132 111 * @param parent 133 112 */ 134 public boolean onMouseMoved(MouseEvent e , Component parent) {135 136 if (isOnEmulatedText( e)) {113 public boolean onMouseMoved(MouseEvent e) 114 { 115 if (isOnEmulatedText()) { 137 116 138 117 if (emulatedSource.getHighlightMode() != HighlightMode.Normal) { 139 118 emulatedSource.setHighlightMode(HighlightMode.Normal); 119 emulatedSource.setHighlightColorToDefault(); 140 120 repaint(); 141 121 } 142 122 143 if (parent != popup &&144 (emulatedSource.getBoundsWidth() + masterOffset.x) > (parent.getWidth() - 10)) { // have some give to transition over widget edge145 if (popup == null) {146 popup = new LabelEditPopup();147 }148 149 int x = (emulatedSource.getPolygon() == null) ? parent.getX() + masterOffset.x : emulatedSource.getPolygon().getBounds().x;150 int y = (emulatedSource.getPolygon() == null) ? parent.getY() + masterOffset.y : emulatedSource.getPolygon().getBounds().y;151 x -= 2;152 y -= 2;153 154 if (!PopupManager.getInstance().isShowing(popup)) {155 PopupManager.getInstance().showPopup(156 popup,157 new Point(x, y),158 popup);159 }160 161 }162 163 123 return true; 164 165 124 } else { 166 167 125 lostFocus(); 168 169 126 } 170 127 171 128 return false; 172 173 } 174 175 /** 176 * 177 * @param e 178 * 179 * @param parent 180 */ 181 public boolean onKeyPressed(KeyEvent e, Component parent) { 182 183 MouseEvent currentME = MouseEventRouter.getCurrentMouseEvent(); 184 185 if (currentME == null) return false; 186 187 Point p = convertToExpediteeSpace(currentME.getLocationOnScreen()); 129 } 130 131 public boolean onKeyTyped(KeyEvent e) 132 { 133 Point p = EcosystemManager.getInputManager().getCursorPosition(); 188 134 189 135 // If so and the event really comes from its parent ... 190 if (currentME.getComponent() == parent && 191 (isOnEmulatedText(p.x, p.y))) { 192 193 int yOffset = (parent == popup) ? -6 : -6; 194 195 Browser._theBrowser.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)); 136 if (isOnEmulatedText(p.x, p.y)) { 137 138 int yOffset = -6; 139 140 EcosystemManager.getGraphicsManager().setCursor(new Cursor(Cursor.CursorType.TEXT)); 196 141 197 142 // If a alphanumeric text entry... 198 if (!e.isActionKey() && 199 (Character.isLetterOrDigit(e.getKeyChar()) || 200 (e.getKeyChar() == KeyEvent.VK_BACK_SPACE && !emulatedSource.isEmpty()) || 201 (e.getKeyChar() == KeyEvent.VK_DELETE && !emulatedSource.isEmpty()) || 202 e.getKeyChar() == KeyEvent.VK_SPACE || 203 e.getKeyChar() == KeyEvent.VK_UNDERSCORE) || 204 e.getKeyChar() == KeyEvent.VK_AMPERSAND || 205 e.getKeyChar() == KeyEvent.VK_OPEN_BRACKET || 206 e.getKeyChar() == KeyEvent.VK_CLOSE_BRACKET || 207 e.getKeyChar() == KeyEvent.VK_MINUS) { 208 209 210 Rectangle[] oldArea = emulatedSource.getDrawingArea(); 211 int oldWidth = emulatedSource.getBoundsWidth(); 212 143 if (!e.isActionKey() && 144 Character.isLetterOrDigit(e.getKeyChar()) || 145 (e.getKeyChar() == Text.BACKSPACE_CHARACTER && !emulatedSource.isEmpty()) || 146 (e.getKeyChar() == Text.DELETE_CHARACTER && !emulatedSource.isEmpty()) || 147 e.getKeyChar() == ' ' || 148 e.getKeyChar() == '_' || 149 e.getKeyChar() == '&' || 150 e.getKeyChar() == '(' || 151 e.getKeyChar() == ')' || 152 e.getKeyChar() == '-' 153 ) 154 { 213 155 // Insert the text according to the current mouse position 214 Point2D.Float newMouse = emulatedSource.insertChar( 215 e.getKeyChar(), 216 p.x, 217 p.y); 156 Point newMouse = emulatedSource.insertChar(e.getKeyChar(), p.x, p.y); 218 157 219 158 List<String> lines = emulatedSource.getTextList(); … … 225 164 fireTextChanged(); 226 165 227 // Move "curs ured mouse"166 // Move "cursored mouse" 228 167 if (newMouse != null) { 229 Point bloc = Browser._theBrowser.getContentPane().getLocationOnScreen(); 230 robot.mouseMove(bloc.x + (int)newMouse.x, bloc.y + (int)newMouse.y + yOffset); 168 EcosystemManager.getInputManager().setCursorPosition(new Point((int) newMouse.x, (int) newMouse.y + yOffset)); 231 169 } 232 233 // Invalidate emulated item if not in popup (popup will naturally handle invalidation)234 if (parent != popup) {235 236 if (oldWidth > emulatedSource.getBoundsWidth()) {237 for (Rectangle r : oldArea)238 FrameGraphics.invalidateArea(r);239 }240 241 repaint();242 243 }244 245 } else if (e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_RIGHT) {246 247 Point2D.Float newMouse = emulatedSource.moveCursor(248 (e.getKeyCode() == KeyEvent.VK_LEFT) ? Text.LEFT : Text.RIGHT,249 (float)p.getX(), (float)p.getY(), false, false);250 251 if (newMouse != null) {252 Point bloc = Browser._theBrowser.getContentPane().getLocationOnScreen();253 robot.mouseMove(bloc.x + (int)newMouse.x, bloc.y + (int)newMouse.y + yOffset);254 }255 256 170 } 257 171 … … 274 188 * @param parent 275 189 */ 276 public boolean onKeyReleased(KeyEvent e, Component parent) { 277 return isOnEmulatedText(MouseEventRouter.getCurrentMouseEvent()); 278 279 } 280 281 282 public boolean onMouseReleased(MouseEvent e) { 283 284 Point p = convertToExpediteeSpace(e.getLocationOnScreen()); 190 public boolean onKeyPressed(KeyEvent e) 191 { 192 Point p = EcosystemManager.getInputManager().getCursorPosition(); 285 193 286 194 // If so and the event really comes from its parent ... 287 195 if (isOnEmulatedText(p.x, p.y)) { 288 196 197 int yOffset = -6; 198 199 EcosystemManager.getGraphicsManager().setCursor(new Cursor(Cursor.CursorType.TEXT)); 200 201 // If a alphanumeric text entry... 202 if (e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_RIGHT) { 203 204 Point newMouse = emulatedSource.moveCursor( 205 (e.getKeyCode() == KeyEvent.VK_LEFT) ? Text.LEFT : Text.RIGHT, 206 (float)p.getX(), (float)p.getY(), false, false); 207 208 if (newMouse != null) { 209 EcosystemManager.getInputManager().setCursorPosition(new Point((int) newMouse.x, (int) newMouse.y + yOffset)); 210 } 211 212 } 213 214 if (emulatedSource.hasSelection()) { 215 emulatedSource.clearSelection(); 216 repaint(); 217 } 218 219 return true; 220 221 } 222 223 return false; 224 } 225 226 /** 227 * 228 * @param e 229 * 230 * @param parent 231 */ 232 public boolean onKeyReleased(KeyEvent e) 233 { 234 return isOnEmulatedText(); 235 } 236 237 238 public boolean onMouseReleased(MouseEvent e) 239 { 240 Point p = EcosystemManager.getInputManager().getCursorPosition(); 241 242 // If so and the event really comes from its parent ... 243 if (isOnEmulatedText(p.x, p.y)) { 289 244 290 245 String toMoveIntoFreespace = null; … … 292 247 if (e.getButton() == MouseEvent.BUTTON1) { 293 248 // LINK 294 } else if (e.getButton() == MouseEvent.BUTTON2 && 295 emulatedSource.hasSelection() && 296 !emulatedSource.isEmpty() && 297 emulatedSource.selectionMouseButton == MouseEvent.BUTTON2) { 249 } else if (e.getButton() == MouseEvent.BUTTON2 && emulatedSource.hasSelection() && !emulatedSource.isEmpty()) { 298 250 299 251 invalidate(); … … 301 253 toMoveIntoFreespace = emulatedSource.cutSelectedText(); 302 254 303 } else if (e.getButton() == MouseEvent.BUTTON3 && 304 emulatedSource.hasSelection() && 305 !emulatedSource.isEmpty() && 306 emulatedSource.selectionMouseButton == MouseEvent.BUTTON3) { 255 } else if (e.getButton() == MouseEvent.BUTTON3 && emulatedSource.hasSelection() && !emulatedSource.isEmpty()) { 307 256 toMoveIntoFreespace = emulatedSource.copySelectedText(); 308 257 … … 315 264 if (toMoveIntoFreespace != null) { 316 265 317 Frame target = Display IO.getCurrentFrame();266 Frame target = DisplayController.getCurrentFrame(); 318 267 if (target != null) { 319 268 Text selectionCopy = new Text(target.getNextItemID(), toMoveIntoFreespace); 320 269 selectionCopy.setPosition(p.x, p.y); 321 270 selectionCopy.setSize(emulatedSource.getSize()); 322 FrameMouseActions.pickup(selectionCopy);271 StandardGestureActions.pickup(selectionCopy); 323 272 lostFocus(); 324 273 } … … 336 285 } 337 286 338 public boolean onMousePressed(MouseEvent e) {339 340 Point p = convertToExpediteeSpace(e.getLocationOnScreen());287 public boolean onMousePressed(MouseEvent e) 288 { 289 Point p = EcosystemManager.getInputManager().getCursorPosition(); 341 290 342 291 // If so and the event really comes from its parent ... … … 354 303 } 355 304 356 public boolean onMouseClicked(MouseEvent e) { 357 return isOnEmulatedText(e); 358 } 359 public boolean onMouseDragged(MouseEvent e) { 360 361 Point p = convertToExpediteeSpace(e.getLocationOnScreen()); 305 public boolean onMouseClicked(MouseEvent e) 306 { 307 return isOnEmulatedText(); 308 } 309 310 public boolean onMouseDragged(MouseEvent e) 311 { 312 Point p = EcosystemManager.getInputManager().getCursorPosition(); 362 313 363 314 // If so and the event really comes from its parent ... 364 315 if (isOnEmulatedText(p.x, p.y)) { 365 316 366 Browser._theBrowser.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));317 EcosystemManager.getGraphicsManager().setCursor(new Cursor(Cursor.CursorType.TEXT)); 367 318 368 319 emulatedSource.setSelectionEnd(p.x, p.y); … … 375 326 } 376 327 377 public void addTextChangeListener(TextChangeListener listener) { 328 public void addTextChangeListener(TextChangeListener listener) 329 { 378 330 assert(listener != null); 379 if (!textChangeListeners.contains(listener)) 380 textChangeListeners.add(listener); 381 } 382 383 public void lostFocus() { 384 Browser._theBrowser.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 331 if (!textChangeListeners.contains(listener)) textChangeListeners.add(listener); 332 } 333 334 public void gainFocus() 335 { 336 if (popup != null && !PopupManager.getInstance().isShowing(popup)) { 337 popup.show(); 338 } 339 } 340 341 public void lostFocus() 342 { 343 EcosystemManager.getGraphicsManager().setCursor(new Cursor(Cursor.CursorType.DEFAULT)); 385 344 386 345 boolean dirty = false; … … 392 351 if (emulatedSource.getHighlightMode() != HighlightMode.None) { 393 352 emulatedSource.setHighlightMode(HighlightMode.None); 353 emulatedSource.setHighlightColorToDefault(); 394 354 dirty = true; 395 355 } 396 356 397 if (popup != null && 398 PopupManager.getInstance().isShowing(popup)) { 399 PopupManager.getInstance().hidePopup(popup); 357 if (popup != null && PopupManager.getInstance().isShowing(popup)) { 358 popup.hide(); 400 359 } 401 360 … … 410 369 * Null is allowed 411 370 */ 412 public void setText(String text) { 371 public void setText(String text) 372 { 413 373 if (text == null) text = ""; 414 374 … … 424 384 } 425 385 426 public String getText() { 386 public String getText() 387 { 427 388 return emulatedSource.getText(); 428 389 } 429 390 430 private void fireTextChanged() {431 432 for (TextChangeListener listener : textChangeListeners) 391 private void fireTextChanged() 392 { 393 for (TextChangeListener listener : textChangeListeners) { 433 394 listener.onTextChanged(this, this.emulatedSource.getText()); 434 435 } 436 437 public void setBackgroundColor(Color c) { 395 } 396 } 397 398 public void setBackgroundColor(Colour c) 399 { 438 400 emulatedSource.setBackgroundColor(c); 439 401 } 440 402 441 private void repaint() {442 403 private void repaint() 404 { 443 405 if (popup != null && PopupManager.getInstance().isShowing(popup)) { 444 406 popup.invalidateAppearance(); 445 FrameGraphics.refresh(true);407 DisplayController.requestRefresh(true); 446 408 } else { 447 409 invalidate(); 448 FrameGraphics.refresh(true); 449 } 450 } 451 452 private void invalidate() { 453 for (Rectangle r : emulatedSource.getDrawingArea()) 454 FrameGraphics.invalidateArea(r); 455 } 456 457 public void paint(Graphics g) { 458 459 if ((popup != null && PopupManager.getInstance().isShowing(popup)) || 460 !parentComponant.isShowing()) 461 return; 462 463 Point pos; 464 try { 465 pos = this.convertToExpediteeSpace(parentComponant.getLocationOnScreen()); 466 } catch (Exception e) { 467 e.printStackTrace(); 468 return; 469 } 470 471 paint( g, 472 pos.x + masterOffset.x, 473 pos.y + masterOffset.y, 474 parentComponant.getWidth() - masterOffset.x); 475 } 476 477 private void paint(Graphics g, int parentX, int parentY, int maxWidth) { 478 479 if (Browser._theBrowser == null) return; 480 481 /*int xoffset = (emulatedSource.getLink() == null) ? 6 : 18; 482 int yoffset = emulatedSource.getBoundsHeight() - 3; 483 parentX += xoffset; 484 parentY += yoffset;*/ 485 486 // Set the emulated position according to the parent position - the parent position 487 // can be from the popup or the actual parent componant 488 if (emulatedSource.getX() != parentX || emulatedSource.getY() != parentY) 489 emulatedSource.setPosition(parentX, parentY); 490 491 Shape saveClip = g.getClip(); 492 493 if (maxWidth > 0) { 494 495 Area clip = FrameGraphics.getCurrentClip(); 496 497 Area tmpClip = (clip != null) ? clip : 498 new Area(new Rectangle(0, 0, 499 Browser._theBrowser.getContentPane().getWidth(), 500 Browser._theBrowser.getContentPane().getHeight())); 501 502 /* tmpClip.intersect(new Area(new Rectangle(0, 0, 503 parentX + maxWidth - xoffset, Browser._theBrowser.getContentPane().getHeight() 504 )));*/ 505 506 tmpClip.intersect(new Area(new Rectangle(0, 0, 507 parentX + maxWidth, Browser._theBrowser.getContentPane().getHeight() 508 ))); 509 510 // No intersection 511 if (!tmpClip.isEmpty()) 512 g.setClip(tmpClip); 513 514 } 515 516 emulatedSource.paint((Graphics2D)g); 517 518 // Restore 519 if (maxWidth > 0) { 520 g.setClip(saveClip); 521 } 522 523 // Restore emulated position for consuming mouse movements 524 try { 525 Point pos = this.convertToExpediteeSpace(parentComponant.getLocationOnScreen()); 526 emulatedSource.setPosition( 527 pos.x + masterOffset.x, 528 pos.y + masterOffset.y); 529 } catch (IllegalComponentStateException ex) { // Cannot fix this .. this whole class needs revising 530 ex.printStackTrace(); 531 } 410 DisplayController.requestRefresh(true); 411 } 412 } 413 414 private void invalidate() 415 { 416 DisplayController.invalidateArea(emulatedSource.getDrawingArea()); 417 } 418 419 public void paint() 420 { 421 GraphicsManager gm = EcosystemManager.getGraphicsManager(); 422 423 EnforcedClipKey key = gm.pushClip(new Clip(emulatedSource.getDrawingArea())); 424 425 emulatedSource.paint(); 426 427 gm.popClip(key); 532 428 } 533 429 … … 537 433 } 538 434 539 private class LabelEditPopup extends Popup implements KeyListener, MouseListener, MouseMotionListener { 540 541 private static final long serialVersionUID = 1L; 542 543 LabelEditPopup() { 544 super.setAudoHide(true); 435 private class LabelEditPopup extends Popup implements KeyListener, MouseListener, MouseMotionListener 436 { 437 LabelEditPopup() 438 { 439 super(null); // No animation (instant show/hide) 545 440 super.setConsumeBackClick(false); 546 441 super.setBorderThickness(0); 547 548 updateSize(); 549 550 addKeyListener(this); 551 addMouseListener(this); 552 addMouseMotionListener(this); 553 } 554 555 public void updateSize() { 556 setSize(emulatedSource.getBoundsWidth() + 4, emulatedSource.getBoundsHeight() + 4); 557 } 558 559 560 public void keyPressed(KeyEvent e) { 561 onKeyPressed(e, LabelEditPopup.this); 562 updateSize(); 563 } 564 565 public void keyReleased(KeyEvent e) { 566 } 567 568 569 public void keyTyped(KeyEvent e) { 570 } 571 572 573 public void mouseClicked(MouseEvent e) { 574 } 575 576 public void mouseEntered(MouseEvent e) { 577 } 578 579 public void mouseExited(MouseEvent e) { 580 } 581 582 public void mousePressed(MouseEvent e) { 583 onMousePressed(e); 584 } 585 586 public void mouseReleased(MouseEvent e) { 587 onMouseReleased(e); 588 updateSize(); 589 } 590 591 592 public void mouseDragged(MouseEvent e) { 593 onMouseDragged(e); 594 } 595 596 public void mouseMoved(MouseEvent e) { 597 598 } 599 600 @Override 601 public void onHide() { 602 super.onHide(); 603 } 604 605 @Override 606 public void onShow() { 607 super.onShow(); 608 } 609 610 611 612 @Override 613 public void paint(Graphics g) { 614 615 EmulatedTextItem.this.paint(g, 7, 16, -1); 616 617 } 618 619 } 620 621 private class RestrictedTextItem extends Text { 622 623 private Color selectionColor = null; 624 private int selectionMouseButton = -1; 625 626 RestrictedTextItem() { 442 } 443 444 @Override 445 public void onHide() 446 { 447 } 448 449 @Override 450 public void onShow() 451 { 452 } 453 454 @Override 455 public void paintInternal() 456 { 457 EmulatedTextItem.this.paint(); 458 } 459 460 @Override 461 public AxisAlignedBoxBounds getFullBounds() 462 { 463 return emulatedSource.getDrawingArea(); 464 } 465 466 @Override 467 public void mouseDragged(MouseEvent e) 468 { 469 boolean consume = onMouseDragged(e); 470 if (consume) e.consume(); 471 } 472 473 @Override 474 public void mouseMoved(MouseEvent e) 475 { 476 boolean consume = onMouseMoved(e); 477 if (consume) e.consume(); 478 } 479 480 @Override 481 public void mouseClicked(MouseEvent e) 482 { 483 boolean consume = onMouseClicked(e); 484 if (consume) e.consume(); 485 } 486 487 @Override 488 public void mousePressed(MouseEvent e) 489 { 490 boolean consume = onMousePressed(e); 491 if (consume) e.consume(); 492 } 493 494 @Override 495 public void mouseReleased(MouseEvent e) 496 { 497 boolean consume = onMouseReleased(e); 498 if (consume) e.consume(); 499 } 500 501 @Override 502 public void mouseEntered(MouseEvent e) 503 { 504 // Not required 505 } 506 507 @Override 508 public void mouseExited(MouseEvent e) 509 { 510 // Not required 511 } 512 513 @Override 514 public void keyTyped(KeyEvent e) 515 { 516 boolean consume = onKeyTyped(e); 517 if (consume) e.consume(); 518 } 519 520 @Override 521 public void keyPressed(KeyEvent e) 522 { 523 boolean consume = onKeyPressed(e); 524 if (consume) e.consume(); 525 } 526 527 @Override 528 public void keyReleased(KeyEvent e) 529 { 530 boolean consume = onKeyReleased(e); 531 if (consume) e.consume(); 532 } 533 534 } 535 536 private class RestrictedTextItem extends Text 537 { 538 private Colour selectionColor = null; 539 540 RestrictedTextItem() 541 { 627 542 super(1); 628 543 } 629 544 630 private void updateSelection(int mouseButton) { 631 selectionColor = super.getSelectionColor(mouseButton); 632 selectionMouseButton = mouseButton; 633 } 634 635 public void setSelectionStart(float mouseX, float mouseY, int mouseButton) { 545 private void updateSelection() 546 { 547 selectionColor = super.getSelectionColour(); 548 } 549 550 public void setSelectionStart(float mouseX, float mouseY, int mouseButton) 551 { 636 552 super.setSelectionStart(mouseX, mouseY); 637 updateSelection(mouseButton); 638 } 639 640 641 642 @Override 643 protected Color getSelectionColor(int mouseButton) { 644 645 if (selectionColor != null) 553 updateSelection(); 554 } 555 556 @Override 557 public Colour getSelectionColour() 558 { 559 if (selectionColor != null) { 646 560 return selectionColor; 647 648 else return super.getSelectionColor(mouseButton); 561 } else { 562 return super.getSelectionColour(); 563 } 649 564 650 565 } -
trunk/src/org/apollo/items/FramePlaybackLauncher.java
r489 r1102 1 1 package org.apollo.items; 2 3 import java.awt.Color;4 import java.awt.GradientPaint;5 import java.awt.Graphics2D;6 import java.awt.Paint;7 import java.awt.Polygon;8 import java.awt.Stroke;9 2 10 3 import org.apollo.ApolloSystem; … … 24 17 import org.apollo.util.ODFrameHeirarchyFetcher.ODFrameReceiver; 25 18 import org.apollo.widgets.FramePlayer; 19 import org.expeditee.core.Colour; 20 import org.expeditee.core.Dimension; 21 import org.expeditee.core.Fill; 22 import org.expeditee.core.GradientFill; 23 import org.expeditee.core.Point; 24 import org.expeditee.core.Stroke; 25 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 26 import org.expeditee.core.bounds.Bounds; 27 import org.expeditee.gio.EcosystemManager; 28 import org.expeditee.gio.GraphicsManager; 26 29 import org.expeditee.gui.Browser; 27 import org.expeditee.gui.Display IO;30 import org.expeditee.gui.DisplayController; 28 31 import org.expeditee.gui.Frame; 29 32 import org.expeditee.gui.FrameIO; … … 43 46 private static int WIDTH = 80; 44 47 private static int HEIGHT = 80; 45 private static Stroke BORDER_ST OKE = Strokes.SOLID_1;46 47 private static final Colo r BASE_COLOR = new Color(60, 148, 255);48 private static final Colo r HIGHLIGHT_COLOR = new Color(253, 255, 201);48 private static Stroke BORDER_STROKE = Strokes.SOLID_1; 49 50 private static final Colour BASE_COLOR = Colour.FromRGB255(60, 148, 255); 51 private static final Colour HIGHLIGHT_COLOR = Colour.FromRGB255(253, 255, 201); 49 52 50 53 private String frameToPlay = null; … … 74 77 75 78 @Override 76 public void paint(Graphics2D g) { 79 public void paint() 80 { 77 81 if (Browser._theBrowser == null) return; 78 82 79 Paint restore = g.getPaint(); 80 83 GraphicsManager g = EcosystemManager.getGraphicsManager(); 84 85 Fill fill = null; 81 86 if (ApolloSystem.useQualityGraphics) { 82 GradientPaint gp = new GradientPaint( 83 _x + (WIDTH / 2), _y, HIGHLIGHT_COLOR, 84 _x + (WIDTH / 2), _y + HEIGHT - (HEIGHT / 5), BASE_COLOR); 85 g.setPaint(gp); 87 Point fromPoint = new Point(_x + (WIDTH / 2), _y); 88 Point toPoint = new Point(_x + (WIDTH / 2), _y + HEIGHT - (HEIGHT / 5)); 89 fill = new GradientFill(HIGHLIGHT_COLOR, fromPoint, BASE_COLOR, toPoint); 86 90 } else { 87 g.setColor(BASE_COLOR); 88 } 89 90 g.fillRect((int)_x, (int)_y, WIDTH, HEIGHT); 91 92 g.setPaint(restore); 93 94 g.setColor(Color.BLACK); 95 g.setStroke(BORDER_STOKE); 96 g.drawRect((int)_x, (int)_y, WIDTH, HEIGHT); 97 98 IconRepository.getIcon("frameplay.png").paintIcon( 99 Browser._theBrowser.getContentPane(), g, getX() + 25, getY() + 25); 91 fill = new Fill(BASE_COLOR); 92 } 93 94 Point topLeft = new Point((int)_x, (int)_y); 95 Dimension size = new Dimension(WIDTH, HEIGHT); 96 g.drawRectangle(topLeft, size, 0.0, fill, Colour.BLACK, BORDER_STROKE, null); 97 98 /*IconRepository.getIcon("frameplay.png").paintIcon( 99 Browser._theBrowser.getContentPane(), g, getX() + 25, getY() + 25);*/ 100 101 g.drawImage(IconRepository.getIcon("frameplay.png"), new Point(getX() + 25, getY() + 25)); 100 102 101 103 } … … 117 119 118 120 @Override 119 public void updatePolygon() { 120 121 _poly = new Polygon(); 122 123 int x = (int)_x; 124 int y = (int)_y; 125 126 _poly.addPoint(x, y); 127 _poly.addPoint(x + WIDTH, y); 128 _poly.addPoint(x + WIDTH, y + HEIGHT); 129 _poly.addPoint(x, y + HEIGHT); 130 121 public Bounds updateBounds() 122 { 123 return new AxisAlignedBoxBounds((int) _x, (int) _y, WIDTH, HEIGHT); 131 124 } 132 125 … … 148 141 } 149 142 150 private void selfDestruct() {151 143 private void selfDestruct() 144 { 152 145 Frame parent = getParent(); 153 146 parent.removeItem(this); 154 147 155 if (Display IO.getCurrentFrame() == null) return;148 if (DisplayController.getCurrentFrame() == null) return; 156 149 157 150 Frame audioFrame = null; 158 151 159 152 // Flag as null if frame to play is actually current frame 160 if (frameToPlay != null && frameToPlay.equals(Display IO.getCurrentFrame().getName()))153 if (frameToPlay != null && frameToPlay.equals(DisplayController.getCurrentFrame().getName())) 161 154 frameToPlay = null; 162 155 163 156 if (frameToPlay == null) { 164 audioFrame = Display IO.getCurrentFrame();157 audioFrame = DisplayController.getCurrentFrame(); 165 158 } else { 166 159 audioFrame = FrameIO.LoadFrame(frameToPlay); … … 199 192 } else { 200 193 // Fetch the audio graph for the frame 201 GraphReceiver receiver = new GraphReceiver(Display IO.getCurrentFrame());194 GraphReceiver receiver = new GraphReceiver(DisplayController.getCurrentFrame()); 202 195 ODFrameHeirarchyFetcher.getInstance().doFetch(audioFrame.getName(), receiver); 203 196 // The callback will later begin playback … … 257 250 // Thus the start frame will be hence taken as a percentage of the whole frame 258 251 259 float percent = _x / Browser._theBrowser.getContentPane().getWidth();252 float percent = _x / EcosystemManager.getGraphicsManager().getWindowSize().getWidth(); 260 253 if (percent < 0) percent = 0; 261 254 if (percent > 1) percent = 1; -
trunk/src/org/apollo/items/RecordOverdubLauncher.java
r489 r1102 1 1 package org.apollo.items; 2 3 import java.awt.Color;4 import java.awt.GradientPaint;5 import java.awt.Graphics2D;6 import java.awt.Paint;7 import java.awt.Polygon;8 import java.awt.Stroke;9 2 10 3 import org.apollo.ApolloSystem; … … 12 5 import org.apollo.io.IconRepository; 13 6 import org.apollo.widgets.SampleRecorder; 7 import org.expeditee.core.Colour; 8 import org.expeditee.core.Dimension; 9 import org.expeditee.core.Fill; 10 import org.expeditee.core.GradientFill; 11 import org.expeditee.core.Point; 12 import org.expeditee.core.Stroke; 13 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 14 import org.expeditee.core.bounds.Bounds; 15 import org.expeditee.gio.EcosystemManager; 16 import org.expeditee.gio.GraphicsManager; 14 17 import org.expeditee.gui.Browser; 15 import org.expeditee.gui.Display IO;18 import org.expeditee.gui.DisplayController; 16 19 import org.expeditee.gui.Frame; 17 20 import org.expeditee.items.Item; … … 23 26 private static int WIDTH = 80; 24 27 private static int HEIGHT = 80; 25 private static Stroke BORDER_ST OKE = Strokes.SOLID_1;28 private static Stroke BORDER_STROKE = Strokes.SOLID_1; 26 29 private int countdown; 27 30 28 private static final Colo r BASE_COLOR = new Color(255, 100, 100);29 private static final Colo r HIGHLIGHT_COLOR = new Color(253, 255, 201);31 private static final Colour BASE_COLOR = Colour.FromRGB255(255, 100, 100); 32 private static final Colour HIGHLIGHT_COLOR = Colour.FromRGB255(253, 255, 201); 30 33 31 34 public RecordOverdubLauncher(int countdown) { … … 49 52 50 53 @Override 51 public void paint( Graphics2D g) {54 public void paint() { 52 55 if (Browser._theBrowser == null) return; 53 56 54 Paint restore = g.getPaint();57 GraphicsManager g = EcosystemManager.getGraphicsManager(); 55 58 59 Fill fill = null; 56 60 if (ApolloSystem.useQualityGraphics) { 57 GradientPaint gp = new GradientPaint( 58 _x + (WIDTH / 2), _y, HIGHLIGHT_COLOR, 59 _x + (WIDTH / 2), _y + HEIGHT - (HEIGHT / 5), BASE_COLOR); 60 g.setPaint(gp); 61 Point fromPoint = new Point(_x + (WIDTH / 2), _y); 62 Point toPoint = new Point(_x + (WIDTH / 2), _y + HEIGHT - (HEIGHT / 5)); 63 fill = new GradientFill(HIGHLIGHT_COLOR, fromPoint, BASE_COLOR, toPoint); 61 64 } else { 62 g.setColor(BASE_COLOR);65 fill = new Fill(BASE_COLOR); 63 66 } 64 67 65 g.fillRect((int)_x, (int)_y, WIDTH, HEIGHT); 68 Point topLeft = new Point((int)_x, (int)_y); 69 Dimension size = new Dimension(WIDTH, HEIGHT); 70 g.drawRectangle(topLeft, size, 0.0, fill, Colour.BLACK, BORDER_STROKE, null); 66 71 67 g.setPaint(restore); 72 /*IconRepository.getIcon("recordplay.png").paintIcon( 73 Browser._theBrowser.getContentPane(), g, getX() + 25, getY() + 25);*/ 68 74 69 g.setColor(Color.BLACK); 70 g.setStroke(BORDER_STOKE); 71 g.drawRect((int)_x, (int)_y, WIDTH, HEIGHT); 72 73 IconRepository.getIcon("recordplay.png").paintIcon( 74 Browser._theBrowser.getContentPane(), g, getX() + 25, getY() + 25); 75 g.drawImage(IconRepository.getIcon("recordplay.png"), new Point(getX() + 25, getY() + 25)); 75 76 76 77 } … … 92 93 93 94 @Override 94 public void updatePolygon() { 95 96 _poly = new Polygon(); 97 98 int x = (int)_x; 99 int y = (int)_y; 100 101 _poly.addPoint(x, y); 102 _poly.addPoint(x + WIDTH, y); 103 _poly.addPoint(x + WIDTH, y + HEIGHT); 104 _poly.addPoint(x, y + HEIGHT); 105 95 public Bounds updateBounds() 96 { 97 return new AxisAlignedBoxBounds((int) _x, (int) _y, WIDTH, HEIGHT); 106 98 } 107 99 … … 128 120 parent.removeItem(this); 129 121 130 Frame currentFrame = Display IO.getCurrentFrame();122 Frame currentFrame = DisplayController.getCurrentFrame(); 131 123 132 124 if (currentFrame != null) { -
trunk/src/org/apollo/meldex/PitchTracker.java
r315 r1102 3 3 import java.util.ArrayList; 4 4 5 @SuppressWarnings("unchecked") // code in java 1.46 5 public class PitchTracker 7 6 { … … 14 13 15 14 // The pitch data 16 ArrayList pitchData;15 ArrayList<PitchValue> pitchData; 17 16 18 17 // Our lovely Pitch Period Estimators … … 26 25 27 26 28 public ArrayList process(byte[] rawData, int rawLength, int rawSampleRate)27 public ArrayList<PitchValue> process(byte[] rawData, int rawLength, int rawSampleRate) 29 28 { 30 29 // Save the sample rate of the loaded sample … … 32 31 33 32 // Allocate a new pitch data array to store our pitch values 34 pitchData = new ArrayList ();33 pitchData = new ArrayList<PitchValue>(); 35 34 36 35 // Reset our 6 pitch period estimators -
trunk/src/org/apollo/meldex/PitchValue.java
r315 r1102 11 11 public PitchValue(double per, int pos) 12 12 { 13 period = per;14 position = pos;13 period = per; 14 position = pos; 15 15 } 16 16 } -
trunk/src/org/apollo/meldex/RogTrack.java
r315 r1102 1 1 package org.apollo.meldex; 2 3 2 4 3 import java.io.File; 5 4 import java.io.FileInputStream; 6 5 import java.io.FileOutputStream; 6 import java.io.IOException; 7 7 import java.util.ArrayList; 8 import javax.swing.JOptionPane; 9 10 @SuppressWarnings("unchecked") // code in java 1.4 8 9 import org.expeditee.gio.EcosystemManager; 10 11 11 public class RogTrack 12 12 { … … 20 20 21 21 // Data representing the track events 22 ArrayList trackData = new ArrayList();22 ArrayList<RogTrackEvent> trackData = new ArrayList<RogTrackEvent>(); 23 23 24 24 … … 217 217 int track_len = trackData.size(); 218 218 219 ArrayList filtered_td = new ArrayList();219 ArrayList<RogTrackEvent> filtered_td = new ArrayList<RogTrackEvent>(); 220 220 221 221 for (int i = 0; i < track_len; i++) { … … 235 235 } 236 236 237 ArrayList me_list = new ArrayList();237 ArrayList<MelodyEvent> me_list = new ArrayList<MelodyEvent>(); 238 238 239 239 for (int i = 0; i < filtered_track_len-1; i++) { … … 283 283 public boolean loadFromFile(File rogFile) 284 284 { 285 try { 286 // Open the file with a FileInputStream, ready for parsing 287 FileInputStream fileIn = new FileInputStream(rogFile); 288 289 // Get the number of bytes in the file 290 int rogLength = fileIn.available(); 291 292 // Create a buffer to store the file, and read the file into it 293 byte[] rogData = new byte[rogLength]; 294 fileIn.read(rogData, 0, rogLength); 295 296 // Parse the .rog file 297 parseFile(rogData, rogLength); 298 } 299 catch (Exception ex) { 300 JOptionPane.showMessageDialog(null, "Exception occurred reading file.\n\n" + ex); 301 return false; 302 } 303 304 // File loaded successfully 305 return true; 285 boolean success = true; 286 FileInputStream fileIn = null; 287 try { 288 // Open the file with a FileInputStream, ready for parsing 289 fileIn = new FileInputStream(rogFile); 290 291 // Get the number of bytes in the file 292 int rogLength = fileIn.available(); 293 294 // Create a buffer to store the file, and read the file into it 295 byte[] rogData = new byte[rogLength]; 296 fileIn.read(rogData, 0, rogLength); 297 298 // Parse the .rog file 299 parseFile(rogData, rogLength); 300 } catch (Exception ex) { 301 EcosystemManager.getGraphicsManager().showDialog("Exception", "Exception occurred reading file.\n\n" + ex); 302 success = false; 303 } finally { 304 if (fileIn != null) { 305 try { 306 fileIn.close(); 307 } catch (IOException e) { 308 // If an IO exception occurs when closing the file, just sweep it under the rug 309 } 310 } 311 } 312 313 // File loaded successfully 314 return success; 306 315 } 307 316 … … 406 415 // Check that the noteName is valid 407 416 if (noteName < 'A' || noteName > 'G') { 408 JOptionPane.showMessageDialog(null, "Parsing error - check that the Rog file is valid.");417 EcosystemManager.getGraphicsManager().showDialog("Exception", "Parsing error - check that the Rog file is valid."); 409 418 return; 410 419 } … … 497 506 } 498 507 catch (Exception ex) { 499 JOptionPane.showMessageDialog(null, "Exception occurred writing to file.\n\n" + ex);508 EcosystemManager.getGraphicsManager().showDialog("Exception", "Exception occurred writing to file.\n\n" + ex); 500 509 return false; 501 510 } -
trunk/src/org/apollo/meldex/StandardisedMelody.java
r315 r1102 93 93 94 94 // Read the melody from the melody file 95 return (StandardisedMelody) melodyFileStream.readObject(); 95 StandardisedMelody standardisedMelody = (StandardisedMelody) melodyFileStream.readObject(); 96 97 melodyFileStream.close(); 98 99 return standardisedMelody; 96 100 97 101 } -
trunk/src/org/apollo/meldex/Transcriber.java
r315 r1102 4 4 import java.util.ArrayList; 5 5 6 @SuppressWarnings("unchecked") // code in java 1.47 6 public class Transcriber 8 7 { … … 255 254 { 256 255 // Pitch track the note 257 ArrayList pitchData = pitchTracker.process(data, length, sampleRate);256 ArrayList<PitchValue> pitchData = pitchTracker.process(data, length, sampleRate); 258 257 259 258 // Average the pitch data … … 265 264 266 265 267 private int averagePitchData(ArrayList pitchData)266 private int averagePitchData(ArrayList<PitchValue> pitchData) 268 267 { 269 268 // Loop through the pitch values... 270 269 int i = 0, k = 0; 271 270 while (i < (pitchData.size() - 1)) { 272 int startPos = ((PitchValue) pitchData.get(i)).position;273 double period = ((PitchValue) pitchData.get(i)).period;271 int startPos = pitchData.get(i).position; 272 double period = pitchData.get(i).period; 274 273 double averagePeriod = period; 275 double runningPeriod = ((PitchValue) pitchData.get(i+1)).position - startPos;274 double runningPeriod = pitchData.get(i+1).position - startPos; 276 275 double numPeriods = runningPeriod / period; 277 276 … … 280 279 while ((i+j) < (pitchData.size() - 1)) { 281 280 // Get the next pitch estimate 282 period = ((PitchValue) pitchData.get(i+j)).period;283 int position = ((PitchValue) pitchData.get(i+j)).position;281 period = pitchData.get(i+j).period; 282 int position = pitchData.get(i+j).position; 284 283 285 284 // Make sure that this period is covered by the average so far … … 289 288 290 289 // Stop if we have covered more than 20 msec 291 int nextPos = ((PitchValue) pitchData.get(i+j+1)).position;290 int nextPos = pitchData.get(i+j+1).position; 292 291 // if ((nextPos - startPos) >= 445) { // !! PURE-ROG !! 293 292 if ((nextPos - startPos) >= (sampleRate * 0.02)) { … … 315 314 316 315 317 private int calculateHistogram(ArrayList data, int length)316 private int calculateHistogram(ArrayList<PitchValue> data, int length) 318 317 { 319 318 // This probably shouldn't be a constant … … 328 327 // Calculate the histogram data 329 328 for (int i = 0; i < (length - 1); i++) { 330 double period = ((PitchValue) data.get(i)).period;331 double position = ((PitchValue) data.get(i)).position;332 double periodLength = ((PitchValue) data.get(i+1)).position - position;329 double period = data.get(i).period; 330 double position = data.get(i).position; 331 double periodLength = data.get(i+1).position - position; 333 332 334 333 // We only need to do this if the pitch does not equal zero -
trunk/src/org/apollo/meldex/WavSample.java
r315 r1102 8 8 import javax.sound.sampled.AudioInputStream; 9 9 import javax.sound.sampled.AudioSystem; 10 import javax.swing.JOptionPane; 11 12 @SuppressWarnings("unchecked") // code in java 1.4 10 11 import org.expeditee.gio.EcosystemManager; 12 13 13 public class WavSample 14 14 { … … 68 68 } 69 69 catch (Exception ex) { 70 JOptionPane.showMessageDialog(null, "Exception occurred creating sample.\n\n" + ex);70 EcosystemManager.getGraphicsManager().showDialog("Exception", "Exception occurred creating sample.\n\n" + ex); 71 71 return false; 72 72 } … … 90 90 } 91 91 catch (Exception ex) { 92 JOptionPane.showMessageDialog(null, "Exception occurred reloading sample.\n\n" + ex);92 EcosystemManager.getGraphicsManager().showDialog("Exception", "Exception occurred reloading sample.\n\n" + ex); 93 93 return false; 94 94 } … … 101 101 } 102 102 catch (Exception ex) { 103 JOptionPane.showMessageDialog(null, "Exception occurred resetting audio stream.\n\n" + ex);103 EcosystemManager.getGraphicsManager().showDialog("Exception", "Exception occurred resetting audio stream.\n\n" + ex); 104 104 return false; 105 105 } … … 172 172 if (format.getSampleSizeInBits() == 8) { 173 173 if (format.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED)) { 174 JOptionPane.showMessageDialog(null, "Oops! Internal Error: Unexpected audio format (signed 8-bit).");174 EcosystemManager.getGraphicsManager().showDialog("Exception", "Oops! Internal Error: Unexpected audio format (signed 8-bit)."); 175 175 return null; 176 176 } … … 178 178 if (format.getSampleSizeInBits() == 16) { 179 179 if (format.getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED)) { 180 JOptionPane.showMessageDialog(null, "Oops! Internal Error: Unexpected audio format (unsigned 16-bit).");180 EcosystemManager.getGraphicsManager().showDialog("Exception", "Oops! Internal Error: Unexpected audio format (unsigned 16-bit)."); 181 181 return null; 182 182 } … … 188 188 189 189 // Create a new list to store the standardised sample values 190 ArrayList stdTemp = new ArrayList();190 ArrayList<Integer> stdTemp = new ArrayList<Integer>(); 191 191 192 192 // Simply pick values from the sample at the frequency specified … … 218 218 219 219 220 private static ArrayList toStandardEndian(AudioFormat format, ArrayListinData)221 { 222 // Endian details do not apply to 8-bit samples, so no conversion needed223 if (format.getSampleSizeInBits() == 8) {224 return inData;225 }226 227 // Create a new list to store the results228 ArrayList outData = new ArrayList();229 230 // Simply convert each number in the sample to the endian form for the current system231 for (int i = 0; i < inData.size(); i += 2) {232 233 int MSB, LSB;234 if (format.isBigEndian()) {235 MSB = ((Integer) inData.get(i)).intValue(); // First byte is MSB (high order)236 LSB = ((Integer) inData.get(i+1)).intValue(); // Second byte is LSB (low order)237 }238 else {239 LSB = ((Integer) inData.get(i)).intValue(); // First byte is LSB (low order)240 MSB = ((Integer) inData.get(i+1)).intValue(); // Second byte is MSB (high order)241 }242 243 int val = (MSB << 8) + (LSB & 255);244 outData.add(new Integer(val));245 }246 247 return outData;248 } 249 250 251 private static ArrayList toUnsignedValues(AudioFormat format, ArrayListinData)220 private static ArrayList<Integer> toStandardEndian(AudioFormat format, ArrayList<Integer> inData) 221 { 222 // Endian details do not apply to 8-bit samples, so no conversion needed 223 if (format.getSampleSizeInBits() == 8) { 224 return inData; 225 } 226 227 // Create a new list to store the results 228 ArrayList<Integer> outData = new ArrayList<Integer>(); 229 230 // Simply convert each number in the sample to the endian form for the current system 231 for (int i = 0; i < inData.size(); i += 2) { 232 233 int MSB, LSB; 234 if (format.isBigEndian()) { 235 MSB = ((Integer) inData.get(i)).intValue(); // First byte is MSB (high order) 236 LSB = ((Integer) inData.get(i+1)).intValue(); // Second byte is LSB (low order) 237 } 238 else { 239 LSB = ((Integer) inData.get(i)).intValue(); // First byte is LSB (low order) 240 MSB = ((Integer) inData.get(i+1)).intValue(); // Second byte is MSB (high order) 241 } 242 243 int val = (MSB << 8) + (LSB & 255); 244 outData.add(new Integer(val)); 245 } 246 247 return outData; 248 } 249 250 251 private static ArrayList<Integer> toUnsignedValues(AudioFormat format, ArrayList<Integer> inData) 252 252 { 253 253 // PCM_UNSIGNED samples are what we want, so no conversion needed … … 257 257 258 258 // Create a new list to store the results 259 ArrayList outData = new ArrayList();259 ArrayList<Integer> outData = new ArrayList<Integer>(); 260 260 261 261 // Simply convert each signed number in the sample to an unsigned value … … 275 275 276 276 277 private static ArrayList to8bit(AudioFormat format, ArrayListinData)277 private static ArrayList<Integer> to8bit(AudioFormat format, ArrayList<Integer> inData) 278 278 { 279 279 // 8-bit data is what we want, so no conversion necessary … … 283 283 284 284 // Create a new list to store the results 285 ArrayList outData = new ArrayList();285 ArrayList<Integer> outData = new ArrayList<Integer>(); 286 286 287 287 // Simply reduce each value in the sample to an 8-bit value … … 298 298 299 299 300 private static ArrayList toMono(AudioFormat format, ArrayListinData)300 private static ArrayList<Integer> toMono(AudioFormat format, ArrayList<Integer> inData) 301 301 { 302 302 // Mono-channel data is what we want, so no conversion necessary … … 306 306 307 307 // Create a new list to store the results 308 ArrayList outData = new ArrayList();308 ArrayList<Integer> outData = new ArrayList<Integer>(); 309 309 310 310 // Simply average all of the channels for each frame … … 362 362 try { 363 363 if (AudioSystem.write(audioData, AudioFileFormat.Type.WAVE, outFile) == -1) { 364 JOptionPane.showMessageDialog(null, "Problem occurred writing to file.");364 EcosystemManager.getGraphicsManager().showDialog("Exception", "Problem occurred writing to file."); 365 365 return false; 366 366 } 367 367 } 368 368 catch (Exception ex) { 369 JOptionPane.showMessageDialog(null, "Exception occurred saving file.\n\n" + ex);369 EcosystemManager.getGraphicsManager().showDialog("Exception", "Exception occurred saving file.\n\n" + ex); 370 370 return false; 371 371 } -
trunk/src/org/apollo/mvc/AbstractSubject.java
r315 r1102 4 4 import java.util.Set; 5 5 6 import javax.swing.SwingUtilities;6 import org.expeditee.gio.EcosystemManager; 7 7 8 8 /** … … 66 66 protected final void fireSubjectChangedLaterOnSwingThread(final SubjectChangedEvent event) { 67 67 68 SwingUtilities.invokeLater(new Runnable() {68 EcosystemManager.getMiscManager().runOnGIOThread(new Runnable() { 69 69 public void run() { 70 70 fireSubjectChanged(event); -
trunk/src/org/apollo/mvc/SwingEventQueue.java
r315 r1102 4 4 import java.util.Queue; 5 5 6 import javax.swing.SwingUtilities;6 import org.expeditee.gio.EcosystemManager; 7 7 8 8 /** 9 9 * If your observer needs to reacts to events on the swing thread (i.e. interacting with swing 10 10 * objects somewhere in the event) and the observed subject raised events on other threads, 11 * this class t hunnels all events into the swing thread and ensures that they are raised in11 * this class tunnels all events into the swing thread and ensures that they are raised in 12 12 * the swing thread (thread safety!). 13 13 * … … 26 26 /** 27 27 * COnstructor. 28 * @param target The SwingThreadedObserver instance to t hunnel events to on the swing thread.28 * @param target The SwingThreadedObserver instance to tunnel events to on the swing thread. 29 29 */ 30 30 public SwingEventQueue(SwingThreadedObserver target) { … … 44 44 eventQueue.add(new QueudEvent(source, event)); 45 45 } 46 SwingUtilities.invokeLater(eventProccessor);46 EcosystemManager.getMiscManager().runOnGIOThread(eventProccessor); 47 47 } 48 48 -
trunk/src/org/apollo/util/AudioPurger.java
r903 r1102 10 10 import org.apollo.io.AudioPathManager; 11 11 import org.apollo.widgets.SampledTrack; 12 import org.expeditee.settings.UserSettings;13 12 import org.expeditee.settings.folders.FolderSettings; 14 13 import org.expeditee.items.ItemUtils; -
trunk/src/org/apollo/util/ExpediteeFileTextSearch.java
r349 r1102 1 1 package org.apollo.util; 2 2 3 import java.awt.Point;4 3 import java.io.BufferedReader; 5 4 import java.io.FileNotFoundException; … … 8 7 import java.util.LinkedList; 9 8 import java.util.List; 9 10 import org.expeditee.core.Point; 10 11 11 12 /** -
trunk/src/org/apollo/util/ODFrameHeirarchyFetcher.java
r315 r1102 3 3 import java.util.LinkedList; 4 4 import java.util.Queue; 5 6 import javax.swing.SwingUtilities;7 5 8 6 import org.apollo.audio.structure.OverdubbedFrame; 9 7 import org.apollo.audio.structure.TrackGraphLoopException; 10 8 import org.apollo.audio.structure.AudioStructureModel; 9 import org.expeditee.gio.EcosystemManager; 11 10 import org.expeditee.gui.FrameIO; 12 11 … … 139 138 } 140 139 141 // Run result noti ofaction for this request on swing thread142 SwingUtilities.invokeLater(request);140 // Run result notification for this request on swing thread 141 EcosystemManager.getMiscManager().runOnGIOThread(request); 143 142 144 143 } -
trunk/src/org/apollo/util/PopupReaper.java
r315 r1102 13 13 import javax.swing.SwingUtilities; 14 14 15 import org.expeditee.g ui.MouseEventRouter;15 import org.expeditee.gio.swing.MouseEventRouter; 16 16 import org.expeditee.gui.Popup; 17 17 import org.expeditee.gui.PopupManager; … … 19 19 20 20 /** 21 * Yet another daemon .. whos job is to hide popups after their lifetimes have passed21 * Yet another daemon .. whose job is to hide popups after their lifetimes have passed 22 22 * 23 23 * @author Brook Novak 24 24 */ 25 25 26 public class PopupReaper {27 26 public class PopupReaper 27 { 28 28 private Map<Popup, TemporaryPopup> tempPopups = new HashMap<Popup, TemporaryPopup>();// SHARED RESOURCE - the locker 29 29 … … 31 31 32 32 private static PopupReaper instance = new PopupReaper(); 33 private PopupReaper() { 34 } 35 public static PopupReaper getInstance() { 33 34 private PopupReaper() 35 { 36 } 37 38 public static PopupReaper getInstance() 39 { 36 40 return instance; 37 41 } … … 62 66 * 63 67 */ 64 public void initPopupLifetime(Popup p, PopupAnimator hideAnimation, int lifetime) { 68 public void initPopupLifetime(Popup p, PopupAnimator hideAnimation, int lifetime) 69 { 65 70 if (p == null) throw new NullPointerException("p"); 66 71 if (lifetime < 0) throw new IllegalArgumentException("lifetime < 0"); … … 87 92 reaper.interrupt(); 88 93 } 89 90 91 92 } 93 94 } 94 95 } 95 96 … … 115 116 * 116 117 */ 117 public boolean revivePopup(Popup p, int lifetime) { 118 public boolean revivePopup(Popup p, int lifetime) 119 { 118 120 if (p == null) throw new NullPointerException("p"); 119 121 if (lifetime < 0) throw new IllegalArgumentException("lifetime < 0"); … … 134 136 135 137 136 private class ReapDaemon extends Thread { 137 138 ReapDaemon() { 138 private class ReapDaemon extends Thread 139 { 140 ReapDaemon() 141 { 139 142 super("Popup Reaper"); 140 143 super.setPriority(Thread.MIN_PRIORITY); … … 142 145 } 143 146 144 public void run() {145 147 public void run() 148 { 146 149 while (true) { 147 150 … … 166 169 * A Positive wait time, or a negative for nothing to to wait on. 167 170 */ 168 private long reap() {169 171 private long reap() 172 { 170 173 Collection<TemporaryPopup> snapshot; 171 174 … … 226 229 * 227 230 */ 228 private class DoHide implements Runnable {229 231 private class DoHide implements Runnable 232 { 230 233 private TemporaryPopup tempPopup; 231 234 public boolean didHide = false; 232 235 233 public DoHide(TemporaryPopup tempPopup) { 236 public DoHide(TemporaryPopup tempPopup) 237 { 234 238 this.tempPopup = tempPopup; 235 239 } … … 244 248 * True if screenPoint is over c. 245 249 */ 246 private boolean isPointInComponant(Component c, Point screenPoint) { 250 private boolean isPointInComponant(Component c, Point screenPoint) 251 { 247 252 assert(c != null); 248 253 assert(screenPoint != null); … … 257 262 } 258 263 259 public void run() { 264 public void run() 265 { 260 266 assert(tempPopup != null); 261 267 262 268 MouseEvent me = MouseEventRouter.getCurrentMouseEvent(); 263 269 if (me != null) { 264 265 if (isPointInComponant(tempPopup.popup, me.getLocationOnScreen())) 266 return; 270 if (isPointInComponant(tempPopup.popup, me.getLocationOnScreen())) return; 267 271 268 272 Component invoker = PopupManager.getInstance().getInvoker(tempPopup.popup); 269 if (invoker != null && isPointInComponant(invoker, me.getLocationOnScreen())) 270 return; 271 273 274 if (invoker != null && isPointInComponant(invoker, me.getLocationOnScreen())) return; 272 275 } 273 276 … … 289 292 * 290 293 */ 291 private class TemporaryPopup implements Comparable {292 294 private class TemporaryPopup implements Comparable<TemporaryPopup> 295 { 293 296 private Popup popup; 294 297 private PopupAnimator hideAnim; … … 310 313 * 311 314 */ 312 public TemporaryPopup(Popup popup, PopupAnimator anim, int lifetime) { 315 public TemporaryPopup(Popup popup, PopupAnimator anim, int lifetime) 316 { 313 317 assert(popup != null); 314 318 assert(lifetime >= 0); … … 320 324 } 321 325 322 public void setNewLifetime(int lifetime) { 326 public void setNewLifetime(int lifetime) 327 { 323 328 assert(lifetime >= 0); 324 329 this.lifetime = lifetime; … … 326 331 } 327 332 328 public void resetLifetime() { 333 public void resetLifetime() 334 { 329 335 setNewLifetime(lifetime); 330 336 } 331 337 332 public long getDelay() { 338 public long getDelay() 339 { 333 340 return destructionTime - System.currentTimeMillis(); 334 341 } … … 337 344 * {@inheritDoc} 338 345 */ 339 public int compareTo(Object o) { 340 341 long dt2 = ((TemporaryPopup)o).destructionTime; 342 343 if (destructionTime < dt2) 344 return -1; 345 346 if (destructionTime > dt2) 347 return 1; 346 public int compareTo(TemporaryPopup o) 347 { 348 long dt2 = o.destructionTime; 349 350 if (destructionTime < dt2) return -1; 351 352 if (destructionTime > dt2) return 1; 348 353 349 354 return 0; -
trunk/src/org/apollo/util/ProbeDaemon.java
r372 r1102 7 7 import org.apollo.audio.util.Timeline; 8 8 import org.apollo.gui.FrameLayoutDaemon; 9 import org.expeditee.gui.Display IO;9 import org.expeditee.gui.DisplayController; 10 10 11 11 public class ProbeDaemon extends Thread { … … 46 46 String timeline = "none"; 47 47 Timeline tl = FrameLayoutDaemon.getInstance().getLastComputedTimeline(); 48 if (tl != null && Display IO.getCurrentFrame() == FrameLayoutDaemon.getInstance().getTimelineOwner()) {48 if (tl != null && DisplayController.getCurrentFrame() == FrameLayoutDaemon.getInstance().getTimelineOwner()) { 49 49 timeline = tl.toString(); 50 50 } -
trunk/src/org/apollo/util/TextItemSearchResult.java
r349 r1102 1 1 package org.apollo.util; 2 2 3 import java.awt.Point;4 3 import java.util.List; 4 5 import org.expeditee.core.Point; 5 6 /** 6 7 * Represents a single mutable search result. -
trunk/src/org/apollo/util/TrackModelLoadManager.java
r315 r1102 3 3 import java.io.File; 4 4 import java.io.IOException; 5 import java.lang.reflect.InvocationTargetException;6 5 import java.util.HashSet; 7 6 import java.util.Set; 8 7 9 8 import javax.sound.sampled.UnsupportedAudioFileException; 10 import javax.swing.SwingUtilities;11 9 12 10 import org.apollo.audio.SampledTrackModel; … … 14 12 import org.apollo.io.LoadedAudioData; 15 13 import org.apollo.mvc.Observer; 14 import org.expeditee.core.BlockingRunnable; 15 import org.expeditee.gio.EcosystemManager; 16 16 import org.expeditee.items.widgets.HeavyDutyInteractiveWidget; 17 17 import org.expeditee.items.widgets.WidgetCacheManager; … … 124 124 125 125 try { 126 SwingUtilities.invokeAndWait(locator); 127 } catch (InterruptedException e) { 128 e.printStackTrace(); 129 } catch (InvocationTargetException e) { 126 EcosystemManager.getMiscManager().runOnGIOThread(locator); 127 } catch (Exception e) { 130 128 e.printStackTrace(); 131 129 } … … 166 164 * Look in expeditee memory - this should be quick - will hold up the user 167 165 */ 168 private class CachedTrackModelLocator implementsRunnable166 private class CachedTrackModelLocator extends BlockingRunnable 169 167 { 170 168 private String localfileName; … … 176 174 } 177 175 178 public void run() {176 public void execute() { 179 177 180 178 // Exploit knowledge that all SampledTrack are Cached HDW -
trunk/src/org/apollo/widgets/AudioConfiguration.java
r315 r1102 31 31 import org.expeditee.items.ItemParentStateChangedEvent; 32 32 import org.expeditee.items.Text; 33 import org.expeditee.items.widgets. InteractiveWidget;34 35 public class AudioConfiguration extends InteractiveWidget implements Observer {33 import org.expeditee.items.widgets.SwingWidget; 34 35 public class AudioConfiguration extends SwingWidget implements Observer { 36 36 37 37 private static MixerItem[] inputMixerItems = null; 38 38 39 private JComboBox inputMixureCombo;39 private JComboBox<MixerItem> inputMixureCombo; 40 40 private JSlider masterVolumeSlider; 41 41 private JCheckBox masterMuteCheckBox; … … 48 48 Font descFont = new Font("Arial", Font.PLAIN, 12); 49 49 50 inputMixureCombo = new JComboBox (getInputMixerItems());50 inputMixureCombo = new JComboBox<MixerItem>(getInputMixerItems()); 51 51 52 52 inputMixureCombo.addActionListener( new ActionListener() { -
trunk/src/org/apollo/widgets/FramePlayer.java
r372 r1102 1 1 package org.apollo.widgets; 2 2 3 import java.awt.Color;4 3 import java.awt.Dimension; 5 4 import java.awt.GridBagConstraints; … … 21 20 import javax.swing.ComboBoxModel; 22 21 import javax.swing.DefaultComboBoxModel; 23 import javax.swing.Icon;24 22 import javax.swing.JButton; 25 23 import javax.swing.JComboBox; … … 45 43 import org.apollo.util.ApolloSystemLog; 46 44 import org.apollo.util.AudioMath; 47 import org.expeditee.gui.DisplayIO; 48 import org.expeditee.gui.DisplayIOObserver; 49 import org.expeditee.gui.FrameGraphics; 45 import org.expeditee.core.Colour; 46 import org.expeditee.core.Image; 47 import org.expeditee.gio.gesture.StandardGestureActions; 48 import org.expeditee.gio.swing.SwingMiscManager; 49 import org.expeditee.gui.DisplayController; 50 import org.expeditee.gui.DisplayObserver; 50 51 import org.expeditee.gui.FrameIO; 51 import org.expeditee.gui.FrameMouseActions;52 52 import org.expeditee.gui.MessageBay; 53 53 import org.expeditee.items.ItemParentStateChangedEvent; 54 54 import org.expeditee.items.Text; 55 import org.expeditee.items.widgets. InteractiveWidget;55 import org.expeditee.items.widgets.SwingWidget; 56 56 57 57 /** … … 61 61 * 62 62 */ 63 public class FramePlayer extends InteractiveWidget64 implements Observer, MultitrackLoadListener, ActionListener, Display IOObserver {63 public class FramePlayer extends SwingWidget 64 implements Observer, MultitrackLoadListener, ActionListener, DisplayObserver { 65 65 66 66 private static final int BUTTON_SIZE = 40; … … 73 73 private JButton rewindButton; 74 74 private JButton playLauncherButton; 75 private JComboBox frameSelection;75 private JComboBox<String> frameSelection; 76 76 private JToggleButton muteButton; 77 77 private JSlider volumeSlider; … … 86 86 public static String FRAME_PLAYERMASTER_CHANNEL_ID = "#$frameplayer#master$"; 87 87 88 private static final Colo r LOADING_BORDER_COLOR = new Color(22, 205, 5);88 private static final Colour LOADING_BORDER_COLOR = Colour.FromRGB255(22, 205, 5); 89 89 //private static final Color FAILED_MESSAGE_COLOR = Color.RED; 90 90 //private static final Font MESSAGE_FONT = TrackWidgetCommons.FREESPACE_TRACKNAME_FONT; … … 180 180 playPauseButton = new JButton(); 181 181 playPauseButton.addActionListener(this); 182 playPauseButton.setIcon(IconRepository.getIcon("play.png"));182 SwingMiscManager.setJButtonIcon(playPauseButton, IconRepository.getIcon("play.png")); 183 183 playPauseButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE)); 184 184 playPauseButton.setToolTipText("Play selection / Pause"); … … 187 187 stopButton.setEnabled(false); 188 188 stopButton.addActionListener(this); 189 stopButton.setIcon(IconRepository.getIcon("stop.png"));189 SwingMiscManager.setJButtonIcon(stopButton, IconRepository.getIcon("stop.png")); 190 190 stopButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE)); 191 191 stopButton.setToolTipText("Stop playback"); … … 193 193 rewindButton = new JButton(); 194 194 rewindButton.addActionListener(this); 195 rewindButton.setIcon(IconRepository.getIcon("rewind.png"));195 SwingMiscManager.setJButtonIcon(rewindButton, IconRepository.getIcon("rewind.png")); 196 196 rewindButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE)); 197 197 rewindButton.setToolTipText("Rewind to start"); … … 199 199 // Icon changes 200 200 muteButton = new JToggleButton(); 201 muteButton.setSelectedIcon(IconRepository.getIcon("volmute.png"));201 SwingMiscManager.setJButtonIcon(muteButton, IconRepository.getIcon("volmute.png")); 202 202 muteButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE)); 203 203 muteButton.setToolTipText("Toggle mute"); … … 212 212 playLauncherButton = new JButton(); 213 213 playLauncherButton.addActionListener(this); 214 playLauncherButton.setIcon(IconRepository.getIcon("frameplay.png"));214 SwingMiscManager.setJButtonIcon(playLauncherButton, IconRepository.getIcon("frameplay.png")); 215 215 playLauncherButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE)); 216 216 playLauncherButton.setToolTipText("Play from a specific position"); … … 231 231 volumeSlider.setPreferredSize(new Dimension((3 * BUTTON_SIZE) - (2 * VOLUME_SPACING), BUTTON_SIZE)); 232 232 233 frameSelection = new JComboBox ();233 frameSelection = new JComboBox<String>(); 234 234 frameSelection.setEditable(true); 235 235 frameSelection.setPreferredSize(new Dimension(4 * BUTTON_SIZE, BUTTON_SIZE)); … … 304 304 stopButton.setEnabled(false); 305 305 playPauseButton.setEnabled(true); 306 playPauseButton.setIcon(IconRepository.getIcon("play.png"));306 SwingMiscManager.setJButtonIcon(playPauseButton, IconRepository.getIcon("play.png")); 307 307 playLauncherButton.setEnabled(true); 308 308 … … 323 323 playLauncherButton.setEnabled(true); 324 324 playPauseButton.setEnabled(true); 325 playPauseButton.setIcon(IconRepository.getIcon("pause.png"));325 SwingMiscManager.setJButtonIcon(playPauseButton, IconRepository.getIcon("pause.png")); 326 326 327 327 setWidgetEdgeThickness(TrackWidgetCommons.PLAYING_TRACK_EDGE_THICKNESS); … … 336 336 337 337 invalidateSelf(); 338 FrameGraphics.refresh(true);338 DisplayController.requestRefresh(true); 339 339 } 340 340 … … 361 361 MultiTrackPlaybackController.getInstance().addObserver(this); // the core! 362 362 masterMix.addObserver(this); 363 Display IO.addDisplayIOObserver(this);363 DisplayController.addDisplayObserver(this); 364 364 365 365 // Evaluate the state of this add set the state accordingly … … 405 405 406 406 // Remove observers 407 Display IO.removeDisplayIOObserver(this);407 DisplayController.removeDisplayObserver(this); 408 408 SoundDesk.getInstance().removeObserver(this); 409 409 MultiTrackPlaybackController.getInstance().removeObserver(this); … … 544 544 if ((frameSelection.getSelectedItem() != null && frameSelection.getSelectedItem().equals(CURRENT_FRAME_SPECIFIER)) 545 545 || frameSelection.getSelectedItem() == null) 546 return Display IO.getCurrentFrame().getName();546 return DisplayController.getCurrentFrame().getName(); 547 547 548 548 String frameSpecifier = (String)frameSelection.getSelectedItem(); 549 549 550 550 if (frameSpecifier.isEmpty()) { 551 return Display IO.getCurrentFrame().getName();551 return DisplayController.getCurrentFrame().getName(); 552 552 } 553 553 … … 671 671 672 672 String target = getSelectedFrameName(); 673 if (target == Display IO.getCurrentFrame().getName()) target = null;673 if (target == DisplayController.getCurrentFrame().getName()) target = null; 674 674 675 675 // Create the launcher 676 676 FramePlaybackLauncher launcher = new FramePlaybackLauncher(target); 677 launcher.setPosition( FrameMouseActions.MouseX, FrameMouseActions.MouseY);677 launcher.setPosition(DisplayController.getMousePosition()); 678 678 679 679 // Pick it up 680 FrameMouseActions.pickup(launcher);680 StandardGestureActions.pickup(launcher); 681 681 } 682 682 … … 687 687 688 688 // Get border color currently used 689 Colo r oldC = getSource().getBorderColor();690 Colo r newC = null;689 Colour oldC = getSource().getBorderColor(); 690 Colour newC = null; 691 691 692 692 if (this.state == PLAYBACK_LOADING) { … … 714 714 private void updateButtonGUI() { 715 715 716 I connewIcon = null;716 Image newIcon = null; 717 717 if (volumeSlider.getValue() <= 25) 718 718 newIcon = IconRepository.getIcon("vol25.png"); … … 724 724 newIcon = IconRepository.getIcon("vol100.png"); 725 725 726 muteButton.setIcon(newIcon);726 SwingMiscManager.setJButtonIcon(muteButton, newIcon); 727 727 } 728 728 … … 783 783 784 784 // Place last visited frames 785 List<String> history = Display IO.getUnmodifiableVisitedList();785 List<String> history = DisplayController.getUnmodifiableVisitedList(); 786 786 787 787 for (int i = history.size() - 1; i >= 0; i--) { … … 802 802 } 803 803 804 ComboBoxModel model = new DefaultComboBoxModel(orderedModelData.toArray());804 ComboBoxModel<String> model = new DefaultComboBoxModel<String>((String[]) orderedModelData.toArray()); 805 805 806 806 // Remove helper tags from model data -
trunk/src/org/apollo/widgets/LinkedTrack.java
r372 r1102 1 1 package org.apollo.widgets; 2 2 3 import java.awt.Color;4 import java.awt.Font;5 3 import java.awt.FontMetrics; 6 4 import java.awt.GradientPaint; … … 8 6 import java.awt.Graphics2D; 9 7 import java.awt.Paint; 10 import java.awt.Point;11 8 import java.awt.Rectangle; 12 import java.awt.Shape;13 import java.awt.Stroke;14 9 import java.awt.event.ActionEvent; 15 10 import java.awt.event.ActionListener; … … 19 14 import java.awt.event.MouseListener; 20 15 import java.awt.event.MouseMotionListener; 21 import java.awt.geom.Area;22 16 import java.awt.geom.Rectangle2D; 23 17 import java.util.LinkedList; … … 29 23 import javax.swing.SwingUtilities; 30 24 25 import org.apollo.ApolloGestureActions; 26 import org.apollo.ApolloKBMGestureTranslator; 31 27 import org.apollo.ApolloSystem; 32 import org.apollo.AudioFrameKeyboardActions;33 import org.apollo.AudioFrameMouseActions;34 28 import org.apollo.audio.ApolloSubjectChangedEvent; 35 29 import org.apollo.audio.SampledAudioManager; … … 62 56 import org.apollo.util.Mutable; 63 57 import org.apollo.util.ODFrameHeirarchyFetcher; 64 import org.apollo.util.PopupReaper;65 58 import org.apollo.util.StringEx; 66 59 import org.apollo.util.ODFrameHeirarchyFetcher.ODFrameReceiver; 60 import org.expeditee.core.Clip; 61 import org.expeditee.core.Colour; 62 import org.expeditee.core.EnforcedClipStack.EnforcedClipKey; 63 import org.expeditee.core.Fill; 64 import org.expeditee.core.Font; 65 import org.expeditee.core.Line; 66 import org.expeditee.core.Point; 67 import org.expeditee.core.Stroke; 68 import org.expeditee.core.TextLayout; 69 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 70 import org.expeditee.gio.EcosystemManager; 71 import org.expeditee.gio.GraphicsManager; 72 import org.expeditee.gio.TextLayoutManager; 73 import org.expeditee.gio.swing.MouseEventRouter; 74 import org.expeditee.gio.swing.SwingConversions; 75 import org.expeditee.gio.swing.SwingMiscManager; 67 76 import org.expeditee.gui.Browser; 68 import org.expeditee.gui.Display IO;77 import org.expeditee.gui.DisplayController; 69 78 import org.expeditee.gui.Frame; 70 import org.expeditee.gui.FrameGraphics;71 79 import org.expeditee.gui.FrameUtils; 72 80 import org.expeditee.gui.MessageBay; 73 import org.expeditee.gui.MouseEventRouter;74 81 import org.expeditee.gui.PopupManager; 75 82 import org.expeditee.items.Item; 76 83 import org.expeditee.items.ItemParentStateChangedEvent; 77 84 import org.expeditee.items.Text; 78 import org.expeditee.items.widgets.InteractiveWidget;79 85 import org.expeditee.items.widgets.InteractiveWidgetInitialisationFailedException; 80 86 import org.expeditee.items.widgets.InteractiveWidgetNotAvailableException; 81 82 public class LinkedTrack extends InteractiveWidget implements ODFrameReceiver, Observer, MultitrackLoadListener, PlaybackClockListener { 87 import org.expeditee.items.widgets.SwingWidget; 88 import org.expeditee.items.widgets.Widget; 89 90 public class LinkedTrack extends SwingWidget implements ODFrameReceiver, Observer, MultitrackLoadListener, PlaybackClockListener { 83 91 84 92 private String virtualFilename; // immutable … … 92 100 93 101 private PlaybackPopup playbackControlPopup = null; 94 95 102 96 103 // private SoundDeskPopup soundDeskPopup = null; … … 116 123 private String abortMessage = null; 117 124 118 private static final Colo r FAILED_MESSAGE_COLOR = Color.RED;125 private static final Colour FAILED_MESSAGE_COLOR = Colour.RED; 119 126 private static final Font MESSAGE_FONT = TrackWidgetCommons.FREESPACE_TRACKNAME_FONT; 120 private static final Font HELPER_FONT = new Font("Arial", Font. BOLD, 12);121 122 private static final Colo r[] TRACK_COLOR_WHEEL = {123 new Color(66, 145, 255),124 new Color(255, 163, 33),125 new Color(155, 227, 48),127 private static final Font HELPER_FONT = new Font("Arial", Font.Style.BOLD, 12); 128 129 private static final Colour[] TRACK_COLOR_WHEEL = { 130 Colour.FromRGB255(66, 145, 255), 131 Colour.FromRGB255(255, 163, 33), 132 Colour.FromRGB255(155, 227, 48) 126 133 }; 127 private static final Colo r TRACK_LOAD_COLOR = Color.BLACK;128 private static final Colo r TRACK_FAIL_COLOR = Color.RED;129 130 private static final Colo r SELECTION_COLOR = new Color(0,0,0,100);134 private static final Colour TRACK_LOAD_COLOR = Colour.BLACK; 135 private static final Colour TRACK_FAIL_COLOR = Colour.RED; 136 137 private static final Colour SELECTION_COLOR = Colour.FromRGBA255(0,0,0,100); 131 138 132 139 private static final Stroke TRACK_BORDER = Strokes.SOLID_1; 133 140 private static final Stroke TRACK_SELECTED_BORDER = Strokes.SOLID_2; 134 private static final Colo r TRACK_BORDER_COLOR = Color.BLACK;135 private static final Colo r TRACK_SELECTED_BORDER_COLOR = new Color(253, 255, 201);141 private static final Colour TRACK_BORDER_COLOR = Colour.BLACK; 142 private static final Colour TRACK_SELECTED_BORDER_COLOR = Colour.FromRGB255(253, 255, 201); 136 143 137 144 … … 154 161 * @param args 155 162 */ 156 public LinkedTrack(Text source, String[] args) { 163 public LinkedTrack(Text source, String[] args) 164 { 157 165 super(source, new JPanel(), 158 166 100, -1, … … 187 195 playbackControlPopup = new PlaybackPopup(); 188 196 189 nameLabel = new EmulatedTextItem( _swingComponent, new Point(10, 20));190 nameLabel.setBackgroundColor(Colo r.WHITE);197 nameLabel = new EmulatedTextItem("", new Point(10, 20)); 198 nameLabel.setBackgroundColor(Colour.WHITE); 191 199 192 200 String metaName = getStrippedDataString(TrackWidgetCommons.META_NAME_TAG); … … 210 218 public void keyPressed(KeyEvent e) { 211 219 if ((state != PLAYING && state != STOPPED) || e.isControlDown()) return; 212 if (nameLabel.onKeyPressed(e, _swingComponent)) {213 e.consume();214 return;215 }216 220 } 217 221 … … 219 223 if ((state != PLAYING && state != STOPPED)) return; 220 224 else if (e.isControlDown()) { 221 if (e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_RIGHT) { 222 AudioFrameKeyboardActions.adjustInitationTime(LinkedTrack.this, e.getKeyCode() == KeyEvent.VK_LEFT); 223 } else if (e.getKeyCode() == KeyEvent.VK_UP || e.getKeyCode() == KeyEvent.VK_DOWN) { 224 AudioFrameKeyboardActions.adjustVerticlePosition(LinkedTrack.this, e.getKeyCode() == KeyEvent.VK_UP); 225 if (e.getKeyCode() == KeyEvent.VK_LEFT) { 226 ApolloGestureActions.adjustInitiationTime(LinkedTrack.this, -ApolloKBMGestureTranslator.TRACK_WIDGET_TIMELINE_ADJUSTMENT); 227 } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { 228 ApolloGestureActions.adjustInitiationTime(LinkedTrack.this, ApolloKBMGestureTranslator.TRACK_WIDGET_TIMELINE_ADJUSTMENT); 229 } else if (e.getKeyCode() == KeyEvent.VK_UP) { 230 ApolloGestureActions.adjustVerticalPosition(LinkedTrack.this, -ApolloKBMGestureTranslator.TRACK_WIDGET_VERTICAL_ADJUSTMENT); 231 } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { 232 ApolloGestureActions.adjustVerticalPosition(LinkedTrack.this, ApolloKBMGestureTranslator.TRACK_WIDGET_VERTICAL_ADJUSTMENT); 225 233 } 226 } else if (nameLabel.onKeyReleased(e, _swingComponent)) {227 e.consume();228 return;229 234 } 230 235 } … … 234 239 235 240 }); 236 237 241 238 242 updateBorderColor(); … … 346 350 playbackControlPopup.stopButton.setEnabled(false); 347 351 playbackControlPopup.playPauseButton.setEnabled(true); 348 playbackControlPopup.playPauseButton.setIcon(IconRepository.getIcon("play.png"));352 SwingMiscManager.setJButtonIcon(playbackControlPopup.playPauseButton, IconRepository.getIcon("play.png")); 349 353 350 354 … … 363 367 playbackControlPopup.rewindButton.setEnabled(false); 364 368 playbackControlPopup.playPauseButton.setEnabled(true); 365 playbackControlPopup.playPauseButton.setIcon(IconRepository.getIcon("pause.png"));369 SwingMiscManager.setJButtonIcon(playbackControlPopup.playPauseButton, IconRepository.getIcon("pause.png")); 366 370 367 371 setWidgetEdgeThickness(TrackWidgetCommons.PLAYING_TRACK_EDGE_THICKNESS); … … 408 412 409 413 invalidateSelf(); 410 FrameGraphics.refresh(true);414 DisplayController.requestRefresh(true); 411 415 } 412 416 … … 528 532 for (Track t : tracks) setTrackState(t, TRACKSTATE_READY); 529 533 invalidateSelf(); 530 FrameGraphics.refresh(true);534 DisplayController.requestRefresh(true); 531 535 break; 532 536 case MultitrackLoadListener.LOAD_FAILED_BAD_GRAPH: … … 552 556 setTrackState((String) state, TRACKSTATE_READY); 553 557 invalidateSelf(); 554 FrameGraphics.refresh(true);558 DisplayController.requestRefresh(true); 555 559 break; 556 560 … … 611 615 */ 612 616 @Override 613 public InteractiveWidget copy()617 public Widget copy() 614 618 throws InteractiveWidgetNotAvailableException, InteractiveWidgetInitialisationFailedException { 615 619 … … 632 636 source.setData(data); 633 637 634 return InteractiveWidget.createWidget((Text)source);638 return Widget.createWidget((Text)source); 635 639 636 640 } … … 640 644 */ 641 645 @Override 642 protected void onParentStateChanged(int eventType) { 646 protected void onParentStateChanged(int eventType) 647 { 643 648 super.onParentStateChanged(eventType); 644 649 … … 667 672 boolean inferInitTime = true; 668 673 669 if (A udioFrameMouseActions.isYAxisRestictionOn()) {674 if (ApolloGestureActions.isYAxisRestictionOn()) { 670 675 Mutable.Long ms = getInitiationTimeFromMeta(); 671 676 if (ms != null) { … … 683 688 684 689 // Also must not set initiation time if the frame is simply being displayed 685 inferInitTime &=686 (AudioFrameMouseActions.isMouseAnchoring() || AudioFrameMouseActions.isMouseStamping());687 690 //inferInitTime &= (AudioFrameMouseActions.isMouseAnchoring() || AudioFrameMouseActions.isMouseStamping()); 691 inferInitTime &= (eventType == ItemParentStateChangedEvent.EVENT_TYPE_ADDED); 692 688 693 if (inferInitTime) { 689 694 initTime = Mutable.createMutableLong(FrameLayoutDaemon.getInstance().getMSAtX(getX(), parent)); … … 731 736 if (MouseEventRouter.getCurrentMouseEvent() != null && 732 737 MouseEventRouter.getCurrentMouseEvent().getButton() == MouseEvent.BUTTON2) { 733 Frame suspended = Display IO.getCurrentFrame();738 Frame suspended = DisplayController.getCurrentFrame(); 734 739 if (suspended != null) { 735 740 FrameLayoutDaemon.getInstance().suspendLayout(suspended, this); … … 755 760 public void run() { 756 761 invalidateSelf(); 757 FrameGraphics.refresh(true);762 DisplayController.requestRefresh(true); 758 763 } 759 764 }); // NOTE TO REPEAT: Pick up a linked track and delete it directly from freespace … … 946 951 */ 947 952 @Override 948 public void paint (Graphics g) {953 public void paintSwingWidget(Graphics2D gm) { 949 954 950 955 if (Browser._theBrowser == null) return; 951 956 957 GraphicsManager g = EcosystemManager.getGraphicsManager(); 958 952 959 // Ensure that load bar or any text doesn't spill over widgets invalidation area 953 Area clip = FrameGraphics.getCurrentClip(); 954 955 Shape clipBackUp = g.getClip(); 956 957 Area tmpClip = (clip != null) ? clip : 958 new Area(new Rectangle(0, 0, 959 Browser._theBrowser.getContentPane().getWidth(), 960 Browser._theBrowser.getContentPane().getHeight())); 961 962 tmpClip.intersect(new Area(getBounds())); 963 964 if (tmpClip.isEmpty()) return; 965 966 g.setClip(tmpClip); 960 EnforcedClipKey clipKey = g.pushClip(new Clip(getBounds())); 967 961 968 962 // Paint backing 969 g.setColor(SampledTrackGraphView.DEFAULT_BACKGROUND_COLOR); 970 g.fillRect(getX(), getY(), getWidth(), getHeight()); 963 g.drawRectangle(getBounds(), 0.0, new Fill(SwingConversions.fromSwingColor(SampledTrackGraphView.DEFAULT_BACKGROUND_COLOR)), null, null, null); 971 964 972 965 String centralizedMessage = null; 966 Colour colour = null; 973 967 974 968 // Render according to the currently widget state … … 978 972 979 973 case FAILED_STATE: 974 centralizedMessage = failMessage; 975 assert(failMessage != null); 976 colour = FAILED_MESSAGE_COLOR; 977 break; 980 978 case EMPTY_STATE: 979 if (getLink() == null) { 980 centralizedMessage = "Click to create"; 981 } else { 982 centralizedMessage = "Nothing to play"; 983 } 984 985 colour = Colour.DARK_GREY; 986 break; 981 987 case LOADING_TRACK_GRAPH: 982 983 if (state == FAILED_STATE) { 984 centralizedMessage = failMessage; 985 assert(failMessage != null); 986 g.setColor(FAILED_MESSAGE_COLOR); 987 } else if (state == LOADING_TRACK_GRAPH){ 988 centralizedMessage = "Loading..."; 989 g.setColor(Color.DARK_GRAY); 990 } else { // empty 991 if (getLink() == null) { 992 centralizedMessage = "Click to create"; 993 } else { 994 centralizedMessage = "Nothing to play"; 995 } 996 997 g.setColor(Color.DARK_GRAY); 998 } 999 988 centralizedMessage = "Loading..."; 989 colour = Colour.DARK_GREY; 1000 990 break; 1001 991 … … 1008 998 1009 999 for (Track track : tracks) { 1010 track.paintTrackArea( (Graphics2D)g,x, y);1000 track.paintTrackArea(x, y); 1011 1001 if (track.isSelected) { 1012 1002 selected = track; 1013 1003 } else { 1014 track.paintTrackBorder( g,x, y);1004 track.paintTrackBorder(x, y); 1015 1005 1016 1006 if (track.area.height > 15) { // don't clutter up busy linked tracks 1017 drawTrackName(track, g, Color.DARK_GRAY);1007 drawTrackName(track, Colour.DARK_GREY); 1018 1008 } 1019 1009 … … 1025 1015 // the selected border is drawn last 1026 1016 if (selected != null) { 1027 selected.paintTrackBorder( g,x, y);1028 drawTrackName(selected, g, Color.BLACK);1017 selected.paintTrackBorder(x, y); 1018 drawTrackName(selected, Colour.BLACK); 1029 1019 } 1030 1020 … … 1038 1028 1039 1029 centralizedMessage = "Loading dubs..."; 1040 g.setColor(Color.BLACK);1030 colour = Colour.BLACK; 1041 1031 1042 1032 } else { … … 1045 1035 int selLeftX = XatFrame(selectionStart); 1046 1036 if (selectionLength > 1) { 1047 g.setColor(SELECTION_COLOR); 1048 g.fillRect( getX() + selLeftX, 1049 getY(), 1050 XatFrame(selectionStart + selectionLength) - selLeftX, 1051 getHeight()); 1037 colour = SELECTION_COLOR; 1038 AxisAlignedBoxBounds b = new AxisAlignedBoxBounds( getX() + selLeftX, 1039 getY(), 1040 XatFrame(selectionStart + selectionLength) - selLeftX, 1041 getHeight()); 1042 g.drawRectangle(b, 0.0, new Fill(colour), null, null, null); 1052 1043 } 1053 1054 // Draw selection start bar1055 ((Graphics2D)g).setStroke(SampledTrackGraphView.GRAPH_BAR_STROKE);1056 1044 1057 1045 // Note that if the start line is near the edges of the panel it can be concealed - thus … … 1063 1051 x = getWidth() - 1; 1064 1052 } 1065 1066 g.setColor(Color.RED); 1067 g.drawLine( 1053 colour = Colour.RED; 1054 Line l = new Line( 1068 1055 x, 1069 1056 getY(), 1070 1057 x, 1071 1058 getY() + getHeight()); 1059 g.drawLine(l, colour, SwingConversions.fromSwingStroke(SampledTrackGraphView.GRAPH_BAR_STROKE)); 1072 1060 1073 1061 … … 1076 1064 1077 1065 x = XatFrame(currentPlaybackFramePosition) + getX(); 1078 1079 ((Graphics2D)g).setStroke(SampledTrackGraphView.GRAPH_BAR_STROKE); 1080 g.setColor(SampledTrackGraphView.PLAYBACK_BAR_COLOR); 1081 g.drawLine(x, getY(), x, getY() + getHeight()); 1066 colour = SwingConversions.fromSwingColor(SampledTrackGraphView.PLAYBACK_BAR_COLOR); 1067 Line l2 = new Line(x, getY(), x, getY() + getHeight()); 1068 g.drawLine(l2, colour, SwingConversions.fromSwingStroke(SampledTrackGraphView.GRAPH_BAR_STROKE)); 1082 1069 1083 1070 } 1084 1071 1085 1072 } 1086 1087 1088 1073 1089 1074 break; … … 1094 1079 if (centralizedMessage != null) { 1095 1080 1096 FontMetrics fm = g.getFontMetrics(MESSAGE_FONT); 1097 Rectangle2D rect = fm.getStringBounds(centralizedMessage, g); 1081 TextLayoutManager t = EcosystemManager.getTextLayoutManager(); 1082 1083 TextLayout layout = t.layoutString(centralizedMessage, MESSAGE_FONT, Point.ORIGIN, null, Integer.MAX_VALUE, 0, true, false).get(0); 1084 1085 AxisAlignedBoxBounds layoutBounds = layout.getPixelBounds(0, 0); 1098 1086 1099 1087 // Calc centered position 1100 int x = getX() + ((getWidth() / 2) - (int)( rect.getWidth() / 2));1101 int y = getY() + ((getHeight() / 2) + (int)( rect.getHeight() / 2) - 4);1088 int x = getX() + ((getWidth() / 2) - (int)(layoutBounds.getWidth() / 2)); 1089 int y = getY() + ((getHeight() / 2) + (int)(layoutBounds.getHeight() / 2) - 4); 1102 1090 1103 1091 // Draw text 1104 g.setFont(MESSAGE_FONT); 1105 g.drawString(centralizedMessage, x, y); 1092 g.drawTextLayout(layout, new Point(x, y), colour); 1106 1093 1107 1094 // Draw add icon if waiting for a link 1108 1095 if (getLink() == null) { 1109 IconRepository.getIcon("goto.png").paintIcon(null,1096 /*IconRepository.getIcon("goto.png").paintIcon(null, 1110 1097 g, 1111 1098 x - 34, 1112 getY() + (getHeight() / 2) - 12); 1099 getY() + (getHeight() / 2) - 12);*/ 1100 g.drawImage(IconRepository.getIcon("goto.png"), new Point(x - 34, getY() + (getHeight() / 2) - 12)); 1113 1101 } 1114 1102 … … 1116 1104 1117 1105 // Paint name label over everything 1118 if (state != NOT_INITIALIZED && state != FAILED_STATE && state != EMPTY_STATE) 1119 nameLabel.paint(g); 1120 1121 g.setClip(clipBackUp); 1122 1123 super.paintLink((Graphics2D)g); 1124 1125 } 1126 1127 private void drawTrackName(Track track, Graphics g, Color textColor) { 1128 1106 if (state != NOT_INITIALIZED && state != FAILED_STATE && state != EMPTY_STATE) nameLabel.paint(); 1107 1108 g.popClip(clipKey); 1109 1110 } 1111 1112 private void drawTrackName(Track track, Colour textColor) 1113 { 1114 Graphics2D g = SwingMiscManager.getIfUsingSwingGraphicsManager().getCurrentSurface(); 1115 1129 1116 // Draw helper message for user to give meaningful information of what they 1130 1117 // are actually highlighting … … 1133 1120 helperMessage = helperMessage + " (" + track.getParentFrameName() + ")"; 1134 1121 1135 FontMetrics fm = g.getFontMetrics( HELPER_FONT);1122 FontMetrics fm = g.getFontMetrics(SwingMiscManager.getIfUsingSwingFontManager().getInternalFont(HELPER_FONT)); 1136 1123 Rectangle2D rect = fm.getStringBounds(helperMessage, g); 1137 1124 … … 1149 1136 1150 1137 // Draw text 1151 g.setColor( textColor);1152 g.setFont( HELPER_FONT);1138 g.setColor(SwingConversions.toSwingColor(textColor)); 1139 g.setFont(SwingMiscManager.getIfUsingSwingFontManager().getInternalFont(HELPER_FONT)); 1153 1140 g.drawString(helperMessage, xoff, yoff); 1154 1141 … … 1156 1143 1157 1144 @Override 1158 protected void paintInFreeSpace(Graphics g) { 1159 1160 super.paintInFreeSpace(g); 1161 1162 Shape clipBackUp = g.getClip(); 1163 Rectangle tmpClip = (clipBackUp != null) ? clipBackUp.getBounds() : 1164 new Rectangle(0, 0, 1165 Browser._theBrowser.getContentPane().getWidth(), 1166 Browser._theBrowser.getContentPane().getHeight()); 1167 1168 g.setClip(tmpClip.intersection(getBounds())); 1145 protected void paintInFreeSpace() 1146 { 1147 super.paintInFreeSpace(); 1148 1149 // Draw the name of the track 1150 1151 GraphicsManager g = EcosystemManager.getGraphicsManager(); 1152 1153 // Ensure that load bar or any text doesn't spill over widgets invalidation area 1154 EnforcedClipKey clipKey = g.pushClip(new Clip(getBounds())); 1169 1155 1170 1156 // Draw the name … … 1173 1159 name = "Unnamed"; 1174 1160 } 1175 1176 g.setFont(TrackWidgetCommons.FREESPACE_TRACKNAME_FONT); 1177 g.setColor(TrackWidgetCommons.FREESPACE_TRACKNAME_TEXT_COLOR); 1178 1179 // Center track name 1180 FontMetrics fm = g.getFontMetrics(TrackWidgetCommons.FREESPACE_TRACKNAME_FONT); 1181 Rectangle2D rect = fm.getStringBounds(name, g); 1182 1183 g.drawString( 1184 name, 1185 this.getX() + (int)((getWidth() - rect.getWidth()) / 2), 1186 this.getY() + (int)((getHeight() - rect.getHeight()) / 2) + (int)rect.getHeight() 1187 ); 1188 1189 g.setClip(clipBackUp); 1190 1191 1161 1162 List<TextLayout> layouts = EcosystemManager.getTextLayoutManager().layoutString(name, TrackWidgetCommons.FREESPACE_TRACKNAME_FONT, getBounds().getTopLeft(), null, getBounds().getWidth(), 0, true, false); 1163 1164 // Centre the track name 1165 int lineYDelta = 0; 1166 for (TextLayout layout : layouts) { 1167 AxisAlignedBoxBounds bounds = layout.getPixelBounds(getBounds().getMinX(), getBounds().getMinY() + lineYDelta); 1168 int centreXOffset = (getBounds().getWidth() - bounds.getWidth()) / 2; 1169 bounds.translate(centreXOffset, 0); 1170 g.drawTextLayout(layout, bounds.getTopLeft(), TrackWidgetCommons.FREESPACE_TRACKNAME_TEXT_COLOR); 1171 lineYDelta += bounds.getHeight(); 1172 } 1173 1174 g.popClip(clipKey); 1192 1175 } 1193 1176 … … 1205 1188 x = XatFrame(currentPlaybackFramePosition); 1206 1189 1207 FrameGraphics.invalidateArea(new Rectangle(1190 DisplayController.invalidateArea(new AxisAlignedBoxBounds( 1208 1191 x + offsetX, 1209 1192 offsetY, … … 1220 1203 x = XatFrame(currentPlaybackFramePosition); 1221 1204 1222 FrameGraphics.invalidateArea(new Rectangle(1205 DisplayController.invalidateArea(new AxisAlignedBoxBounds( 1223 1206 x + offsetX , 1224 1207 offsetY, … … 1462 1445 1463 1446 // Get border color currently used 1464 Colo r oldC = getSource().getBorderColor();1465 1466 Colo r newC = TrackWidgetCommons.getBorderColor(1447 Colour oldC = getSource().getBorderColor(); 1448 1449 Colour newC = TrackWidgetCommons.getBorderColor( 1467 1450 SoundDesk.getInstance().isSolo(masterMix.getChannelID()), 1468 1451 masterMix.isMuted()); … … 1518 1501 * 1519 1502 */ 1520 private class PlaybackPopup extends PlaybackControlPopup { 1521 1522 private static final long serialVersionUID = 1L; 1523 1503 private class PlaybackPopup extends PlaybackControlPopup 1504 { 1524 1505 public PlaybackPopup() { 1525 1506 miscButton.setActionCommand("goto"); 1526 miscButton.setIcon(IconRepository.getIcon("goto.png"));1507 SwingMiscManager.setJButtonIcon(miscButton, IconRepository.getIcon("goto.png")); 1527 1508 miscButton.setToolTipText("Goto linked frame"); 1528 1509 } 1529 1510 1530 1511 @Override 1531 public void onHide() {1532 super.onHide();1512 public void onHide() 1513 { 1533 1514 } 1534 1515 1535 1516 @Override 1536 public void onShow() {1537 super.onShow();1517 public void onShow() 1518 { 1538 1519 updateVolume((int)(100 * masterMix.getVolume())); 1539 1520 updateMute(masterMix.isMuted()); 1540 1521 updateSolo(SoundDesk.getInstance().isSolo(masterMix.getChannelID())); 1541 1522 } 1542 1543 public void actionPerformed(ActionEvent e) {1544 1523 1524 public void actionPerformed(ActionEvent e) 1525 { 1545 1526 if (e.getSource() == miscButton) { 1546 1527 … … 1670 1651 currentPlaybackFramePosition = -1; 1671 1652 setSelection(0, 0); // invalidates 1672 FrameGraphics.refresh(true);1653 DisplayController.requestRefresh(true); 1673 1654 1674 1655 } … … 1691 1672 } 1692 1673 1693 private class MouseActions implements MouseListener, MouseMotionListener { 1694 1695 public void mouseClicked(MouseEvent e) { 1674 private class MouseActions implements MouseListener, MouseMotionListener 1675 { 1676 public void mouseClicked(MouseEvent e) 1677 { 1696 1678 assert(state != EMPTY_STATE); 1697 1679 … … 1705 1687 } 1706 1688 1707 1708 public void mouseEntered(MouseEvent e){1689 public void mouseEntered(MouseEvent e) 1690 { 1709 1691 assert(state != EMPTY_STATE); 1710 1692 } 1711 1693 1712 1694 1713 public void mouseExited(MouseEvent e) { 1695 public void mouseExited(MouseEvent e) 1696 { 1714 1697 assert(state != EMPTY_STATE); 1715 1716 } 1717 1718 1719 public void mousePressed(MouseEvent e) { 1720 1698 } 1699 1700 1701 public void mousePressed(MouseEvent e) 1702 { 1721 1703 assert(state != EMPTY_STATE); 1722 1704 … … 1732 1714 setSelection(frameAtX(selectionStartX), 1); 1733 1715 1734 FrameGraphics.refresh(true); 1735 } 1736 1737 1738 public void mouseReleased(MouseEvent e) { 1739 1740 1716 DisplayController.requestRefresh(true); 1717 } 1718 1719 1720 public void mouseReleased(MouseEvent e) 1721 { 1741 1722 assert(state != EMPTY_STATE); 1742 1743 1723 1744 1724 // Was the release a simple click … … 1765 1745 return; 1766 1746 } 1767 1768 1769 } 1770 1771 1772 public void mouseDragged(MouseEvent e) { 1773 1747 } 1748 1749 1750 public void mouseDragged(MouseEvent e) 1751 { 1774 1752 assert(state != EMPTY_STATE); 1775 1753 … … 1800 1778 } 1801 1779 1802 FrameGraphics.refresh(true); 1803 } 1804 1805 public void mouseMoved(MouseEvent e) { 1780 DisplayController.requestRefresh(true); 1781 } 1782 1783 public void mouseMoved(MouseEvent e) 1784 { 1806 1785 assert(state != EMPTY_STATE); 1807 1786 1808 1787 if (state != PLAYING && state != STOPPED) return; 1809 1788 1810 if (nameLabel.onMouseMoved(e, _swingComponent)) { 1811 e.consume(); 1812 return; 1789 if (nameLabel != null) { 1790 nameLabel.gainFocus(); 1813 1791 } 1814 1792 … … 1822 1800 1823 1801 // Get rid of all popups 1824 PopupManager.getInstance().hideAuto hidePopups();1825 1826 Rectangle animationSource = _swingComponent.getBounds();1802 PopupManager.getInstance().hideAutoHidePopups(); 1803 1804 AxisAlignedBoxBounds animationSource = SwingConversions.fromSwingRectangle(_swingComponent.getBounds()); 1827 1805 1828 1806 // Determine where popup should show 1829 1807 int x = LinkedTrack.this.getX(); 1830 int y = LinkedTrack.this.getY() - playbackControlPopup.get Height() - 2; // by default show above1808 int y = LinkedTrack.this.getY() - playbackControlPopup.getFullBounds().getHeight() - 2; // by default show above 1831 1809 1832 1810 // I get sick.dizzy from the popup expanding from the whole thing... 1833 animationSource. height = 1;1834 animationSource. width = Math.min(animationSource.width, playbackControlPopup.getWidth());1811 animationSource.getSize().height = 1; 1812 animationSource.getSize().width = Math.min(animationSource.getWidth(), playbackControlPopup.getFullBounds().getWidth()); 1835 1813 1836 1814 if (y < 0) { 1837 1815 y = LinkedTrack.this.getY() + LinkedTrack.this.getHeight() + 2; 1838 animationSource. y = y - 2;1816 animationSource.getTopLeft().y = y - 2; 1839 1817 } 1840 1818 1841 1819 // Animate the popup 1842 PopupManager.getInstance().showPopup( 1843 playbackControlPopup, 1844 new Point(x, y), 1845 _swingComponent, 1846 PopupManager.getInstance().new ExpandShrinkAnimator( 1847 animationSource, 1848 Color.LIGHT_GRAY)); 1849 1850 PopupReaper.getInstance().initPopupLifetime( 1851 playbackControlPopup, 1852 PopupManager.getInstance().new ExpandShrinkAnimator( 1853 animationSource, 1854 Color.LIGHT_GRAY), 1855 TrackWidgetCommons.POPUP_LIFETIME); 1856 1820 playbackControlPopup.getAutoHideTime().setLifetime(TrackWidgetCommons.POPUP_LIFETIME); 1821 PopupManager.getInstance().add(playbackControlPopup); 1822 playbackControlPopup.show(); 1857 1823 } else { 1858 PopupReaper.getInstance().revivePopup(playbackControlPopup, TrackWidgetCommons.POPUP_LIFETIME);1824 playbackControlPopup.show(); 1859 1825 } 1860 1826 … … 1878 1844 if (shouldInvalidate) { 1879 1845 invalidateSelf(); 1880 FrameGraphics.refresh(true);1846 DisplayController.requestRefresh(true); 1881 1847 } 1882 1848 } … … 1888 1854 * @author Brook Novak 1889 1855 */ 1890 private class Track {1891 1856 private class Track 1857 { 1892 1858 private AbsoluteTrackNode absNode; // immutable. Never null 1893 1859 1894 1860 private Rectangle area; 1895 1861 1896 private Colo r baseColor;1862 private Colour baseColor; 1897 1863 1898 1864 boolean isSelected = false; … … 1900 1866 private int state = TRACKSTATE_READY; 1901 1867 1902 Track(AbsoluteTrackNode absNode) { 1868 Track(AbsoluteTrackNode absNode) 1869 { 1903 1870 assert(absNode != null); 1904 1871 this.absNode = absNode; 1905 1872 } 1906 1873 1907 public String getChannelID() { 1874 public String getChannelID() 1875 { 1908 1876 return absNode.getChannelID(); 1909 1877 } … … 1929 1897 } 1930 1898 1931 public void paintTrackArea(Graphics2D g, int x, int y) { 1899 public void paintTrackArea(int x, int y) 1900 { 1901 Graphics2D g = SwingMiscManager.getIfUsingSwingGraphicsManager().getCurrentSurface(); 1932 1902 1933 1903 if (state == TRACKSTATE_LOADING && LinkedTrack.this.state == PLAYBACK_LOADING) { 1934 g.setColor( TRACK_LOAD_COLOR);1904 g.setColor(SwingConversions.toSwingColor(TRACK_LOAD_COLOR)); 1935 1905 } else if (state == TRACKSTATE_FAILED) { 1936 g.setColor( TRACK_FAIL_COLOR);1906 g.setColor(SwingConversions.toSwingColor(TRACK_FAIL_COLOR)); 1937 1907 } else { 1938 g.setColor( baseColor);1908 g.setColor(SwingConversions.toSwingColor(baseColor)); 1939 1909 } 1940 1910 … … 1943 1913 1944 1914 GradientPaint gp = new GradientPaint( 1945 (int) (area.x + x + (area.width / 2)), area.y + y + (int)(area.height * 0.8), baseColor,1946 (int) (area.x + x + (area.width / 2)), area.y + y, TRACK_SELECTED_BORDER_COLOR);1915 (int) (area.x + x + (area.width / 2)), area.y + y + (int)(area.height * 0.8), SwingConversions.toSwingColor(baseColor), 1916 (int) (area.x + x + (area.width / 2)), area.y + y, SwingConversions.toSwingColor(TRACK_SELECTED_BORDER_COLOR)); 1947 1917 g.setPaint(gp); 1948 1918 } 1949 1919 1950 // Draw a filled rect - represented a track in the h eirarchy1920 // Draw a filled rect - represented a track in the hierarchy 1951 1921 g.fillRect(area.x + x, area.y + y, area.width, area.height); 1952 1922 … … 1957 1927 } 1958 1928 1959 public void paintTrackBorder(Graphics g, int x, int y) { 1929 public void paintTrackBorder(int x, int y) 1930 { 1931 Graphics g = SwingMiscManager.getIfUsingSwingGraphicsManager().getCurrentSurface(); 1960 1932 1961 1933 if (isSelected) { 1962 g.setColor( TRACK_SELECTED_BORDER_COLOR);1963 ((Graphics2D)g).setStroke( TRACK_SELECTED_BORDER);1934 g.setColor(SwingConversions.toSwingColor(TRACK_SELECTED_BORDER_COLOR)); 1935 ((Graphics2D)g).setStroke(SwingConversions.toSwingStroke(TRACK_SELECTED_BORDER)); 1964 1936 } else { 1965 g.setColor( TRACK_BORDER_COLOR);1966 ((Graphics2D)g).setStroke( TRACK_BORDER); // todo muted colors etc...1937 g.setColor(SwingConversions.toSwingColor(TRACK_BORDER_COLOR)); 1938 ((Graphics2D)g).setStroke(SwingConversions.toSwingStroke(TRACK_BORDER)); // todo muted colors etc... 1967 1939 } 1968 1940 … … 1972 1944 } 1973 1945 1946 // TODO: Why not? cts16 1974 1947 @Override 1975 1948 public boolean isWidgetEdgeThicknessAdjustable() { -
trunk/src/org/apollo/widgets/MasterVolume.java
r315 r1102 12 12 import org.expeditee.items.ItemParentStateChangedEvent; 13 13 import org.expeditee.items.Text; 14 import org.expeditee.items.widgets. InteractiveWidget;14 import org.expeditee.items.widgets.SwingWidget; 15 15 16 16 /** … … 20 20 * 21 21 */ 22 public class MasterVolume extends InteractiveWidget implements Observer {22 public class MasterVolume extends SwingWidget implements Observer { 23 23 24 24 private VolumeControlButton vcButton; -
trunk/src/org/apollo/widgets/MetronomePlayer.java
r335 r1102 21 21 import org.apollo.mvc.Subject; 22 22 import org.apollo.mvc.SubjectChangedEvent; 23 import org.expeditee.gio.swing.SwingMiscManager; 23 24 import org.expeditee.items.ItemParentStateChangedEvent; 24 25 import org.expeditee.items.Text; 25 import org.expeditee.items.widgets. InteractiveWidget;26 import org.expeditee.items.widgets.SwingWidget; 26 27 27 28 /** … … 33 34 * 34 35 */ 35 public class MetronomePlayer extends InteractiveWidget implements Observer {36 public class MetronomePlayer extends SwingWidget implements Observer { 36 37 37 38 private JLabel tempoLabel; 38 39 private JSlider bpmSlider; 39 40 private JButton startStopButton; 40 private JComboBox beatsPerMeasureCombo;41 private JComboBox<String> beatsPerMeasureCombo; 41 42 private JCheckBox enabledCheckbox; 42 43 private boolean interfaceIsUpdating = false; … … 84 85 }); 85 86 86 beatsPerMeasureCombo = new JComboBox (new String[]{"1", "2", "3", "4", "5", "6", "7", "8"});87 beatsPerMeasureCombo = new JComboBox<String>(new String[]{"1", "2", "3", "4", "5", "6", "7", "8"}); 87 88 beatsPerMeasureCombo.setPreferredSize(new Dimension(60, 25)); 88 89 beatsPerMeasureCombo.setEditable(false); … … 133 134 134 135 if (Metronome.getInstance().isPlaying()) { 135 startStopButton.setIcon(IconRepository.getIcon("metrostop.png"));136 SwingMiscManager.setJButtonIcon(startStopButton, IconRepository.getIcon("metrostop.png")); 136 137 setWidgetEdgeThickness(TrackWidgetCommons.PLAYING_TRACK_EDGE_THICKNESS); 137 138 138 139 } else { 139 startStopButton.setIcon(IconRepository.getIcon("metroplay.png"));140 SwingMiscManager.setJButtonIcon(startStopButton, IconRepository.getIcon("metroplay.png")); 140 141 setWidgetEdgeThickness(TrackWidgetCommons.STOPPED_TRACK_EDGE_THICKNESS); 141 142 } -
trunk/src/org/apollo/widgets/SampleRecorder.java
r1057 r1102 1 1 package org.apollo.widgets; 2 2 3 import java.awt.Color;4 3 import java.awt.Dimension; 5 4 import java.awt.FontMetrics; … … 49 48 import org.apollo.util.ApolloSystemLog; 50 49 import org.apollo.util.TrackNameCreator; 51 import org.expeditee.gui.DisplayIO; 50 import org.expeditee.core.Colour; 51 import org.expeditee.gio.gesture.StandardGestureActions; 52 import org.expeditee.gio.swing.SwingConversions; 53 import org.expeditee.gio.swing.SwingMiscManager; 54 import org.expeditee.gui.DisplayController; 52 55 import org.expeditee.gui.Frame; 53 import org.expeditee.gui.FrameGraphics;54 import org.expeditee.gui.FrameMouseActions;55 56 import org.expeditee.items.ItemParentStateChangedEvent; 56 57 import org.expeditee.items.Text; 57 import org.expeditee.items.widgets. InteractiveWidget;58 import org.expeditee.items.widgets.SwingWidget; 58 59 59 60 /** … … 63 64 * 64 65 */ 65 public class SampleRecorder extends InteractiveWidget 66 implements ActionListener, Observer, MultitrackLoadListener { 66 public class SampleRecorder extends SwingWidget implements ActionListener, Observer, MultitrackLoadListener { 67 67 68 68 private enum WidgetState { … … 105 105 private final static int MAX_COUNTDOWN_TIME = 60; 106 106 107 private static final Colo r GRAPH_BACKCOLOR = Color.BLACK;108 private static final Colo r GRAPH_WAVECOLOR = Color.GREEN;107 private static final Colour GRAPH_BACKCOLOR = Colour.BLACK; 108 private static final Colour GRAPH_WAVECOLOR = Colour.GREEN; 109 109 110 110 private final static int RENDER_POINTS_PER_SECOND = 20; // how many points to render each second … … 112 112 private final static String COUNTDOWN_META = "countdown="; 113 113 114 public SampleRecorder(Text source, String[] args) { 114 public SampleRecorder(Text source, String[] args) 115 { 115 116 this(source, args, false); 116 117 } 117 118 118 public SampleRecorder(Text source, String[] args, boolean isTemporary) { 119 public SampleRecorder(Text source, String[] args, boolean isTemporary) 120 { 119 121 super(source, new JPanel(new GridBagLayout()), 120 122 AnimatedSampleGraph.GRAPH_WIDTH + (2 * HORO_SPACING), … … 132 134 // Create gui layout 133 135 recordButton = new JButton(); 134 recordButton.setIcon(IconRepository.getIcon("record.png"));136 SwingMiscManager.setJButtonIcon(recordButton, IconRepository.getIcon("record.png")); 135 137 recordButton.addActionListener(this); 136 138 recordButton.setPreferredSize(new Dimension(AnimatedSampleGraph.GRAPH_WIDTH / 2, BUTTON_HEIGHT)); 137 139 138 140 recordSynchedButton = new JButton(); 139 recordSynchedButton.setIcon(IconRepository.getIcon("recordplay.png"));141 SwingMiscManager.setJButtonIcon(recordSynchedButton, IconRepository.getIcon("recordplay.png")); 140 142 recordSynchedButton.addActionListener(this); 141 143 recordSynchedButton.setPreferredSize(new Dimension(AnimatedSampleGraph.GRAPH_WIDTH / 2, BUTTON_HEIGHT)); 142 144 143 145 stopButton = new JButton(); 144 stopButton.setIcon(IconRepository.getIcon("stop.png"));146 SwingMiscManager.setJButtonIcon(stopButton, IconRepository.getIcon("stop.png")); 145 147 stopButton.addActionListener(this); 146 148 stopButton.setPreferredSize(new Dimension(AnimatedSampleGraph.GRAPH_WIDTH, BUTTON_HEIGHT)); … … 303 305 304 306 sampleGraph.alternateText = Integer.toString(countDown); 305 sampleGraph.alternateTextColor = (countDown > 3) ? Colo r.WHITE : Color.RED;307 sampleGraph.alternateTextColor = (countDown > 3) ? Colour.WHITE : Colour.RED; 306 308 sampleGraph.invalidateGraph(); 307 FrameGraphics.refresh(true);309 DisplayController.requestRefresh(true); 308 310 309 311 countdownThread = new CountDownTimer(countDown); … … 373 375 Frame targetFrame = getParentFrame(); 374 376 if (targetFrame == null) { 375 targetFrame = Display IO.getCurrentFrame();377 targetFrame = DisplayController.getCurrentFrame(); 376 378 } 377 379 … … 398 400 } else { 399 401 400 FrameMouseActions.pickup(trackWidget.getItems());402 StandardGestureActions.pickup(trackWidget.getItems()); 401 403 402 404 // Reset the state … … 602 604 assert (state == WidgetState.Ready); 603 605 604 Frame target = Display IO.getCurrentFrame();606 Frame target = DisplayController.getCurrentFrame(); 605 607 if (target == null) return; 606 608 … … 608 610 609 611 RecordOverdubLauncher launcher = new RecordOverdubLauncher((Integer)countDownSpinner.getValue()); 610 launcher.setPosition( FrameMouseActions.MouseX, FrameMouseActions.MouseY);612 launcher.setPosition(DisplayController.getMousePosition()); 611 613 612 614 // Pick it up 613 FrameMouseActions.pickup(launcher);615 StandardGestureActions.pickup(launcher); 614 616 615 617 } … … 757 759 setState(WidgetState.LoadingPlayback, "Loading tracks..."); 758 760 759 Frame currentFrame = Display IO.getCurrentFrame();761 Frame currentFrame = DisplayController.getCurrentFrame(); 760 762 if (currentFrame == null || currentFrame.getName() == null) { 761 763 … … 843 845 844 846 private String alternateText = null; 845 private Colo r alternateTextColor = Color.WHITE;847 private Colour alternateTextColor = Colour.WHITE; 846 848 847 849 AnimatedSampleGraph() { 848 850 imageBuffer = new BufferedImage(GRAPH_WIDTH, GRAPH_HEIGHT, BufferedImage.TYPE_INT_RGB); 849 851 imageGraphics = (Graphics2D)imageBuffer.getGraphics(); 850 imageGraphics.setColor( GRAPH_BACKCOLOR);852 imageGraphics.setColor(SwingConversions.toSwingColor(GRAPH_BACKCOLOR)); 851 853 imageGraphics.fillRect(0, 0, GRAPH_WIDTH, GRAPH_HEIGHT); 852 854 setPreferredSize(new Dimension(GRAPH_WIDTH, GRAPH_HEIGHT)); … … 857 859 */ 858 860 public void clear() { 859 imageGraphics.setColor( GRAPH_BACKCOLOR);861 imageGraphics.setColor(SwingConversions.toSwingColor(GRAPH_BACKCOLOR)); 860 862 imageGraphics.fillRect(0, 0, GRAPH_WIDTH, GRAPH_HEIGHT); 861 863 invalidateGraph(); … … 867 869 if (alternateText != null) { 868 870 869 g.setColor( Color.BLACK);871 g.setColor(SwingConversions.toSwingColor(Colour.BLACK)); 870 872 g.fillRect(0, 0, getWidth(), getHeight()); 871 873 872 g.setFont( TrackWidgetCommons.FREESPACE_TRACKNAME_FONT);873 g.setColor( alternateTextColor);874 g.setFont(SwingMiscManager.getIfUsingSwingFontManager().getInternalFont(TrackWidgetCommons.FREESPACE_TRACKNAME_FONT)); 875 g.setColor(SwingConversions.toSwingColor(alternateTextColor)); 874 876 875 877 // Center track name 876 FontMetrics fm = g.getFontMetrics( TrackWidgetCommons.FREESPACE_TRACKNAME_FONT);878 FontMetrics fm = g.getFontMetrics(SwingMiscManager.getIfUsingSwingFontManager().getInternalFont(TrackWidgetCommons.FREESPACE_TRACKNAME_FONT)); 877 879 Rectangle2D rect = fm.getStringBounds(alternateText, g); 878 880 … … 907 909 908 910 // Render backcolor 909 imageGraphics.setColor( GRAPH_BACKCOLOR);911 imageGraphics.setColor(SwingConversions.toSwingColor(GRAPH_BACKCOLOR)); 910 912 imageGraphics.fillRect(GRAPH_WIDTH - pixelWidth, 0, pixelWidth, GRAPH_HEIGHT); 911 913 912 914 // Render wave forms from lastSampleHeight 913 imageGraphics.setColor( GRAPH_WAVECOLOR);915 imageGraphics.setColor(SwingConversions.toSwingColor(GRAPH_WAVECOLOR)); 914 916 int currentPixelX = GRAPH_WIDTH - pixelWidth; 915 917 … … 933 935 Rectangle dirty = this.getBounds(); 934 936 dirty.translate(SampleRecorder.this.getX(), SampleRecorder.this.getY()); 935 FrameGraphics.invalidateArea(dirty);936 FrameGraphics.refresh(true);937 DisplayController.invalidateArea(SwingConversions.fromSwingRectangle(dirty)); 938 DisplayController.requestRefresh(true); 937 939 938 940 } … … 979 981 sampleGraph.alternateText = Integer.toString(currentCountdown); 980 982 sampleGraph.alternateTextColor = (currentCountdown > 3) ? 981 Colo r.WHITE : Color.RED;983 Colour.WHITE : Colour.RED; 982 984 sampleGraph.invalidateGraph(); 983 FrameGraphics.refresh(true);985 DisplayController.requestRefresh(true); 984 986 } 985 987 }); -
trunk/src/org/apollo/widgets/SampledTrack.java
r1007 r1102 5 5 import java.awt.Graphics; 6 6 import java.awt.Graphics2D; 7 import java.awt.Point;8 7 import java.awt.Rectangle; 9 8 import java.awt.Shape; 10 import java.awt.Stroke;11 9 import java.awt.event.ActionEvent; 12 10 import java.awt.event.KeyEvent; … … 27 25 import javax.swing.SwingUtilities; 28 26 29 import org.apollo.A udioFrameKeyboardActions;30 import org.apollo.A udioFrameMouseActions;27 import org.apollo.ApolloGestureActions; 28 import org.apollo.ApolloKBMGestureTranslator; 31 29 import org.apollo.audio.ApolloPlaybackMixer; 32 30 import org.apollo.audio.ApolloSubjectChangedEvent; … … 56 54 import org.apollo.util.AudioMath; 57 55 import org.apollo.util.Mutable; 58 import org.apollo.util.PopupReaper;59 56 import org.apollo.util.TrackModelHandler; 60 57 import org.apollo.util.TrackModelLoadManager; 61 58 import org.apollo.util.TrackNameCreator; 62 import org.expeditee.gui.Browser; 63 import org.expeditee.gui.DisplayIO; 59 import org.expeditee.Util; 60 import org.expeditee.core.Colour; 61 import org.expeditee.core.Point; 62 import org.expeditee.core.Stroke; 63 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 64 import org.expeditee.gio.gesture.StandardGestureActions; 65 import org.expeditee.gio.swing.MouseEventRouter; 66 import org.expeditee.gio.swing.SwingConversions; 67 import org.expeditee.gio.swing.SwingMiscManager; 68 import org.expeditee.gui.DisplayController; 64 69 import org.expeditee.gui.Frame; 65 import org.expeditee.gui.FrameGraphics;66 70 import org.expeditee.gui.FrameIO; 67 import org.expeditee.gui.FrameMouseActions;68 import org.expeditee.gui.MouseEventRouter;69 71 import org.expeditee.gui.PopupManager; 70 72 import org.expeditee.items.ItemParentStateChangedEvent; … … 72 74 import org.expeditee.items.Text; 73 75 import org.expeditee.items.widgets.HeavyDutyInteractiveWidget; 74 import org.expeditee.items.widgets.InteractiveWidget;75 76 import org.expeditee.items.widgets.InteractiveWidgetInitialisationFailedException; 76 77 import org.expeditee.items.widgets.InteractiveWidgetNotAvailableException; 78 import org.expeditee.items.widgets.Widget; 77 79 78 80 /** … … 82 84 * 83 85 */ 84 public class SampledTrack extends HeavyDutyInteractiveWidget 85 implements TrackModelHandler, EffecientInvalidator, Observer { 86 public class SampledTrack extends HeavyDutyInteractiveWidget implements TrackModelHandler, EffecientInvalidator, Observer { 86 87 87 88 /** The observered subject. Can be null */ … … 115 116 private static final Stroke FREESPACE_OUTLINING = Strokes.SOLID_2; 116 117 117 private static final Colo r SEMI_TRANSPARENT_FREESPACE_BACKCOLOR = new Color(118 private static final Colour SEMI_TRANSPARENT_FREESPACE_BACKCOLOR = new Colour( 118 119 FREESPACE_BACKCOLOR.getRed(), FREESPACE_BACKCOLOR.getGreen(), 119 FREESPACE_BACKCOLOR.getBlue(), 128);120 FREESPACE_BACKCOLOR.getBlue(), Colour.FromComponent255(128)); 120 121 121 122 … … 173 174 initObservers(); 174 175 176 } 177 178 @Override 179 public void onMoved() 180 { 181 if (nameLabel != null) nameLabel.setPosition(new Point(getX() + 10, getY() + 20)); 175 182 } 176 183 … … 279 286 280 287 if (nameLabel != null) { 281 nameLabel. onMouseMoved(e, fulltrackView);288 nameLabel.gainFocus(); 282 289 } 283 290 … … 291 298 292 299 // Get rid of all popups 293 PopupManager.getInstance().hideAuto hidePopups();300 PopupManager.getInstance().hideAutoHidePopups(); 294 301 295 302 Rectangle animationSource = _swingComponent.getBounds(); … … 297 304 // Determine where popup should show 298 305 int x = SampledTrack.this.getX(); 299 int y = SampledTrack.this.getY() - playbackControlPopup.get Height() - 2; // by default show above306 int y = SampledTrack.this.getY() - playbackControlPopup.getFullBounds().getHeight() - 2; // by default show above 300 307 301 308 // I get sick.dizzy from the popup expanding from the whole thing... 302 309 animationSource.height = 1; 303 animationSource.width = Math.min(animationSource.width, playbackControlPopup.get Width());310 animationSource.width = Math.min(animationSource.width, playbackControlPopup.getFullBounds().getWidth()); 304 311 305 312 if (y < 0) { … … 309 316 310 317 // Animate the popup 311 PopupManager.getInstance().showPopup( 312 playbackControlPopup, 313 new Point(x, y), 314 fulltrackView, 315 PopupManager.getInstance().new ExpandShrinkAnimator( 316 animationSource, 317 Color.LIGHT_GRAY)); 318 319 PopupReaper.getInstance().initPopupLifetime( 320 playbackControlPopup, 321 PopupManager.getInstance().new ExpandShrinkAnimator( 322 animationSource, 323 Color.LIGHT_GRAY), 324 TrackWidgetCommons.POPUP_LIFETIME); 325 318 playbackControlPopup.getAutoHideTime().setLifetime(TrackWidgetCommons.POPUP_LIFETIME); 319 PopupManager.getInstance().add(playbackControlPopup); 320 playbackControlPopup.show(); 326 321 } else { 327 PopupReaper.getInstance().revivePopup(playbackControlPopup, TrackWidgetCommons.POPUP_LIFETIME);322 playbackControlPopup.show(); 328 323 } 329 324 … … 398 393 fulltrackView.addKeyListener(new KeyListener() { 399 394 400 public void keyPressed(KeyEvent e) { 401 if (!e.isControlDown() && nameLabel != null) { 402 if (nameLabel.onKeyPressed(e, fulltrackView)) { 403 e.consume(); 404 } 405 } 406 } 407 408 public void keyReleased(KeyEvent e) { 409 if (!e.isControlDown() && nameLabel != null) { 410 if (nameLabel.onKeyReleased(e, fulltrackView)) { 411 e.consume(); 412 } 413 } 414 395 public void keyPressed(KeyEvent e) 396 { 397 } 398 399 public void keyReleased(KeyEvent e) 400 { 415 401 // Toggle pitch-track indexing 416 402 if (e.isControlDown() && e.getKeyCode() == KeyEvent.VK_I) { 417 403 setShouldOmitIndexAudio(!shouldOmitIndexAudio()); 418 FrameGraphics.refresh(true);404 DisplayController.requestRefresh(true); 419 405 } 420 406 … … 429 415 else if (e.isControlDown() && e.getKeyCode() == KeyEvent.VK_L) { 430 416 431 Frame current = Display IO.getCurrentFrame();417 Frame current = DisplayController.getCurrentFrame(); 432 418 433 419 if (current != null) { … … 473 459 } 474 460 475 } else if (e.isControlDown() && 476 (e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_RIGHT)) { 477 e.consume(); 478 AudioFrameKeyboardActions.adjustInitationTime(SampledTrack.this, e.getKeyCode() == KeyEvent.VK_LEFT); 479 } else if (e.isControlDown() && 480 (e.getKeyCode() == KeyEvent.VK_UP || e.getKeyCode() == KeyEvent.VK_DOWN)) { 481 e.consume(); 482 AudioFrameKeyboardActions.adjustVerticlePosition(SampledTrack.this, e.getKeyCode() == KeyEvent.VK_UP); 461 } else if (e.isControlDown()) { 462 if (e.getKeyCode() == KeyEvent.VK_LEFT) { 463 e.consume(); 464 ApolloGestureActions.adjustInitiationTime(SampledTrack.this, -ApolloKBMGestureTranslator.TRACK_WIDGET_TIMELINE_ADJUSTMENT); 465 } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) { 466 e.consume(); 467 ApolloGestureActions.adjustInitiationTime(SampledTrack.this, ApolloKBMGestureTranslator.TRACK_WIDGET_TIMELINE_ADJUSTMENT); 468 } else if (e.getKeyCode() == KeyEvent.VK_UP) { 469 e.consume(); 470 ApolloGestureActions.adjustVerticalPosition(SampledTrack.this, -ApolloKBMGestureTranslator.TRACK_WIDGET_VERTICAL_ADJUSTMENT); 471 } else if (e.getKeyCode() == KeyEvent.VK_DOWN) { 472 e.consume(); 473 ApolloGestureActions.adjustVerticalPosition(SampledTrack.this, ApolloKBMGestureTranslator.TRACK_WIDGET_VERTICAL_ADJUSTMENT); 474 } 483 475 } 484 476 … … 490 482 }); 491 483 492 493 494 nameLabel = new EmulatedTextItem(_swingComponent, new Point(10, 20)); 495 nameLabel.setBackgroundColor(Color.WHITE); 484 nameLabel = new EmulatedTextItem("", (new Point(10, 20)).add(getBounds().getTopLeft())); 485 nameLabel.setBackgroundColor(Colour.WHITE); 496 486 497 487 String metaName = getStrippedDataString(TrackWidgetCommons.META_NAME_TAG); … … 616 606 Text source = new Text( 617 607 targetFrame.getNextItemID(), 618 ItemUtils.GetTag(ItemUtils.TAG_IWIDGET) + ":" + formatArgs(args));608 ItemUtils.GetTag(ItemUtils.TAG_IWIDGET) + ":" + Util.formatArgs(args)); 619 609 620 610 source.setParent(targetFrame); … … 685 675 686 676 @Override 687 public InteractiveWidget copy()677 public Widget copy() 688 678 throws InteractiveWidgetNotAvailableException, InteractiveWidgetInitialisationFailedException { 689 679 … … 1119 1109 } 1120 1110 1121 public void onGraphDirty(SampledTrackGraphView graph, Rectangle dirty) { 1111 public void onGraphDirty(SampledTrackGraphView graph, Rectangle dirty) 1112 { 1122 1113 dirty.translate(getX(), getY() - 1); 1123 FrameGraphics.invalidateArea(dirty);1124 FrameGraphics.refresh(true);1114 DisplayController.invalidateArea(SwingConversions.fromSwingRectangle(dirty)); 1115 DisplayController.requestRefresh(true); 1125 1116 } 1126 1117 … … 1131 1122 1132 1123 @Override 1133 protected void onSizeChanged() { 1124 protected void onSizeChanged() 1125 { 1134 1126 super.onSizeChanged(); 1135 1127 // Keep meta as constant as possible for best reults … … 1246 1238 1247 1239 @Override 1248 public void paintInFreeSpace(Graphics g) { 1249 paintInFreeSpace(g, false); 1250 } 1251 1252 public void paintInFreeSpace(Graphics g, boolean isAtFinalPass) { 1240 public void paintInFreeSpace() 1241 { 1242 paintInFreeSpace(false); 1243 } 1244 1245 public void paintInFreeSpace(boolean isAtFinalPass) 1246 { 1247 Graphics g = SwingMiscManager.getIfUsingSwingGraphicsManager().getCurrentSurface(); 1253 1248 1254 1249 if (isLoaded()) { … … 1270 1265 1271 1266 1272 Point containerPoint = Swing Utilities.convertPoint(me.getComponent(),1273 new Point(0,0), Browser._theBrowser.getContentPane());1267 Point containerPoint = SwingConversions.fromSwingPoint(SwingUtilities.convertPoint(me.getComponent(), 1268 new java.awt.Point(0,0), SwingMiscManager.getIfUsingSwingGraphicsManager().getContentPane())); 1274 1269 1275 1270 Shape clipBackUp = g.getClip(); 1276 1271 g.setClip(null); 1277 1272 1278 g.setColor( Color.ORANGE);1273 g.setColor(SwingConversions.toSwingColor(Colour.ORANGE)); 1279 1274 ((Graphics2D)g).setStroke(EditableSampledTrackGraphView.GRAPH_BAR_STROKE); 1280 1275 g.drawLine( … … 1284 1279 containerPoint.y + me.getComponent().getHeight()); 1285 1280 1286 FrameGraphics.invalidateArea(new Rectangle(1281 DisplayController.invalidateArea(new AxisAlignedBoxBounds( 1287 1282 containerPoint.x + me.getX(), 1288 1283 containerPoint.y, … … 1293 1288 g.setClip(clipBackUp); 1294 1289 1295 g.setColor(S EMI_TRANSPARENT_FREESPACE_BACKCOLOR);1290 g.setColor(SwingConversions.toSwingColor(SEMI_TRANSPARENT_FREESPACE_BACKCOLOR)); 1296 1291 g.fillRect(getX(), getY(), getWidth(), getHeight()); 1297 1292 1298 1293 if (isAtFinalPass) { // final pass does not draw the borders... so must manually draw them 1299 g.setColor( Color.BLACK);1300 ((Graphics2D)g).setStroke( FREESPACE_OUTLINING);1294 g.setColor(SwingConversions.toSwingColor(Colour.BLACK)); 1295 ((Graphics2D)g).setStroke(SwingConversions.toSwingStroke(FREESPACE_OUTLINING)); 1301 1296 g.drawRect(getX(), getY(), getWidth(), getHeight()); 1302 1297 } … … 1311 1306 } 1312 1307 1313 super.paintInFreeSpace( g);1308 super.paintInFreeSpace(); 1314 1309 1315 1310 if (isLoaded()) { … … 1318 1313 Rectangle tmpClip = (clipBackUp != null) ? clipBackUp.getBounds() : 1319 1314 new Rectangle(0, 0, 1320 Browser._theBrowser.getContentPane().getWidth(),1321 Browser._theBrowser.getContentPane().getHeight());1322 1323 g.setClip(tmpClip.intersection( getBounds()));1315 SwingMiscManager.getIfUsingSwingGraphicsManager().getContentPane().getWidth(), 1316 SwingMiscManager.getIfUsingSwingGraphicsManager().getContentPane().getHeight()); 1317 1318 g.setClip(tmpClip.intersection(SwingConversions.toSwingRectangle(getBounds()))); 1324 1319 1325 1320 // Draw the name … … 1327 1322 if (name == null) name = "Unnamed"; 1328 1323 1329 g.setFont( TrackWidgetCommons.FREESPACE_TRACKNAME_FONT);1330 g.setColor( TrackWidgetCommons.FREESPACE_TRACKNAME_TEXT_COLOR);1324 g.setFont(SwingMiscManager.getIfUsingSwingFontManager().getInternalFont(TrackWidgetCommons.FREESPACE_TRACKNAME_FONT)); 1325 g.setColor(SwingConversions.toSwingColor(TrackWidgetCommons.FREESPACE_TRACKNAME_TEXT_COLOR)); 1331 1326 1332 1327 // Center track name 1333 FontMetrics fm = g.getFontMetrics( TrackWidgetCommons.FREESPACE_TRACKNAME_FONT);1328 FontMetrics fm = g.getFontMetrics(SwingMiscManager.getIfUsingSwingFontManager().getInternalFont(TrackWidgetCommons.FREESPACE_TRACKNAME_FONT)); 1334 1329 Rectangle2D rect = fm.getStringBounds(name, g); 1335 1330 … … 1349 1344 1350 1345 @Override 1351 public void paint(Graphics g) { 1352 super.paint(g); 1346 public void paintHeavyDutyWidget(Graphics2D g) 1347 { 1348 super.paintHeavyDutyWidget(g); 1353 1349 1354 1350 if (isLoaded() && nameLabel != null) { 1355 nameLabel.paint( g);1351 nameLabel.paint(); 1356 1352 1357 1353 if (shouldOmitIndexAudio()) { … … 1360 1356 -20 : 0; 1361 1357 1362 IconRepository.getIcon("omitindexed.png").paintIcon(1358 /*IconRepository.getIcon("omitindexed.png").paintIcon( 1363 1359 _swingComponent, 1364 1360 g, 1365 1361 getX() + getWidth() - EditableSampledTrackGraphView.LOCK_ICON_CORNER_OFFSET + shiftOffset, 1366 getY() + EditableSampledTrackGraphView.LOCK_ICON_CORNER_OFFSET - 16); 1362 getY() + EditableSampledTrackGraphView.LOCK_ICON_CORNER_OFFSET - 16);*/ 1363 1364 g.drawImage(SwingMiscManager.getIfUsingSwingImageManager().getInternalImage(IconRepository.getIcon("omitindexed.png")), 1365 getX() + getWidth() - EditableSampledTrackGraphView.LOCK_ICON_CORNER_OFFSET + shiftOffset, 1366 getY() + EditableSampledTrackGraphView.LOCK_ICON_CORNER_OFFSET - 16, null); 1367 1367 1368 1368 } … … 1404 1404 boolean inferInitTime = true; 1405 1405 1406 if (A udioFrameMouseActions.isYAxisRestictionOn()) {1406 if (ApolloGestureActions.isYAxisRestictionOn()) { 1407 1407 Mutable.Long ms = getInitiationTimeFromMeta(); 1408 1408 if (ms != null) { … … 1417 1417 } 1418 1418 1419 inferInitTime &= 1420 (AudioFrameMouseActions.isMouseAnchoring() || AudioFrameMouseActions.isMouseStamping()); 1421 1419 // Also must not set initiation time if the frame is simply being displayed 1420 //inferInitTime &= (AudioFrameMouseActions.isMouseAnchoring() || AudioFrameMouseActions.isMouseStamping()); 1421 inferInitTime &= (eventType == ItemParentStateChangedEvent.EVENT_TYPE_ADDED); 1422 1422 1423 if (inferInitTime) 1423 1424 initTime = Mutable.createMutableLong(FrameLayoutDaemon.getInstance().getMSAtX(getX(), parent)); … … 1499 1500 MouseEventRouter.getCurrentMouseEvent().getButton() == MouseEvent.BUTTON2 && 1500 1501 MouseEventRouter.getCurrentMouseEvent() != lastInsertME) { 1501 Frame suspended = Display IO.getCurrentFrame();1502 Frame suspended = DisplayController.getCurrentFrame(); 1502 1503 if (suspended != null) { 1503 1504 FrameLayoutDaemon.getInstance().suspendLayout(suspended, this); … … 1682 1683 1683 1684 // Get border color currently used 1684 Colo r oldC = getSource().getBorderColor();1685 1686 Colo r newC = TrackWidgetCommons.getBorderColor(1685 Colour oldC = getSource().getBorderColor(); 1686 1687 Colour newC = TrackWidgetCommons.getBorderColor( 1687 1688 SoundDesk.getInstance().isSolo(trackMix.getChannelID()), 1688 1689 trackMix.isMuted()); … … 1772 1773 // Build the new neighbouring widget 1773 1774 Frame target = getParentFrame(); 1774 if (target == null) target = Display IO.getCurrentFrame();1775 if (target == null) target = DisplayController.getCurrentFrame(); 1775 1776 1776 1777 // Determine init time … … 1811 1812 trackMix); 1812 1813 1813 FrameMouseActions.pickup(extractedTrack.getItems());1814 StandardGestureActions.pickup(extractedTrack.getItems()); 1814 1815 1815 1816 } … … 1840 1841 trackModel, 1841 1842 pfname, 1842 _swingComponent.getBounds(),1843 SwingConversions.fromSwingRectangle(_swingComponent.getBounds()), 1843 1844 trackMix); 1844 1845 … … 1846 1847 1847 1848 // Get rid of all popups 1848 PopupManager.getInstance().hideAuto hidePopups();1849 PopupManager.getInstance().hideAutoHidePopups(); 1849 1850 1850 1851 int start = trackModel.getSelectionStart(); … … 1859 1860 ExpandedTrackManager.getInstance().expandSingleTrack( 1860 1861 trackModel, 1861 _swingComponent.getBounds(),1862 SwingConversions.fromSwingRectangle(_swingComponent.getBounds()), 1862 1863 trackMix, 1863 1864 pfname, … … 1882 1883 * 1883 1884 */ 1884 private class PlaybackPopup extends PlaybackControlPopup implements Observer { 1885 1886 private static final long serialVersionUID = 1L; 1887 1888 public PlaybackPopup() { 1885 private class PlaybackPopup extends PlaybackControlPopup implements Observer 1886 { 1887 public PlaybackPopup() 1888 { 1889 1889 miscButton.setActionCommand("expand"); 1890 miscButton.setIcon(IconRepository.getIcon("expand.png"));1890 SwingMiscManager.setJButtonIcon(miscButton, IconRepository.getIcon("expand.png")); 1891 1891 miscButton.setToolTipText("Expand"); 1892 1893 1892 } 1894 1893 1895 1894 @Override 1896 public void onHide() { 1897 super.onHide(); 1898 1895 public void onHide() 1896 { 1899 1897 // Listen for volume or mute changed events 1900 1898 trackMix.removeObserver(this); … … 1905 1903 1906 1904 @Override 1907 public void onShow() {1908 super.onShow();1905 public void onShow() 1906 { 1909 1907 // Listen for volume or mute changed events 1910 1908 trackMix.addObserver(this); … … 2016 2014 } 2017 2015 2018 public Subject getObservedSubject() { 2016 public Subject getObservedSubject() 2017 { 2019 2018 return null; 2020 2019 } 2021 2020 2022 public void setObservedSubject(Subject parent) { 2021 public void setObservedSubject(Subject parent) 2022 { 2023 2023 } 2024 2024 … … 2026 2026 * Receives events from the track model OR from the observed track sequence. 2027 2027 */ 2028 public void modelChanged(Subject source, SubjectChangedEvent event) {2029 2028 public void modelChanged(Subject source, SubjectChangedEvent event) 2029 { 2030 2030 // Synch GUI with track state 2031 2031 switch (event.getID()) { … … 2049 2049 stopButton.setEnabled(true); 2050 2050 rewindButton.setEnabled(false); 2051 playPauseButton.setIcon(IconRepository.getIcon("pause.png"));2051 SwingMiscManager.setJButtonIcon(playPauseButton, IconRepository.getIcon("pause.png")); 2052 2052 2053 2053 invalidateStateIcons(); … … 2063 2063 rewindButton.setEnabled(true); 2064 2064 stopButton.setEnabled(false); 2065 playPauseButton.setIcon(IconRepository.getIcon("play.png"));2065 SwingMiscManager.setJButtonIcon(playPauseButton, IconRepository.getIcon("play.png")); 2066 2066 2067 2067 // Note: … … 2109 2109 2110 2110 @Override 2111 protected void volumeChanged() { 2111 protected void volumeChanged() 2112 { 2112 2113 trackMix.setVolume(((float)volumeSlider.getValue()) / 100.0f); 2113 2114 } 2114 2115 2115 2116 @Override 2116 protected void muteChanged() { 2117 protected void muteChanged() 2118 { 2117 2119 trackMix.setMuted(muteButton.isSelected()); 2118 2120 } 2119 2121 2120 2122 @Override 2121 protected void soloChanged() { 2123 protected void soloChanged() 2124 { 2122 2125 SoundDesk.getInstance().setSoloIDPrefix(soloButton.isSelected() ? 2123 2126 trackMix.getChannelID() : null 2124 2127 ); 2125 2128 } 2126 2127 2129 } 2128 2130 2129 2131 @Override 2130 public boolean isWidgetEdgeThicknessAdjustable() { 2132 public boolean isWidgetEdgeThicknessAdjustable() 2133 { 2131 2134 return false; 2132 2135 } 2133 2134 2135 2136 2136 } -
trunk/src/org/apollo/widgets/SearchRecorder.java
r355 r1102 30 30 import org.apollo.util.ApolloSystemLog; 31 31 import org.expeditee.actions.Actions; 32 import org.expeditee.gui.DisplayIO; 32 import org.expeditee.gio.swing.SwingMiscManager; 33 import org.expeditee.gui.DisplayController; 33 34 import org.expeditee.gui.Frame; 34 35 import org.expeditee.items.ItemParentStateChangedEvent; 35 36 import org.expeditee.items.Text; 36 import org.expeditee.items.widgets. InteractiveWidget;37 38 public class SearchRecorder extends InteractiveWidget37 import org.expeditee.items.widgets.SwingWidget; 38 39 public class SearchRecorder extends SwingWidget 39 40 implements ActionListener, Observer { 40 41 … … 68 69 // Create gui layout 69 70 recordButton = new JButton(); 70 recordButton.setIcon(IconRepository.getIcon("searchmel.png"));71 SwingMiscManager.setJButtonIcon(recordButton, IconRepository.getIcon("searchmel.png")); 71 72 recordButton.setToolTipText("Search for audio from live recording"); 72 73 recordButton.addActionListener(this); … … 74 75 75 76 commitButton = new JButton(); 76 commitButton.setIcon(IconRepository.getIcon("commitquery.png"));77 SwingMiscManager.setJButtonIcon(commitButton, IconRepository.getIcon("commitquery.png")); 77 78 commitButton.addActionListener(this); 78 79 commitButton.setToolTipText("GO!"); … … 82 83 cancelButton = new JButton(); 83 84 cancelButton.setToolTipText("Cancel"); 84 cancelButton.setIcon(IconRepository.getIcon("cancel.png"));85 SwingMiscManager.setJButtonIcon(cancelButton, IconRepository.getIcon("cancel.png")); 85 86 cancelButton.addActionListener(this); 86 87 cancelButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE)); … … 384 385 if (hasExplicityStopped) { 385 386 386 Frame sourceFrame = Display IO.getCurrentFrame();387 Frame sourceFrame = DisplayController.getCurrentFrame(); 387 388 388 389 if (sourceFrame != null && -
trunk/src/org/apollo/widgets/TrackWidgetCommons.java
r315 r1102 1 1 package org.apollo.widgets; 2 2 3 import java.awt.Color;4 import java.awt.Font;3 import org.expeditee.core.Colour; 4 import org.expeditee.core.Font; 5 5 6 6 public final class TrackWidgetCommons { 7 private TrackWidgetCommons() { 7 8 /** Static-only class. */ 9 private TrackWidgetCommons() 10 { 8 11 } 9 12 … … 17 20 public static final int CACHE_DEPTH = 1; 18 21 19 public static final Colo r FREESPACE_TRACKNAME_TEXT_COLOR = Color.WHITE;20 public static final Font FREESPACE_TRACKNAME_FONT = new Font("Arial", Font. BOLD, 20);22 public static final Colour FREESPACE_TRACKNAME_TEXT_COLOR = Colour.WHITE; 23 public static final Font FREESPACE_TRACKNAME_FONT = new Font("Arial", Font.Style.BOLD, 20); 21 24 22 25 public static final int POPUP_LIFETIME = 1500; 23 26 24 public static final Colo r STANDARD_TRACK_EDGE_COLOR = Color.BLACK;25 public static final Colo r MUTED_TRACK_EDGE_COLOR = Color.GRAY;26 public static final Colo r SOLO_TRACK_EDGE_COLOR = Color.RED;27 public static final Colo r MUTED_SOLO_TRACK_EDGE_COLOR = new Color(255, 168, 168);27 public static final Colour STANDARD_TRACK_EDGE_COLOR = Colour.BLACK; 28 public static final Colour MUTED_TRACK_EDGE_COLOR = Colour.GREY; 29 public static final Colour SOLO_TRACK_EDGE_COLOR = Colour.RED; 30 public static final Colour MUTED_SOLO_TRACK_EDGE_COLOR = Colour.FromRGB255(255, 168, 168); 28 31 29 32 public static final float STOPPED_TRACK_EDGE_THICKNESS = 1.0f; … … 31 34 32 35 33 public static Colo r getBorderColor(boolean isSolo, boolean isMuted) {36 public static Colour getBorderColor(boolean isSolo, boolean isMuted) { 34 37 35 Colo r newC = null;38 Colour newC = null; 36 39 37 40 if (isSolo && isMuted) { -
trunk/src/org/expeditee/actions/Actions.java
r990 r1102 19 19 package org.expeditee.actions; 20 20 21 import java.awt.GraphicsEnvironment;22 import java.io.Serializable;23 21 import java.lang.reflect.Constructor; 24 22 import java.lang.reflect.Method; … … 26 24 import java.rmi.UnexpectedException; 27 25 import java.util.ArrayList; 28 import java.util.Arrays;29 26 import java.util.Collection; 30 27 import java.util.Comparator; … … 35 32 36 33 import org.expeditee.agents.Agent; 37 import org.expeditee.gui.DisplayIO; 34 import org.expeditee.gio.EcosystemManager; 35 import org.expeditee.gui.DisplayController; 38 36 import org.expeditee.gui.Frame; 39 import org.expeditee.gui.FrameGraphics;40 37 import org.expeditee.gui.FrameIO; 41 38 import org.expeditee.gui.FrameUtils; … … 217 214 * actions. 218 215 */ 219 public static Collection<String> Init() {220 221 Collection<String> warnings = new LinkedList<String>();216 public static List<String> Init() { 217 218 List<String> warnings = new LinkedList<String>(); 222 219 List<Class<?>> classes; 223 220 … … 436 433 // loose changes 437 434 if (firstCanditate.getDeclaringClass().getName().equals(NAVIGATIONS_CLASS)) { 438 FrameIO.SaveFrame(Display IO.getCurrentFrame());435 FrameIO.SaveFrame(DisplayController.getCurrentFrame()); 439 436 } 440 437 final List<Method> canditates = new LinkedList<Method>(); … … 825 822 + nameWithCorrectCase + "'"); 826 823 } 827 FrameGraphics.refresh(false);824 DisplayController.requestRefresh(false); 828 825 } 829 826 … … 1031 1028 private static void initFonts() { 1032 1029 if (_Fonts.size() == 0) { 1033 String[] availableFonts = GraphicsEnvironment 1034 .getLocalGraphicsEnvironment() 1035 .getAvailableFontFamilyNames(); 1030 String[] availableFonts = EcosystemManager.getFontManager().getRegisteredFontFamilies(); 1036 1031 for (String s : availableFonts) { 1037 1032 _Fonts.put(s.toLowerCase(), s); -
trunk/src/org/expeditee/actions/Debug.java
r919 r1102 21 21 import java.util.List; 22 22 23 import org.expeditee.gui.Display IO;23 import org.expeditee.gui.DisplayController; 24 24 import org.expeditee.items.Constraint; 25 25 import org.expeditee.items.Item; … … 38 38 */ 39 39 public static void ShowConstraints() { 40 List<Item> items = Display IO.getCurrentFrame().getItems();40 List<Item> items = DisplayController.getCurrentFrame().getItems(); 41 41 42 42 for (Item i : items) -
trunk/src/org/expeditee/actions/ExploratorySearchActions.java
r919 r1102 19 19 package org.expeditee.actions; 20 20 21 import org.expeditee.core.Point; 22 import org.expeditee.gio.EcosystemManager; 23 import org.expeditee.gio.gesture.StandardGestureActions; 21 24 import org.expeditee.gui.Browser; 22 import org.expeditee.gui.Display IO;25 import org.expeditee.gui.DisplayController; 23 26 import org.expeditee.gui.Frame; 24 27 import org.expeditee.gui.FrameIO; 25 import org.expeditee.gui.FrameKeyboardActions;26 import org.expeditee.gui.FrameMouseActions;27 28 import org.expeditee.gui.FreeItems; 28 29 import org.expeditee.items.Item; … … 59 60 } 60 61 61 Text linkToBrowserSession = Display IO.getCurrentFrame().addText(FrameMouseActions.getX(), FrameMouseActions.getY(), " - Web Browser Session", null);62 linkToBrowserSession.setParent(Display IO.getCurrentFrame());63 FrameKeyboardActions.AddDate(linkToBrowserSession);64 FrameMouseActions.pickup(linkToBrowserSession);62 Text linkToBrowserSession = DisplayController.getCurrentFrame().addText(DisplayController.getMouseX(), DisplayController.getMouseY(), " - Web Browser Session", null); 63 linkToBrowserSession.setParent(DisplayController.getCurrentFrame()); 64 Text.AddDate(linkToBrowserSession); 65 StandardGestureActions.pickup(linkToBrowserSession); 65 66 66 67 // Create new frame … … 75 76 // Add web browser active overlay and @old 76 77 Text t = (Text) frame.addText(-150, 50, "@ao: 2", null, "overlayset2"); 77 t.setAnchorRight(-100 .0f);78 t.setAnchorTop(50 .0f);78 t.setAnchorRight(-100); 79 t.setAnchorTop(50); 79 80 t = (Text) frame.addText(-150, 50, "@old", null); 80 81 t.setFamily("Roboto Condensed"); … … 84 85 t.setJustification(Justification.right); 85 86 t.setLinkMark(false); 86 t.setAnchorLeft(9 .0f);87 t.setAnchorBottom(114 .0f);87 t.setAnchorLeft(9); 88 t.setAnchorBottom(114); 88 89 89 90 Text wt; … … 101 102 + ("--anchorLeft " + (lm + ExploratorySearchSettings.BROWSER_HORZ_OFFSET) + " --anchorRight " + rm + " --anchorTop " 102 103 + (ExploratorySearchSettings.BROWSER_VERT_OFFSET + tm) + " --anchorBottom " + bm + " ") 103 + ( Browser._theBrowser.getContentPane().getWidth() - ExploratorySearchSettings.BROWSER_HORZ_OFFSET - lm - rm) + " "104 + ( Browser._theBrowser.getContentPane().getHeight() - ExploratorySearchSettings.BROWSER_VERT_OFFSET - tm - bm) + " : " + url, null);104 + (EcosystemManager.getGraphicsManager().getWindowSize().getWidth() - ExploratorySearchSettings.BROWSER_HORZ_OFFSET - lm - rm) + " " 105 + (EcosystemManager.getGraphicsManager().getWindowSize().getHeight() - ExploratorySearchSettings.BROWSER_VERT_OFFSET - tm - bm) + " : " + url, null); 105 106 } else { 106 107 wt = frame.addText(ExploratorySearchSettings.BROWSER_HORZ_OFFSET + lm, ExploratorySearchSettings.BROWSER_VERT_OFFSET + tm, … … 122 123 // Replace any text item on cursor with link to a new mindmap 123 124 FreeItems.getInstance().clear(); 124 Text text = DisplayIO.getCurrentFrame().addText(FrameMouseActions.getX(), FrameMouseActions.getY(), " - Mindmap Session", null); 125 text.setParent(DisplayIO.getCurrentFrame()); 126 FrameKeyboardActions.AddDate(text); 127 FrameMouseActions.pickup(text); 125 Point cursorPos = DisplayController.getMousePosition(); 126 Text text = DisplayController.getCurrentFrame().addText(cursorPos.getX(), cursorPos.getY(), " - Mindmap Session", null); 127 text.setParent(DisplayController.getCurrentFrame()); 128 Text.AddDate(text); 129 StandardGestureActions.pickup(text); 128 130 Frame frame = FrameIO.CreateNewFrame(text); 129 131 text.setLink("" + frame.getNumber()); … … 132 134 frame.removeAllItems(frame.getItems()); 133 135 Text t = (Text) frame.addText(-150, 50, "@ao: 2", null, "overlayset3"); 134 t.setAnchorLeft(-150 .0f);135 t.setAnchorTop(50 .0f);136 t.setAnchorLeft(-150); 137 t.setAnchorTop(50); 136 138 t = (Text) frame.addText(-150, 50, "@old", null); 137 139 t.setFamily("Roboto Condensed"); … … 141 143 t.setJustification(Justification.right); 142 144 t.setLinkMark(false); 143 t.setAnchorLeft(9 .0f);144 t.setAnchorBottom(114 .0f);145 t.setAnchorLeft(9); 146 t.setAnchorBottom(114); 145 147 146 148 FrameIO.SaveFrame(frame); … … 168 170 } 169 171 170 Text linkToBrowserSession = DisplayIO.getCurrentFrame().addText(FrameMouseActions.getX(), FrameMouseActions.getY(), url, null); 171 linkToBrowserSession.setParent(DisplayIO.getCurrentFrame()); 172 FrameMouseActions.pickup(linkToBrowserSession); 172 Point cursorPos = DisplayController.getMousePosition(); 173 Text linkToBrowserSession = DisplayController.getCurrentFrame().addText(cursorPos.getX(), cursorPos.getY(), url, null); 174 linkToBrowserSession.setParent(DisplayController.getCurrentFrame()); 175 StandardGestureActions.pickup(linkToBrowserSession); 173 176 174 177 // Create new frame … … 183 186 // Add web browser active overlay and @old 184 187 Text t = (Text) frame.addText(-150, 50, "@ao: 2", null, "overlayset2"); 185 t.setAnchorLeft(-150 .0f);186 t.setAnchorTop(50 .0f);188 t.setAnchorLeft(-150); 189 t.setAnchorTop(50); 187 190 t = (Text) frame.addText(-150, 50, "@old", null); 188 191 t.setFamily("Roboto Condensed"); … … 192 195 t.setJustification(Justification.right); 193 196 t.setLinkMark(false); 194 t.setAnchorLeft(9 .0f);195 t.setAnchorBottom(114 .0f);197 t.setAnchorLeft(9); 198 t.setAnchorBottom(114); 196 199 197 200 Text wt; … … 209 212 + ("--anchorLeft " + (lm + ExploratorySearchSettings.BROWSER_HORZ_OFFSET) + " --anchorRight " + rm + " --anchorTop " 210 213 + (ExploratorySearchSettings.BROWSER_VERT_OFFSET + tm) + " --anchorBottom " + bm + " ") 211 + ( Browser._theBrowser.getContentPane().getWidth() - ExploratorySearchSettings.BROWSER_HORZ_OFFSET - lm - rm) + " "212 + ( Browser._theBrowser.getContentPane().getHeight() - ExploratorySearchSettings.BROWSER_VERT_OFFSET - tm - bm) + " : " + url, null);214 + (EcosystemManager.getGraphicsManager().getWindowSize().getWidth() - ExploratorySearchSettings.BROWSER_HORZ_OFFSET - lm - rm) + " " 215 + (EcosystemManager.getGraphicsManager().getWindowSize().getHeight() - ExploratorySearchSettings.BROWSER_VERT_OFFSET - tm - bm) + " : " + url, null); 213 216 } else { 214 217 wt = frame.addText(ExploratorySearchSettings.BROWSER_HORZ_OFFSET + lm, ExploratorySearchSettings.BROWSER_VERT_OFFSET + tm, -
trunk/src/org/expeditee/actions/GreenstoneActions.java
r919 r1102 19 19 package org.expeditee.actions; 20 20 21 import java.awt.Color;22 21 import java.lang.reflect.InvocationTargetException; 23 22 import java.lang.reflect.Method; … … 25 24 26 25 import org.expeditee.agents.SearchGreenstone; 26 import org.expeditee.core.Colour; 27 27 import org.expeditee.greenstone.ResultDocument; 28 28 import org.expeditee.gui.AttributeValuePair; … … 134 134 } 135 135 } 136 MessageBay.displayMessage("Feedback complete", null, Colo r.green136 MessageBay.displayMessage("Feedback complete", null, Colour.GREEN 137 137 .darker(), true, null); 138 138 } -
trunk/src/org/expeditee/actions/Help.java
r919 r1102 25 25 import java.util.List; 26 26 27 import org.expeditee.gui.DisplayIO; 27 import org.expeditee.gio.EcosystemManager; 28 import org.expeditee.gui.DisplayController; 28 29 import org.expeditee.gui.Frame; 29 import org.expeditee.gui.FrameMouseActions;30 30 import org.expeditee.items.Item; 31 31 import org.expeditee.items.Text; … … 77 77 }); 78 78 79 Frame current = Display IO.getCurrentFrame();80 float x = FrameMouseActions.MouseX;81 float y = FrameMouseActions.MouseY;79 Frame current = DisplayController.getCurrentFrame(); 80 float x = DisplayController.getFloatMouseX(); 81 float y = DisplayController.getFloatMouseY(); 82 82 83 83 // Do case sensitive comparison -
trunk/src/org/expeditee/actions/IDE.java
r919 r1102 19 19 package org.expeditee.actions; 20 20 21 import java.awt.Color;22 import java.io.BufferedReader;23 21 import java.io.File; 24 import java.io.InputStreamReader;25 22 26 23 import org.expeditee.agents.WriteTree; 27 import org.expeditee.gui.DisplayIO; 24 import org.expeditee.core.Colour; 25 import org.expeditee.gui.DisplayController; 28 26 import org.expeditee.gui.Frame; 29 27 import org.expeditee.gui.FrameIO; … … 37 35 int exitVal = 0; // default's to status OK 38 36 39 Frame source = Display IO.getCurrentFrame();37 Frame source = DisplayController.getCurrentFrame(); 40 38 String title = source.getTitleItem().getText(); 41 39 String[] tokens = title.split("\\s+"); … … 72 70 } 73 71 else { 74 MessageBay.displayMessage("Compiled " + fileName, Colo r.darkGray);72 MessageBay.displayMessage("Compiled " + fileName, Colour.DARK_GREY); 75 73 } 76 74 } catch (Exception e) { … … 101 99 102 100 public static void RunClass() { 103 Frame source = Display IO.getCurrentFrame();101 Frame source = DisplayController.getCurrentFrame(); 104 102 String className = getClassName(source); 105 103 try { -
trunk/src/org/expeditee/actions/Javascript.java
r919 r1102 19 19 package org.expeditee.actions; 20 20 21 import java.awt.Color;22 21 import java.util.LinkedList; 23 22 import java.util.List; … … 26 25 import org.expeditee.agents.Agent; 27 26 import org.expeditee.agents.DefaultAgent; 28 import org.expeditee.gui.DisplayIO; 27 import org.expeditee.core.Colour; 28 import org.expeditee.gui.DisplayController; 29 29 import org.expeditee.gui.Frame; 30 import org.expeditee.gui.FrameGraphics;31 30 import org.expeditee.gui.FrameIO; 32 31 import org.expeditee.gui.MessageBay; … … 75 74 private static int _stepPause = -1; 76 75 77 private static Colo r _stepColor;76 private static Colour _stepColor; 78 77 79 78 private static boolean _nextStatement; … … 93 92 //Have changed parameters, so it takes an Item, not just a Text item. 94 93 private static void RunJavascriptFrame(Frame frame, Item current, 95 boolean acceptKeyboardInput, boolean step, int pause, Colo r color) {94 boolean acceptKeyboardInput, boolean step, int pause, Colour color) { 96 95 try { 97 96 if (current != null) { … … 101 100 */ 102 101 // DisplayIO.addToBack(current.getParent()); 103 Display IO.addToBack(DisplayIO.getCurrentFrame());102 DisplayController.addToBack(DisplayController.getCurrentFrame()); 104 103 } else { 105 104 /* TODO we should not have to pass an item just to run a frame! */ … … 108 107 } 109 108 110 _stepColor = color == null ? Colo r.green: color;111 _stepColor = new Colo r(_stepColor.getRed(), _stepColor.getGreen(),112 _stepColor.getBlue(), 50);109 _stepColor = color == null ? Colour.GREEN : color; 110 _stepColor = new Colour(_stepColor.getRed(), _stepColor.getGreen(), 111 _stepColor.getBlue(), Colour.FromComponent255(50)); 113 112 _stepPause = pause; 114 113 _step = step; … … 168 167 FrameUtils.DisplayFrame(item.getParent().getName(), true, true); 169 168 item.setHighlightMode(HighlightMode.Normal); 170 item.setHighlightColor(Colo r.CYAN);169 item.setHighlightColor(Colour.CYAN); 171 170 FrameIO.SaveFrame(item.getParent()); 172 171 } … … 192 191 193 192 if (_step) { 194 if (child != Display IO.getCurrentFrame()) {195 Display IO.setCurrentFrame(child, true);196 } 197 Display IO.addToBack(child);193 if (child != DisplayController.getCurrentFrame()) { 194 DisplayController.setCurrentFrame(child, true); 195 } 196 DisplayController.addToBack(child); 198 197 } 199 198 … … 216 215 AgentStats.ItemExecuted(); 217 216 try { 218 Colo r oldColor = item.getBackgroundColor();217 Colour oldColor = item.getBackgroundColor(); 219 218 if (_step) { 220 219 pause(item); … … 226 225 } else { 227 226 item.setHighlightMode(Item.HighlightMode.None); 227 item.setHighlightColorToDefault(); 228 228 } 229 229 } … … 233 233 && lastItemStatus != Status.FalseIf) { 234 234 if (_step) { 235 Display IO.removeFromBack();235 DisplayController.removeFromBack(); 236 236 } 237 237 return lastItemStatus; … … 257 257 258 258 if (_step) { 259 Display IO.removeFromBack();260 if (Display IO.getCurrentFrame() != current.getParent())261 Display IO.setCurrentFrame(current.getParent(), true);259 DisplayController.removeFromBack(); 260 if (DisplayController.getCurrentFrame() != current.getParent()) 261 DisplayController.setCurrentFrame(current.getParent(), true); 262 262 } 263 263 … … 276 276 return; 277 277 278 Colo r oldColor = item.getBackgroundColor();278 Colour oldColor = item.getBackgroundColor(); 279 279 item.setBackgroundColor(_stepColor); 280 280 item.setHighlightMode(Item.HighlightMode.None); 281 item.setHighlightColorToDefault(); 281 282 282 283 // Make sure we are on the frame with this item 283 284 Frame parent = item.getParentOrCurrentFrame(); 284 if (!parent.equals(Display IO.getCurrentFrame())) {285 Display IO.setCurrentFrame(parent, true);286 } 287 288 FrameGraphics.Repaint();285 if (!parent.equals(DisplayController.getCurrentFrame())) { 286 DisplayController.setCurrentFrame(parent, true); 287 } 288 289 DisplayController.requestRefresh(true); 289 290 290 291 int timeRemaining; … … 297 298 if (_stop) { 298 299 item.setBackgroundColor(oldColor); 299 item.setHighlightMode (HighlightMode.Normal, _stepColor);300 item.setHighlightModeAndColour(HighlightMode.Normal, _stepColor); 300 301 throw new Exception("Program terminated"); 301 302 } … … 388 389 _programsRunning++; 389 390 AgentStats.reset(); 390 MessageBay.displayMessage("Running Javascript Program ...", Colo r.BLUE);391 MessageBay.displayMessage("Running Javascript Program ...", Colour.BLUE); 391 392 } 392 393 -
trunk/src/org/expeditee/actions/Javascript2.java
r1080 r1102 19 19 package org.expeditee.actions; 20 20 21 import java.awt.Color;22 import java.util.Collection;23 import java.util.LinkedList;24 import java.util.List;25 26 import javax.script.Bindings;27 21 import javax.script.Invocable; 28 import javax.script.ScriptContext;29 import javax.script.ScriptEngine;30 import javax.script.ScriptEngineManager;31 import javax.script.ScriptException;32 import javax.script.SimpleScriptContext;33 22 34 23 import org.expeditee.gui.Frame; 35 import org.expeditee.gui.FrameIO;36 import org.expeditee.gui.FrameUtils;37 24 import org.expeditee.gui.MessageBay; 38 import org.expeditee.io.flowlayout.XGroupItem;39 25 import org.expeditee.items.Item; 40 import org.expeditee.items.ItemUtils;41 import org.expeditee.items.Text;42 26 43 27 /** -
trunk/src/org/expeditee/actions/JfxBrowserActions.java
r919 r1102 22 22 import java.io.InputStreamReader; 23 23 import java.net.HttpURLConnection; 24 import java.net.MalformedURLException;25 import java.net.URI;26 import java.net.URISyntaxException;27 24 import java.net.URL; 28 25 import java.net.URLEncoder; 29 26 import java.util.ArrayList; 30 27 31 import org.expeditee.gui.Browser; 32 import org.expeditee.gui.DisplayIO; 28 import org.expeditee.gio.EcosystemManager; 29 import org.expeditee.gio.gesture.StandardGestureActions; 30 import org.expeditee.gui.DisplayController; 33 31 import org.expeditee.gui.Frame; 34 import org.expeditee.gui.FrameGraphics;35 32 import org.expeditee.gui.FrameIO; 36 import org.expeditee.gui.FrameMouseActions;37 33 import org.expeditee.gui.FrameUtils; 38 34 import org.expeditee.gui.FreeItems; … … 42 38 import org.expeditee.items.Picture; 43 39 import org.expeditee.items.Text; 44 import org.expeditee.items.widgets. InteractiveWidget;40 import org.expeditee.items.widgets.Widget; 45 41 import org.expeditee.items.widgets.JfxBrowser; 46 import org.expeditee.settings.exploratorysearch.ExploratorySearchSettings;47 42 import org.expeditee.settings.network.NetworkSettings; 48 43 import org.json.simple.JSONObject; … … 83 78 FreeItems.getInstance().clear(); // remove url text from cursor 84 79 85 wt.setParent(Display IO.getCurrentFrame()); // set parent of text source for InteractiveWidget.createWidget()86 wt.setXY( FrameMouseActions.getX(), FrameMouseActions.getY());80 wt.setParent(DisplayController.getCurrentFrame()); // set parent of text source for InteractiveWidget.createWidget() 81 wt.setXY(DisplayController.getMouseX(), DisplayController.getMouseY()); 87 82 88 83 // create widget from text item 89 JfxBrowser browser = (JfxBrowser) InteractiveWidget.createWidget(wt);84 JfxBrowser browser = (JfxBrowser) Widget.createWidget(wt); 90 85 91 FrameMouseActions.pickup(browser.getItems()); // attach browser widget to mouse86 StandardGestureActions.pickup(browser.getItems()); // attach browser widget to mouse 92 87 } 93 88 … … 109 104 // If no text with url is passed to action create a new text item with http://www.waikato.ac.nz for a default url 110 105 if(!FreeItems.textOnlyAttachedToCursor()) { 111 text = Display IO.getCurrentFrame().addText(FrameMouseActions.getX(), FrameMouseActions.getY(),106 text = DisplayController.getCurrentFrame().addText(DisplayController.getMouseX(), DisplayController.getMouseY(), 112 107 NetworkSettings.HomePage.get(), null); 113 text.setParent(Display IO.getCurrentFrame()); // set parent of text source for InteractiveWidget.createWidget()114 FrameMouseActions.pickup(text); // Attach new text link to cursor108 text.setParent(DisplayController.getCurrentFrame()); // set parent of text source for InteractiveWidget.createWidget() 109 StandardGestureActions.pickup(text); // Attach new text link to cursor 115 110 } 116 111 … … 123 118 Text wt = frame.addText(0, 0, "@iw: org.expeditee.items.widgets.JfxBrowser " 124 119 + ("--anchorLeft 0 --anchorRight 0 --anchorTop 0 --anchorBottom 0 ") 125 + Browser._theBrowser.getContentPane().getWidth() + " " + Browser._theBrowser.getContentPane().getHeight()120 + EcosystemManager.getGraphicsManager().getWindowSize().getWidth() + " " + EcosystemManager.getGraphicsManager().getWindowSize().getHeight() 126 121 + " : " + text.getText(), null); 127 122 128 InteractiveWidget.createWidget(wt);123 Widget.createWidget(wt); 129 124 130 125 FrameIO.SaveFrame(frame); // save frame to disk … … 179 174 180 175 // Create widget via text annotation 181 frame.addText(10, 10, "@iw: org.expeditee.items.widgets.JfxBrowser " + (int) ( FrameGraphics.getMaxFrameSize().getWidth() * 0.9) + " "182 + (int) ( FrameGraphics.getMaxFrameSize().getHeight() * 0.9) + " : " + url, null);176 frame.addText(10, 10, "@iw: org.expeditee.items.widgets.JfxBrowser " + (int) (DisplayController.getFramePaintArea().getWidth() * 0.9) + " " 177 + (int) (DisplayController.getFramePaintArea().getHeight() * 0.9) + " : " + url, null); 183 178 184 179 FrameIO.SaveFrame(frame); … … 294 289 295 290 if (!picSource.equals("")) { 296 pic = WebParser.getImageFromUrl(picSource, null, Display IO.getCurrentFrame(), 0, 0, 50, null, null,291 pic = WebParser.getImageFromUrl(picSource, null, DisplayController.getCurrentFrame(), 0, 0, 50, null, null, 297 292 null, null, null, 0, 0); 298 293 items.add(pic); … … 300 295 } 301 296 302 titleItem.setPosition( FrameMouseActions.getPosition());297 titleItem.setPosition(DisplayController.getMousePosition()); 303 298 mainTextItem.setPosition(titleItem.getX(), titleItem.getY() + titleItem.getBoundsHeight()); 304 299 sourceItem.setPosition(mainTextItem.getX(), mainTextItem.getY() + mainTextItem.getBoundsHeight()); … … 313 308 items.add(sourceItem); 314 309 items.add(ddgLink); 315 FrameMouseActions.pickup(items);310 StandardGestureActions.pickup(items); 316 311 } catch (IOException e) { 317 312 MessageBay.displayMessage("Problem loading results"); -
trunk/src/org/expeditee/actions/Mail.java
r919 r1102 19 19 package org.expeditee.actions; 20 20 21 import java.awt.Color;22 21 import java.util.Collection; 23 22 … … 25 24 26 25 import org.expeditee.agents.mail.MailSession; 26 import org.expeditee.core.Colour; 27 import org.expeditee.gio.EcosystemManager; 28 import org.expeditee.gio.gesture.StandardGestureActions; 27 29 import org.expeditee.gui.AttributeValuePair; 28 import org.expeditee.gui.Display IO;30 import org.expeditee.gui.DisplayController; 29 31 import org.expeditee.gui.Frame; 30 import org.expeditee.gui.FrameKeyboardActions;31 import org.expeditee.gui.FrameMouseActions;32 32 import org.expeditee.gui.MessageBay; 33 33 import org.expeditee.items.Item; … … 116 116 public static Text getMailByID(int messageNo) { 117 117 Text mailItem = MailSession.getInstance().getMail( 118 Display IO.getCurrentFrame(), FrameMouseActions.getPosition(),118 DisplayController.getCurrentFrame(), DisplayController.getMousePosition(), 119 119 messageNo - 1); 120 120 // MessageBay.displayMessage(mailItems.size() + " messages read", … … 139 139 int noOfMessages) { 140 140 Collection<Text> mailItems = MailSession.getInstance().getMail(flag, 141 isPresent, Display IO.getCurrentFrame(),142 FrameMouseActions.getPosition(), noOfMessages);141 isPresent, DisplayController.getCurrentFrame(), 142 DisplayController.getMousePosition(), noOfMessages); 143 143 // MessageBay.displayMessage(mailItems.size() + " messages read", 144 144 // Color.green); … … 187 187 188 188 reply.setActions(null); 189 FrameMouseActions.tdfc(reply);190 191 Frame replyFrame = Display IO.getCurrentFrame();189 StandardGestureActions.tdfc(reply); 190 191 Frame replyFrame = DisplayController.getCurrentFrame(); 192 192 String titleText = frame.getTitle(); 193 193 // Add Re on the end if it is not already there … … 197 197 } 198 198 replyFrame.setTitle(titleText); 199 FrameKeyboardActions.Drop(null, false);199 StandardGestureActions.Drop(null, false); 200 200 201 201 // Add a link to the original message 202 202 Text original = replyFrame.createNewText("@original"); 203 original.setPosition( FrameMouseActions.getPosition());203 original.setPosition(DisplayController.getMousePosition()); 204 204 original.setLink(frame.getName()); 205 FrameKeyboardActions.Drop(original, false);205 StandardGestureActions.Drop(original, false); 206 206 207 207 Text to = replyFrame.createNewText("@to: " + fromAddress); 208 to.setPosition( FrameMouseActions.getPosition());208 to.setPosition(DisplayController.getMousePosition()); 209 209 to.addAction("MailTree"); 210 FrameKeyboardActions.Drop(to, false); 211 DisplayIO.setCursorPosition(FrameMouseActions.MouseX, 212 FrameMouseActions.MouseY + 15); 210 StandardGestureActions.Drop(to, false); 211 DisplayController.setCursorPosition(DisplayController.getMouseX(), DisplayController.getMouseY() + 15); 213 212 } 214 213 … … 216 215 if (FrameShare.getInstance().sendMessage(message, peerName)) { 217 216 MessageBay.displayMessage("Sent message to " + peerName, 218 Colo r.green.darker());217 Colour.GREEN.darker()); 219 218 } else { 220 219 MessageBay.errorMessage("Could not find " + peerName); -
trunk/src/org/expeditee/actions/Misc.java
r1079 r1102 19 19 package org.expeditee.actions; 20 20 21 import java.awt.Color;22 import java.awt.Desktop;23 import java.awt.Image;24 import java.awt.image.BufferedImage;25 import java.awt.image.VolatileImage;26 21 import java.io.BufferedReader; 27 22 import java.io.File; … … 31 26 import java.io.InputStreamReader; 32 27 import java.lang.reflect.Method; 33 import java.net.URI;34 import java.net.URISyntaxException;35 28 import java.net.URL; 36 29 import java.net.URLClassLoader; … … 39 32 import java.util.LinkedList; 40 33 import java.util.List; 41 import java.util.Map;42 34 import java.util.Map.Entry; 43 import java.util.Set;44 35 import java.util.jar.Attributes; 45 36 import java.util.jar.JarFile; 46 37 47 import javax.imageio.ImageIO; 48 38 import org.expeditee.core.Colour; 39 import org.expeditee.core.Image; 40 import org.expeditee.core.Point; 41 import org.expeditee.gio.EcosystemManager; 42 import org.expeditee.gio.gesture.StandardGestureActions; 49 43 import org.expeditee.gui.AttributeUtils; 50 import org.expeditee.gui.Browser;51 44 import org.expeditee.io.Conversion; 52 import org.expeditee.gui.Display IO;45 import org.expeditee.gui.DisplayController; 53 46 import org.expeditee.io.ExpReader; 54 47 import org.expeditee.gui.Frame; 55 48 import org.expeditee.gui.FrameGraphics; 56 49 import org.expeditee.gui.FrameIO; 57 import org.expeditee.gui.FrameKeyboardActions;58 import org.expeditee.gui.FrameMouseActions;59 50 import org.expeditee.gui.FrameUtils; 60 51 import org.expeditee.gui.FreeItems; … … 63 54 import org.expeditee.gui.Reminders; 64 55 import org.expeditee.gui.TimeKeeper; 65 import org.expeditee.importer.FrameDNDTransferHandler;66 56 import org.expeditee.items.Item; 67 57 import org.expeditee.items.ItemUtils; … … 69 59 import org.expeditee.items.Text; 70 60 import org.expeditee.items.XRayable; 71 import org.expeditee.items.widgets. InteractiveWidget;61 import org.expeditee.items.widgets.Widget; 72 62 import org.expeditee.items.widgets.WidgetCorner; 73 63 import org.expeditee.items.widgets.WidgetEdge; … … 83 73 import org.nfunk.jep.ParseException; 84 74 85 import com.lowagie.text.Font;86 87 75 88 76 89 77 /** 90 * A list of miscellaneous Actions and Actionsspecific to Expeditee78 * A list of miscellaneous Actions specific to Expeditee 91 79 * 92 80 */ … … 96 84 * Causes the system to beep 97 85 */ 98 public static void beep() { 99 java.awt.Toolkit.getDefaultToolkit().beep(); 86 public static void beep() 87 { 88 EcosystemManager.getMiscManager().beep(); 100 89 } 101 90 … … 161 150 * Treats a string as a URL and attempts to open it 162 151 */ 163 public static void openURL(String siteURL){ 164 165 try { 166 URL check = new URL(siteURL); 167 Desktop.getDesktop().browse(new URI(siteURL)); 168 169 } catch (IOException| URISyntaxException e) { 170 171 MessageBay.displayMessage("'" + siteURL + "' is not a valid URL"); 172 } 152 public static void openURL(String siteURL) 153 { 154 boolean success = EcosystemManager.getMiscManager().browse(siteURL); 155 156 if (!success) MessageBay.displayMessage("'" + siteURL + "' is not a valid URL"); 173 157 } 174 158 /** … … 177 161 public static void setRestorePoint() 178 162 { 179 Frame current = Display IO.getCurrentFrame();163 Frame current = DisplayController.getCurrentFrame(); 180 164 current.change(); 181 165 FrameIO.SaveFrameAsRestore(current, true, true); … … 185 169 */ 186 170 public static void display() { 187 FrameGraphics.refresh(false);171 DisplayController.requestRefresh(false); 188 172 } 189 173 190 174 public static String getWindowSize() { 191 return Browser.getWindows()[0].getSize().toString();175 return EcosystemManager.getGraphicsManager().getWindowSize().toString(); 192 176 } 193 177 … … 205 189 */ 206 190 public static void toggleAudienceMode() { 207 FrameGraphics.ToggleAudienceMode();191 DisplayController.ToggleAudienceMode(); 208 192 } 209 193 … … 212 196 */ 213 197 public static void toggleTwinFramesMode() { 214 Display IO.ToggleTwinFrames();198 DisplayController.toggleTwinFrames(); 215 199 } 216 200 … … 227 211 for (String action : actions) { 228 212 if (!action.equalsIgnoreCase("runitem")) { 229 Actions.PerformAction(Display IO.getCurrentFrame(), current,213 Actions.PerformAction(DisplayController.getCurrentFrame(), current, 230 214 action); 231 215 } … … 249 233 String deletedFrameName = FrameIO.DeleteFrame(toDelete); 250 234 if (deletedFrameName != null) { 251 Display IO.Back();235 DisplayController.Back(); 252 236 // Remove any links on the previous frame to the one being 253 237 // deleted 254 Frame current = Display IO.getCurrentFrame();238 Frame current = DisplayController.getCurrentFrame(); 255 239 for (Item i : current.getItems()) 256 240 if (i.getLink() != null … … 312 296 // copy the item and switch 313 297 item = item.copy(); 314 item.setPosition(Display IO.getMouseX(), FrameMouseActions.getY());298 item.setPosition(DisplayController.getMousePosition()); 315 299 } 316 300 return item; … … 327 311 Collection<Item> copies = ItemUtils.CopyItems(items); 328 312 Item first = items.iterator().next(); 329 float deltaX = Display IO.getMouseX() - first.getX();330 float deltaY = FrameMouseActions.getY() - first.getY();313 float deltaX = DisplayController.getMouseX() - first.getX(); 314 float deltaY = DisplayController.getMouseY() - first.getY(); 331 315 for (Item i : copies) { 332 316 if (i.isVisible()) … … 334 318 i.setParent(null); 335 319 } 336 FrameMouseActions.pickup(copies);337 FrameGraphics.Repaint();320 StandardGestureActions.pickup(copies); 321 DisplayController.requestRefresh(true); 338 322 } 339 323 … … 347 331 * The Color to give the Item. 348 332 */ 349 public static void SetItemBackgroundColor(Item toChange, Colo r toUse) {333 public static void SetItemBackgroundColor(Item toChange, Colour toUse) { 350 334 if (toChange == null) 351 335 return; 352 336 353 337 toChange.setBackgroundColor(toUse); 354 FrameGraphics.Repaint();338 DisplayController.requestRefresh(true); 355 339 } 356 340 … … 364 348 * The Color to give the Item. 365 349 */ 366 public static void SetItemColor(Item toChange, Colo r toUse) {350 public static void SetItemColor(Item toChange, Colour toUse) { 367 351 if (toChange == null) 368 352 return; 369 353 370 354 toChange.setColor(toUse); 371 FrameGraphics.Repaint();355 DisplayController.requestRefresh(true); 372 356 } 373 357 … … 428 412 public static void attachStatsToCursor(String itemText) { 429 413 SessionStats.CreatedText(); 430 Frame current = Display IO.getCurrentFrame();414 Frame current = DisplayController.getCurrentFrame(); 431 415 Item text = current.getStatsTextItem(itemText); 432 FrameMouseActions.pickup(text);433 FrameGraphics.Repaint();416 StandardGestureActions.pickup(text); 417 DisplayController.requestRefresh(true); 434 418 } 435 419 436 420 public static void attachTextToCursor(String itemText) { 437 421 SessionStats.CreatedText(); 438 Frame current = Display IO.getCurrentFrame();422 Frame current = DisplayController.getCurrentFrame(); 439 423 Item text = current.getTextItem(itemText); 440 FrameMouseActions.pickup(text);441 FrameGraphics.Repaint();424 StandardGestureActions.pickup(text); 425 DisplayController.requestRefresh(true); 442 426 } 443 427 … … 494 478 } 495 479 496 for (Entry<String, java.awt.Font> entry: Text.FONT_WHEEL_ADDITIONAL_LOOKUP.entrySet()){480 for (Entry<String, org.expeditee.core.Font> entry: Text.FONT_WHEEL_ADDITIONAL_LOOKUP.entrySet()){ 497 481 498 482 String fontName = entry.getKey(); … … 585 569 */ 586 570 public static void jpegFrame() { 587 ImageFrame(Display IO.getCurrentFrame().getName(), "JPEG");571 ImageFrame(DisplayController.getCurrentFrame().getName(), "JPEG"); 588 572 } 589 573 … … 610 594 } 611 595 612 public static String SaveImage( BufferedImage screen, String format,596 public static String SaveImage(Image screen, String format, 613 597 String directory, String fileName) { 614 598 String suffix = "." + format.toLowerCase(); … … 633 617 634 618 // If the image is successfully written out return the fileName 635 if ( ImageIO.write(screen,format, out))619 if (screen.writeToDisk(format, out)) 636 620 return fileName; 637 621 … … 647 631 Image oldBuffer = frame.getBuffer(); 648 632 frame.setBuffer(null); 649 // Jpeg only works properly with vol itile frames633 // Jpeg only works properly with volatile frames 650 634 // Png transparency only works with bufferedImage form 651 Image frameBuffer = FrameGraphics.getBuffer(frame, false, format 652 .equalsIgnoreCase("jpeg")); 653 // Make sure overlay stuff doesnt disapear on the frame visible on the 635 Image frameBuffer = FrameGraphics.getFrameImage(frame, null, null, false, format.equalsIgnoreCase("jpeg")); 636 // Make sure overlay stuff doesnt disappear on the frame visible on the 654 637 // screen 655 638 frame.setBuffer(oldBuffer); 656 BufferedImage screen = null; 657 658 if (frameBuffer instanceof VolatileImage) { 659 // If its the current frame it will be a volitive image 660 screen = ((VolatileImage) frameBuffer).getSnapshot(); 661 } else { 662 assert (frameBuffer instanceof BufferedImage); 663 screen = (BufferedImage) frameBuffer; 664 } 665 return SaveImage(screen, format, directory, frame.getExportFileName()); 639 640 return SaveImage(frameBuffer, format, directory, frame.getExportFileName()); 666 641 } 667 642 … … 842 817 current.setActions(null); 843 818 844 FrameGraphics.Repaint();819 DisplayController.requestRefresh(true); 845 820 } 846 821 … … 932 907 text.setFormula(formulaFullCase); 933 908 if (text.isFloating()) { 934 text.setPosition(FrameMouseActions.MouseX,935 FrameMouseActions.MouseY);936 FrameMouseActions.resetOffset();909 Point cursorPos = EcosystemManager.getInputManager().getCursorPosition(); 910 text.setPosition(cursorPos.x, cursorPos.y); 911 StandardGestureActions.resetOffset(); 937 912 } else { 938 913 text.getParentOrCurrentFrame().change(); … … 956 931 public static void attachToCursor(Item item) { 957 932 item.setParent(null); 958 FrameMouseActions.pickup(item);959 FrameGraphics.Repaint();933 StandardGestureActions.pickup(item); 934 DisplayController.requestRefresh(true); 960 935 } 961 936 … … 965 940 i.invalidateAll(); 966 941 } 967 FrameMouseActions.pickup(items);942 StandardGestureActions.pickup(items); 968 943 // TODO figure out why this isnt repainting stuff immediately 969 944 // All of text item doesnt repaint until the cursor is moved 970 FrameGraphics.requestRefresh(true);945 DisplayController.requestRefresh(true); 971 946 } 972 947 … … 980 955 } 981 956 try { 982 FrameDNDTransferHandler.getInstance().importFileList(files, 983 FrameMouseActions.getPosition()); 957 EcosystemManager.getDragAndDropManager().importFileList(files, EcosystemManager.getInputManager().getCursorPosition()); 984 958 } catch (Exception e) { 985 959 } … … 990 964 if (file.exists()) { 991 965 try { 992 FrameDNDTransferHandler.getInstance().importFile(file, 993 FrameMouseActions.getPosition()); 966 EcosystemManager.getDragAndDropManager().importFile(file, EcosystemManager.getInputManager().getCursorPosition()); 994 967 } catch (Exception e) { 995 968 e.printStackTrace(); … … 1021 994 } 1022 995 1023 float curX = FrameMouseActions.MouseX; 1024 float curY = FrameMouseActions.MouseY; 996 Point cursorPos = DisplayController.getMousePosition(); 997 float curX = cursorPos.x; 998 float curY = cursorPos.y; 1025 999 1026 1000 Collection<Item> newItems = new LinkedList<Item>(); 1027 1001 Item[] d = new Item[sides]; 1028 1002 // create dots 1029 Frame current = Display IO.getCurrentFrame();1003 Frame current = DisplayController.getCurrentFrame(); 1030 1004 for (int i = 0; i < d.length; i++) { 1031 1005 d[i] = current.createDot(); … … 1053 1027 } 1054 1028 1055 Colo r newColor = item.getColor();1029 Colour newColor = item.getColor(); 1056 1030 if (newColor != null) { 1057 1031 d[0].setColor(item.getColor()); … … 1068 1042 1069 1043 ItemUtils.EnclosedCheck(newItems); 1070 FrameGraphics.refresh(false);1044 DisplayController.requestRefresh(false); 1071 1045 1072 1046 return d[0]; … … 1077 1051 } 1078 1052 1079 public static void print(String file) { 1080 try { 1081 if (Browser._theBrowser.isMinimumVersion6()) { 1082 if (Desktop.isDesktopSupported()) { 1083 Desktop.getDesktop().print(new File(file)); 1084 } 1085 } 1086 } catch (Exception e) { 1087 MessageBay.errorMessage("Printing error: " + e.getMessage()); 1088 } 1053 public static void print(String file) 1054 { 1055 String errorMessage = EcosystemManager.getMiscManager().print(file); 1056 1057 if (errorMessage != null) MessageBay.errorMessage("Printing error: " + errorMessage); 1089 1058 } 1090 1059 … … 1129 1098 * @throws Exception 1130 1099 */ 1131 public static void startLoboBrowser(Item text) throws Exception {1100 /* public static void startLoboBrowser(Item text) throws Exception { 1132 1101 if (!(text instanceof Text)) { 1133 1102 MessageBay.errorMessage("Must be a text item."); … … 1154 1123 1155 1124 FrameMouseActions.pickup(browser.getItems()); // attach browser widget to mouse 1156 } 1125 }*/ 1157 1126 1158 1127 /** … … 1161 1130 * @throws Exception 1162 1131 */ 1163 public static void startLoboBrowserNewFrame(Item text) throws Exception { 1132 public static void startLoboBrowserNewFrame(Item text) throws Exception 1133 { 1164 1134 if (!(text instanceof Text)) { 1165 1135 MessageBay.errorMessage("Must be a text item."); 1166 1136 return; 1167 1137 } 1138 1168 1139 if(text.getLink() != null) { // text item can't already have a link 1169 1140 MessageBay.errorMessage("Text item already has link."); … … 1176 1147 FrameUtils.Parse(frame); 1177 1148 1178 for( InteractiveWidget iw : frame.getInteractiveWidgets()) { // may be other widgets on frame1149 for(Widget iw : frame.getInteractiveWidgets()) { // may be other widgets on frame 1179 1150 if(iw instanceof org.expeditee.items.widgets.Browser) { 1180 1151 // Set browser to 'full screen' 1181 iw.setSize(-1, -1, -1, -1, Browser._theBrowser.getWidth(), Browser._theBrowser.getHeight() 1182 - MessageBay.MESSAGE_BUFFER_HEIGHT - 80); 1152 iw.setSize(-1, -1, -1, -1, DisplayController.getFramePaintArea().getWidth(), DisplayController.getFramePaintArea().getHeight() - 80); 1183 1153 1184 1154 // If there is a text item attached to cursor use it as url for browser 1185 if (FreeItems.textOnlyAttachedToCursor()) {1155 if (FreeItems.textOnlyAttachedToCursor()) { 1186 1156 text.setLink("" + frame.getNumber()); 1187 1157 ((org.expeditee.items.widgets.Browser)iw).navigate(text.getText()); … … 1190 1160 ((org.expeditee.items.widgets.Browser)iw).navigate("http://www.waikato.ac.nz"); 1191 1161 Text t = new Text("http://www.waikato.ac.nz"); 1192 t.setParent(Display IO.getCurrentFrame()); // set parent of text source for InteractiveWidget.createWidget()1193 t.setXY( FrameMouseActions.getX(), FrameMouseActions.getY());1162 t.setParent(DisplayController.getCurrentFrame()); // set parent of text source for InteractiveWidget.createWidget() 1163 t.setXY(DisplayController.getFloatMouseX(), DisplayController.getFloatMouseY()); 1194 1164 t.setLink("" + frame.getNumber()); // link url text to new browser frame 1195 FrameMouseActions.pickup(t); // Attach new text link to cursor1165 StandardGestureActions.pickup(t); // Attach new text link to cursor 1196 1166 } 1197 1167 } … … 1201 1171 } 1202 1172 1203 private static boolean startWidget(String name) throws Exception { 1173 private static boolean startWidget(String name) throws Exception 1174 { 1204 1175 String fullName = Actions.getClassName(name); 1205 1176 if(fullName == null) { … … 1210 1181 FreeItems.getInstance().clear(); 1211 1182 Text wt = new Text("@iw:" + fullName); // create new text item for browser widget 1212 wt.setParent(Display IO.getCurrentFrame()); // set parent of text source for InteractiveWidget.createWidget()1213 wt.setXY( FrameMouseActions.getX(), FrameMouseActions.getY()); // move to the mouse cursor1214 InteractiveWidget widget = InteractiveWidget.createWidget(wt);1215 FrameMouseActions.pickup(widget.getItems());1183 wt.setParent(DisplayController.getCurrentFrame()); // set parent of text source for InteractiveWidget.createWidget() 1184 wt.setXY(DisplayController.getMouseX(), DisplayController.getMouseY()); // move to the mouse cursor 1185 Widget widget = Widget.createWidget(wt); 1186 StandardGestureActions.pickup(widget.getItems()); 1216 1187 1217 1188 return true; … … 1223 1194 } 1224 1195 1225 Actions.PerformAction(Display IO.getCurrentFrame(), null, command);1196 Actions.PerformAction(DisplayController.getCurrentFrame(), null, command); 1226 1197 } 1227 1198 … … 1241 1212 if(name == "action" || name == "agent") { 1242 1213 if(args.length() > 0) { 1243 Actions.PerformAction(Display IO.getCurrentFrame(), null, args);1214 Actions.PerformAction(DisplayController.getCurrentFrame(), null, args); 1244 1215 } else { 1245 1216 MessageBay.displayMessage("Please specify an action/agent name"); … … 1324 1295 if (i instanceof WidgetEdge || i instanceof WidgetCorner) { 1325 1296 continue; 1326 } 1327 else { 1297 } else { 1328 1298 int new_x = i.getX(); 1329 1299 int new_y = i.getY(); … … 1345 1315 } 1346 1316 // update the polygon, otherwise stuff moves but leaves it's outline behind 1347 i. updatePolygon();1348 } 1349 1350 for ( InteractiveWidget iw : frame.getInteractiveWidgets()) {1317 i.invalidateBounds(); 1318 } 1319 1320 for (Widget iw : frame.getInteractiveWidgets()) { 1351 1321 1352 1322 int new_x = iw.getX(); … … 1368 1338 frame.change(); 1369 1339 // redraw everything 1370 FrameKeyboardActions.Refresh();1340 StandardGestureActions.Refresh(); 1371 1341 } 1372 1342 … … 1505 1475 public static void GitPushFrame() { 1506 1476 1507 FrameKeyboardActions.Save();1508 1509 Frame current = Display IO.getCurrentFrame();1477 StandardGestureActions.Save(); 1478 1479 Frame current = DisplayController.getCurrentFrame(); 1510 1480 String userName = UserSettings.ProfileName.get(); 1511 1481 … … 1544 1514 1545 1515 public static void GitPullFrame() { 1546 Frame current = Display IO.getCurrentFrame();1516 Frame current = DisplayController.getCurrentFrame(); 1547 1517 1548 1518 List<String> cmd_array = new ArrayList<String>(); … … 1554 1524 1555 1525 FrameIO.Reload(); 1556 FrameKeyboardActions.Refresh();1526 StandardGestureActions.Refresh(); 1557 1527 } 1558 1528 -
trunk/src/org/expeditee/actions/Navigation.java
r1032 r1102 21 21 import java.util.List; 22 22 23 import org.expeditee.gui.Display IO;23 import org.expeditee.gui.DisplayController; 24 24 import org.expeditee.gui.Frame; 25 25 import org.expeditee.gui.FrameIO; … … 49 49 */ 50 50 public static void Back() { 51 Display IO.Back();51 DisplayController.Back(); 52 52 } 53 53 54 54 public static void Forward() { 55 Display IO.Forward();55 DisplayController.Forward(); 56 56 } 57 57 … … 78 78 public static void GotoZero() { 79 79 FrameUtils 80 .DisplayFrame(Display IO.getCurrentFrame().getFramesetName() + 0);80 .DisplayFrame(DisplayController.getCurrentFrame().getFramesetName() + 0); 81 81 } 82 82 … … 96 96 */ 97 97 public static void Goto(Integer value) { 98 FrameUtils.DisplayFrame(Display IO.getCurrentFrame().getFramesetName()98 FrameUtils.DisplayFrame(DisplayController.getCurrentFrame().getFramesetName() 99 99 + value); 100 100 } … … 132 132 */ 133 133 public static void Large() { 134 if (Display IO.isTwinFramesOn())135 Display IO.ToggleTwinFrames();134 if (DisplayController.isTwinFramesOn()) 135 DisplayController.toggleTwinFrames(); 136 136 } 137 137 … … 188 188 189 189 public static void NextChild(Frame source) { 190 String back = Display IO.peekFromBackUpStack();190 String back = DisplayController.peekFromBackUpStack(); 191 191 // if there is no parent frame (i.e. the user is on the home frame) // 192 192 if (back == null) { // No frame was on the Backup stack … … 259 259 // better to say more explicitly/directly what the mode is!!!! 260 260 public static void Small() { 261 if (!Display IO.isTwinFramesOn())262 Display IO.ToggleTwinFrames();261 if (!DisplayController.isTwinFramesOn()) 262 DisplayController.toggleTwinFrames(); 263 263 } 264 264 -
trunk/src/org/expeditee/actions/Python.java
r1080 r1102 19 19 package org.expeditee.actions; 20 20 21 import java.awt.Color;22 import java.util.Collection;23 import java.util.LinkedList;24 21 import java.util.List; 25 22 26 import javax.script.Bindings;27 23 import javax.script.Invocable; 28 import javax.script.ScriptContext;29 import javax.script.ScriptEngine;30 import javax.script.ScriptEngineManager;31 import javax.script.ScriptException;32 import javax.script.SimpleScriptContext;33 24 34 25 import org.expeditee.gui.Frame; 35 import org.expeditee.gui.FrameIO;36 import org.expeditee.gui.FrameUtils;37 26 import org.expeditee.gui.MessageBay; 38 import org.expeditee.io.flowlayout.XGroupItem;39 27 import org.expeditee.items.Item; 40 import org.expeditee.items.ItemUtils;41 28 import org.expeditee.items.Text; 42 29 -
trunk/src/org/expeditee/actions/ScriptBase.java
r1080 r1102 19 19 package org.expeditee.actions; 20 20 21 import java.awt.Color;22 21 import java.util.Collection; 23 22 import java.util.LinkedList; … … 32 31 import javax.script.SimpleScriptContext; 33 32 33 import org.expeditee.core.Colour; 34 34 import org.expeditee.gui.Frame; 35 35 import org.expeditee.gui.FrameIO; … … 235 235 Text errorItem; 236 236 errorItem = errorFrame.addText(x, y, errorItemLines[cl.line], null); 237 errorItem.setBackgroundColor(Colo r.RED);237 errorItem.setBackgroundColor(Colour.RED); 238 238 for(String line : message.split("[\\n\\r]+")) { 239 239 errorItem.setTooltip("text: " + line); -
trunk/src/org/expeditee/actions/Simple.java
r947 r1102 19 19 package org.expeditee.actions; 20 20 21 import java.awt.Color; 22 import java.awt.Point; 23 import java.awt.event.InputEvent; 24 import java.awt.geom.Point2D; 21 //import java.awt.event.InputEvent; 25 22 import java.io.BufferedReader; 26 23 import java.io.InputStreamReader; … … 47 44 import org.expeditee.agents.SearchTree; 48 45 import org.expeditee.agents.WriteTree; 46 import org.expeditee.core.Colour; 47 import org.expeditee.core.Point; 48 import org.expeditee.gio.gesture.StandardGestureActions; 49 49 import org.expeditee.gui.AttributeUtils; 50 50 import org.expeditee.gui.AttributeValuePair; 51 51 import org.expeditee.gui.Browser; 52 import org.expeditee.gui.Display IO;52 import org.expeditee.gui.DisplayController; 53 53 import org.expeditee.gui.Frame; 54 import org.expeditee.gui.FrameGraphics;55 54 import org.expeditee.gui.FrameIO; 56 import org.expeditee.gui.FrameMouseActions;57 55 import org.expeditee.gui.FrameUtils; 58 56 import org.expeditee.gui.FreeItems; … … 156 154 private static int _stepPause = -1; 157 155 158 private static Colo r _stepColor;156 private static Colour _stepColor; 159 157 160 158 private static boolean _nextStatement; … … 173 171 174 172 public static void NewSimpleTest() { 175 Frame newSimpleTest = FrameIO.CreateFrame(Display IO.getCurrentFrame()173 Frame newSimpleTest = FrameIO.CreateFrame(DisplayController.getCurrentFrame() 176 174 .getFramesetName(), "Test", null); 177 175 List<String> actions = new ArrayList<String>(); … … 183 181 184 182 public static void NextTest() { 185 Frame next = Display IO.getCurrentFrame();183 Frame next = DisplayController.getCurrentFrame(); 186 184 do { 187 185 next = FrameIO.LoadNext(next); … … 191 189 192 190 public static void PreviousTest() { 193 Frame prev = Display IO.getCurrentFrame();191 Frame prev = DisplayController.getCurrentFrame(); 194 192 do { 195 193 prev = FrameIO.LoadPrevious(prev); … … 240 238 int testsFailed = 0; 241 239 242 FrameIO.SaveFrame(Display IO.getCurrentFrame(), false);240 FrameIO.SaveFrame(DisplayController.getCurrentFrame(), false); 243 241 MessageBay.displayMessage("Starting test suite: " + _frameset, 244 Colo r.CYAN);242 Colour.CYAN); 245 243 246 244 // Get the next number in the inf file for the _frameset … … 312 310 // Report the number of test passed and failed 313 311 MessageBay.displayMessage( 314 "Total tests: " + (testsPassed + testsFailed), Colo r.CYAN);312 "Total tests: " + (testsPassed + testsFailed), Colour.CYAN); 315 313 if (testsPassed > 0) 316 314 MessageBay.displayMessage("Passed: " + testsPassed, Item.GREEN); 317 315 if (testsFailed > 0) 318 MessageBay.displayMessage("Failed: " + testsFailed, Colo r.RED);316 MessageBay.displayMessage("Failed: " + testsFailed, Colour.RED); 319 317 // Remove items from the cursor... 320 318 FreeItems.getInstance().clear(); … … 350 348 //Have changed parameters, so it takes an Item, not just a Text item. 351 349 private static void RunFrame(Frame frame, Item current, 352 boolean acceptKeyboardInput, boolean step, int pause, Colo r color) {350 boolean acceptKeyboardInput, boolean step, int pause, Colour color) { 353 351 try { 354 352 if (current != null) { … … 358 356 */ 359 357 // DisplayIO.addToBack(current.getParent()); 360 Display IO.addToBack(DisplayIO.getCurrentFrame());358 DisplayController.addToBack(DisplayController.getCurrentFrame()); 361 359 } else { 362 360 /* TODO we should not have to pass an item just to run a frame! */ … … 365 363 } 366 364 367 _stepColor = color == null ? Colo r.green: color;368 _stepColor = new Colo r(_stepColor.getRed(), _stepColor.getGreen(),369 _stepColor.getBlue(), 50);365 _stepColor = color == null ? Colour.GREEN : color; 366 _stepColor = new Colour(_stepColor.getRed(), _stepColor.getGreen(), 367 _stepColor.getBlue(), Colour.FromComponent255(50)); 370 368 _stepPause = pause; 371 369 _step = step; … … 429 427 */ 430 428 public static void DebugFrame(Frame frame, Text current, float pause, 431 Colo r color) {429 Colour color) { 432 430 if (isProgramRunning()) { 433 431 stop(); … … 454 452 FrameUtils.DisplayFrame(item.getParent().getName(), true, true); 455 453 item.setHighlightMode(HighlightMode.Normal); 456 item.setHighlightColor(Colo r.CYAN);454 item.setHighlightColor(Colour.CYAN); 457 455 FrameIO.SaveFrame(item.getParent()); 458 456 } … … 499 497 500 498 if (_step) { 501 if (child != Display IO.getCurrentFrame()) {502 Display IO.setCurrentFrame(child, true);503 } 504 Display IO.addToBack(child);499 if (child != DisplayController.getCurrentFrame()) { 500 DisplayController.setCurrentFrame(child, true); 501 } 502 DisplayController.addToBack(child); 505 503 } 506 504 … … 524 522 AgentStats.ItemExecuted(); 525 523 try { 526 Colo r oldColor = item.getBackgroundColor();524 Colour oldColor = item.getBackgroundColor(); 527 525 if (_step) { 528 526 pause(item); … … 534 532 } else { 535 533 item.setHighlightMode(Item.HighlightMode.None); 534 item.setHighlightColorToDefault(); 536 535 } 537 536 } … … 541 540 && lastItemStatus != Status.FalseIf) { 542 541 if (_step) { 543 Display IO.removeFromBack();542 DisplayController.removeFromBack(); 544 543 } 545 544 return lastItemStatus; … … 565 564 566 565 if (_step) { 567 Display IO.removeFromBack();568 if (Display IO.getCurrentFrame() != current.getParent())569 Display IO.setCurrentFrame(current.getParent(), true);566 DisplayController.removeFromBack(); 567 if (DisplayController.getCurrentFrame() != current.getParent()) 568 DisplayController.setCurrentFrame(current.getParent(), true); 570 569 } 571 570 … … 583 582 return; 584 583 585 Colo r oldColor = item.getBackgroundColor();584 Colour oldColor = item.getBackgroundColor(); 586 585 item.setBackgroundColor(_stepColor); 587 586 item.setHighlightMode(Item.HighlightMode.None); 587 item.setHighlightColorToDefault(); 588 588 589 589 // Make sure we are on the frame with this item 590 590 Frame parent = item.getParentOrCurrentFrame(); 591 if (!parent.equals(Display IO.getCurrentFrame())) {592 Display IO.setCurrentFrame(parent, true);591 if (!parent.equals(DisplayController.getCurrentFrame())) { 592 DisplayController.setCurrentFrame(parent, true); 593 593 } 594 594 595 FrameGraphics.Repaint();595 DisplayController.requestRefresh(true); 596 596 597 597 int timeRemaining; … … 604 604 if (_stop) { 605 605 item.setBackgroundColor(oldColor); 606 item.setHighlightMode (HighlightMode.Normal, _stepColor);606 item.setHighlightModeAndColour(HighlightMode.Normal, _stepColor); 607 607 throw new Exception("Program terminated"); 608 608 } … … 1125 1125 // attribute without the value in the same item 1126 1126 if (!found && attributeItem != null) { 1127 Point2D.Float endPoint = attributeItem 1128 .getParagraphEndPosition(); 1127 Point endPoint = attributeItem.getParagraphEndPosition(); 1129 1128 1130 1129 for (Text text : targetFrame.getTextItems()) { … … 1217 1216 String stringColor = context.getPrimitives().getVariable( 1218 1217 tokens[2]).stringValue(); 1219 item.setBackgroundColor((Colo r) Conversion.Convert(1220 Colo r.class, stringColor));1218 item.setBackgroundColor((Colour) Conversion.Convert( 1219 Colour.class, stringColor)); 1221 1220 } else if (tokens[0].equals("setitemcolor")) { 1222 1221 assertVariableType(tokens[1], 1, SPointer.itemPrefix); … … 1226 1225 String stringColor = context.getPrimitives().getVariable( 1227 1226 tokens[2]).stringValue(); 1228 item.setColor((Colo r) Conversion.Convert(Color.class,1227 item.setColor((Colour) Conversion.Convert(Colour.class, 1229 1228 stringColor, item.getColor())); 1230 1229 … … 1377 1376 // attribute without the value in the same item 1378 1377 if (!found && attributeItem != null) { 1379 Point2D.Float endPoint = attributeItem 1380 .getParagraphEndPosition(); 1378 Point endPoint = attributeItem.getParagraphEndPosition(); 1381 1379 1382 1380 for (Text text : targetFrame.getTextItems()) { … … 1484 1482 assertVariableType(tokens[1], 1, SPointer.framePrefix); 1485 1483 1486 Frame currentFrame = Display IO.getCurrentFrame();1484 Frame currentFrame = DisplayController.getCurrentFrame(); 1487 1485 context.getPointers().setObject(tokens[1], currentFrame); 1488 1486 … … 1504 1502 && tokens.length > 2) { 1505 1503 Text text = (Text) currentItem; 1506 int cursorLinePos = text 1507 .getLinePosition(FrameMouseActions.getY()); 1504 int cursorLinePos = text.getLinePosition(DisplayController.getMouseY()); 1508 1505 context.getPrimitives().setValue(tokens[2], 1509 1506 new SInteger(cursorLinePos + 1)); 1510 1507 if (tokens.length > 3) { 1511 1508 int cursorCharPos = text.getCharPosition( 1512 cursorLinePos, Display IO.getMouseX())1509 cursorLinePos, DisplayController.getMouseX()) 1513 1510 .getCharIndex(); 1514 1511 context.getPrimitives().setValue(tokens[3], … … 1532 1529 1533 1530 //no frame specified by user so use current frame. 1534 getFrameName = Display IO.getCurrentFrame().getName();1531 getFrameName = DisplayController.getCurrentFrame().getName(); 1535 1532 getItem = Misc.getItemContainingData(data, FrameUtils.getFrame(getFrameName)); 1536 1533 } … … 1569 1566 1570 1567 //no frame specified by user so use current frame. 1571 getFrameName = Display IO.getCurrentFrame().getName();1568 getFrameName = DisplayController.getCurrentFrame().getName(); 1572 1569 getItem = Misc.getItemAtPosition(x, y, FrameUtils.getFrame(getFrameName)); 1573 1570 } … … 1662 1659 assertVariableType(tokens[1], 1, SPointer.itemPrefix); 1663 1660 // assertPrimitiveType(tokens[2], 2); 1664 Colo r itemColor = ((Item) context.getPointers()1661 Colour itemColor = ((Item) context.getPointers() 1665 1662 .getVariable(tokens[1]).getValue()) 1666 1663 .getPaintBackgroundColor(); … … 1672 1669 assertVariableType(tokens[1], 1, SPointer.itemPrefix); 1673 1670 // assertPrimitiveType(tokens[2], 2); 1674 Colo r itemColor = ((Item) context.getPointers()1671 Colour itemColor = ((Item) context.getPointers() 1675 1672 .getVariable(tokens[1]).getValue()).getPaintColor(); 1676 1673 String color = itemColor.getRed() + " " … … 1834 1831 double delay = context.getPrimitives().getDoubleValue(tokens[1]); 1835 1832 String s = getMessage(tokens, context, code.toString(), " ", 2); 1836 Display IO.typeStringDirect(delay, s);1833 DisplayController.typeStringDirect(delay, s); 1837 1834 } else if (tokens[0].equals("type") || tokens[0].equals("typenospaces")) { 1838 1835 … … 1840 1837 .equals("type") ? " " : "", 1); 1841 1838 1842 Display IO.typeStringDirect(0.025, s);1839 DisplayController.typeStringDirect(0.025, s); 1843 1840 } else if (tokens[0].equals("runstring")) { 1844 1841 String codeText = getMessage(tokens, context, code.toString(), " ", … … 1858 1855 // Process p = Runtime.getRuntime().exec(new String[]{"date", 1859 1856 // ">", "test.date"}); 1860 MessageBay.displayMessage(command, Colo r.darkGray);1857 MessageBay.displayMessage(command, Colour.DARK_GREY); 1861 1858 1862 1859 BufferedReader stdInput = new BufferedReader( … … 2028 2025 Item item = (Item) context.getPointers().getVariable(itemVar) 2029 2026 .getValue(); 2030 item 2031 .setPosition(FrameMouseActions.MouseX, 2032 FrameMouseActions.MouseY); 2033 FrameMouseActions.pickup(item); 2027 item.setPosition(DisplayController.getMouseX(), DisplayController.getMouseY()); 2028 StandardGestureActions.pickup(item); 2034 2029 } else if (tokens[0].equals("attachstrtocursor")) { 2035 2030 String stringVar = DEFAULT_STRING; … … 2040 2035 } 2041 2036 String s = context.getPrimitives().getStringValue(stringVar); 2042 Frame frame = Display IO.getCurrentFrame();2037 Frame frame = DisplayController.getCurrentFrame(); 2043 2038 Item item = frame.createNewText(s); 2044 item 2045 .setPosition(FrameMouseActions.MouseX, 2046 FrameMouseActions.MouseY); 2047 FrameMouseActions.pickup(item); 2039 item.setPosition(DisplayController.getMouseX(), DisplayController.getMouseY()); 2040 StandardGestureActions.pickup(item); 2048 2041 } else if (tokens[0].equals("additemtoframe")) { 2049 2042 String itemVar = DEFAULT_ITEM; … … 2410 2403 } 2411 2404 } 2412 Display IO.setCurrentFrame(frame, false);2405 DisplayController.setCurrentFrame(frame, false); 2413 2406 pause(thisFramesPause); 2414 2407 … … 2629 2622 tokens[3]) * 1000); 2630 2623 2631 int initialX = Display IO.getMouseX();2632 int initialY = FrameMouseActions.getY();2624 int initialX = DisplayController.getMouseX(); 2625 int initialY = DisplayController.getMouseY(); 2633 2626 2634 2627 final int timeInterval = 40; … … 2643 2636 Thread.yield(); 2644 2637 Thread.sleep(timeInterval); 2645 Display IO.setCursorPosition(newX, newY);2638 DisplayController.setCursorPosition(newX, newY); 2646 2639 // DisplayIO.repaint(); 2647 2640 } 2648 2641 // Thread.yield(); 2649 2642 Thread.sleep(milliseconds % timeInterval); 2650 Display IO.setCursorPosition(finalX, finalY);2643 DisplayController.setCursorPosition(finalX, finalY); 2651 2644 } else if (tokens[0].equals("glideitemto")) { 2652 2645 assertMinParametreCount(tokens, 3); … … 2686 2679 2687 2680 item.setPosition(newX, newY); 2688 FrameGraphics.Repaint();2681 DisplayController.requestRefresh(true); 2689 2682 } 2690 2683 // Thread.yield(); … … 2692 2685 item.setPosition(finalX, finalY); 2693 2686 // DisplayIO.setCursorPosition(finalX, finalY); 2694 FrameMouseActions.anchor(item);2687 StandardGestureActions.anchor(item); 2695 2688 FreeItems.getInstance().clear(); 2696 FrameGraphics.Repaint();2689 DisplayController.requestRefresh(true); 2697 2690 // FrameMouseActions.updateCursor(); 2698 2691 } … … 2740 2733 } else if (tokens[0].equals("pressleftbutton")) { 2741 2734 assertExactParametreCount(tokens, 0); 2742 DisplayIO.pressMouse(InputEvent.BUTTON1_MASK);2735 //DisplayIO.pressMouse(InputEvent.BUTTON1_MASK); TODO: Reinstate. cts16 2743 2736 } else if (tokens[0].equals("pressmiddlebutton")) { 2744 2737 assertExactParametreCount(tokens, 0); 2745 DisplayIO.pressMouse(InputEvent.BUTTON2_MASK);2738 //DisplayIO.pressMouse(InputEvent.BUTTON2_MASK); TODO: Reinstate. cts16 2746 2739 } else if (tokens[0].equals("pressrightbutton")) { 2747 2740 assertExactParametreCount(tokens, 0); 2748 DisplayIO.pressMouse(InputEvent.BUTTON3_MASK);2741 //DisplayIO.pressMouse(InputEvent.BUTTON3_MASK); TODO: Reinstate. cts16 2749 2742 } else if (tokens[0].equals("releaseleftbutton")) { 2750 2743 assertExactParametreCount(tokens, 0); 2751 DisplayIO.releaseMouse(InputEvent.BUTTON1_MASK);2744 //DisplayIO.releaseMouse(InputEvent.BUTTON1_MASK); TODO: Reinstate. cts16 2752 2745 } else if (tokens[0].equals("releasemiddlebutton")) { 2753 2746 assertExactParametreCount(tokens, 0); 2754 DisplayIO.releaseMouse(InputEvent.BUTTON2_MASK);2747 //DisplayIO.releaseMouse(InputEvent.BUTTON2_MASK); TODO: Reinstate. cts16 2755 2748 } else if (tokens[0].equals("releaserightbutton")) { 2756 2749 assertExactParametreCount(tokens, 0); 2757 DisplayIO.releaseMouse(InputEvent.BUTTON3_MASK);2750 //DisplayIO.releaseMouse(InputEvent.BUTTON3_MASK); TODO: Reinstate. cts16 2758 2751 } else if (tokens[0].equals("clickleftbutton")) { 2759 2752 assertExactParametreCount(tokens, 0); 2760 FrameMouseActions.leftButton();2753 // FrameMouseActions.leftButton(); TODO: Reinstate. cts16 2761 2754 // DisplayIO.clickMouse(InputEvent.BUTTON1_MASK); 2762 2755 } else if (tokens[0].equals("clickmiddlebutton")) { 2763 2756 assertExactParametreCount(tokens, 0); 2764 FrameMouseActions.middleButton();2757 // FrameMouseActions.middleButton(); TODO: Reinstate. cts16 2765 2758 // DisplayIO.clickMouse(InputEvent.BUTTON2_MASK); 2766 2759 } else if (tokens[0].equals("clickrightbutton")) { 2767 2760 assertExactParametreCount(tokens, 0); 2768 FrameMouseActions.rightButton();2761 // FrameMouseActions.rightButton(); TODO: Reinstate. cts16 2769 2762 // DisplayIO.clickMouse(InputEvent.BUTTON3_MASK); 2770 2763 } else if (tokens[0].equals("repaint")) { 2771 2764 assertExactParametreCount(tokens, 0); 2772 2765 // FrameGraphics.Repaint(); 2773 FrameGraphics.requestRefresh(true);2766 DisplayController.requestRefresh(true); 2774 2767 } else if (tokens[0].equals("add")) { 2775 2768 assertMaxParametreCount(tokens, 3); … … 2931 2924 int x = (int) context.getPrimitives().getIntegerValue(tokens[1]); 2932 2925 int y = (int) context.getPrimitives().getIntegerValue(tokens[2]); 2933 Display IO.setCursorPosition(x, y);2926 DisplayController.setCursorPosition(x, y); 2934 2927 2935 2928 … … 2981 2974 2982 2975 if (source == null) 2983 source = Display IO.getCurrentFrame();2976 source = DisplayController.getCurrentFrame(); 2984 2977 int lastParam = tokens.length - 1; 2985 2978 String resultVarName = null; … … 3102 3095 _programsRunning++; 3103 3096 AgentStats.reset(); 3104 MessageBay.displayMessage("Running SimpleProgram...", Colo r.BLUE);3097 MessageBay.displayMessage("Running SimpleProgram...", Colour.BLUE); 3105 3098 } 3106 3099 -
trunk/src/org/expeditee/agents/DefaultAgent.java
r919 r1102 19 19 package org.expeditee.agents; 20 20 21 import org.expeditee.gui.DisplayController; 21 22 import org.expeditee.gui.Frame; 22 import org.expeditee.gui.FrameGraphics;23 23 import org.expeditee.gui.MessageBay; 24 24 import org.expeditee.gui.TimeKeeper; … … 128 128 AGENTS_RUNNING--; 129 129 130 FrameGraphics.requestRefresh(true);130 DisplayController.requestRefresh(true); 131 131 SessionStats.setEnabled(true); 132 132 } -
trunk/src/org/expeditee/agents/DisplayComet.java
r919 r1102 23 23 import java.util.Stack; 24 24 25 import org.expeditee.gui.Display IO;25 import org.expeditee.gui.DisplayController; 26 26 import org.expeditee.gui.Frame; 27 27 import org.expeditee.gui.FrameIO; … … 45 45 Collection<String> seen = new HashSet<String>(); 46 46 47 Display IO.addToBack(frame);47 DisplayController.addToBack(frame); 48 48 49 49 // Goto the end of the comet … … 74 74 if (_stop) 75 75 return null; 76 Display IO.setCurrentFrame(_frameList.pop(), true);76 DisplayController.setCurrentFrame(_frameList.pop(), true); 77 77 _frameCount++; 78 78 pause(_delay); -
trunk/src/org/expeditee/agents/DisplayTree.java
r919 r1102 19 19 package org.expeditee.agents; 20 20 21 import org.expeditee.gui.Display IO;21 import org.expeditee.gui.DisplayController; 22 22 import org.expeditee.gui.Frame; 23 23 import org.expeditee.gui.MessageBay; … … 54 54 55 55 // push current frame on to back-stack 56 Display IO.addToBack(start);56 DisplayController.addToBack(start); 57 57 58 58 return super.initialise(start, launcher); … … 63 63 // return the user to the Frame they started on 64 64 if (!_stop) { 65 Display IO.Back();65 DisplayController.Back(); 66 66 } 67 67 super.finalise(start); … … 79 79 80 80 // ignore loops 81 if (toProcess != Display IO.getCurrentFrame())82 Display IO.setCurrentFrame(toProcess, false);81 if (toProcess != DisplayController.getCurrentFrame()) 82 DisplayController.setCurrentFrame(toProcess, false); 83 83 // parse the frame for any pause settings 84 84 delay(toProcess); -
trunk/src/org/expeditee/agents/Format.java
r919 r1102 26 26 import java.util.List; 27 27 28 import org.expeditee.gui.DisplayController; 28 29 import org.expeditee.gui.Frame; 29 import org.expeditee.gui.FrameGraphics;30 30 import org.expeditee.gui.FrameUtils; 31 31 import org.expeditee.items.Item; … … 148 148 + /* item.getX() + */it.getBoundsWidth()); 149 149 150 if (xCheck < FrameGraphics.getMaxSize().width) {150 if (xCheck < DisplayController.getFramePaintArea().getWidth()) { 151 151 Item columnHead = columnHeads.get(i + 1); 152 152 if (columnHead.getX() < maxX && columnHead.getY() < maxY) { … … 182 182 start.setChanged(true); 183 183 start.addToUndoMove(changedItems); 184 FrameGraphics.requestRefresh(true);184 DisplayController.requestRefresh(true); 185 185 return null; 186 186 } -
trunk/src/org/expeditee/agents/GraphFramesetLinks.java
r919 r1102 19 19 package org.expeditee.agents; 20 20 21 import java.awt.Color;22 21 import java.util.List; 23 22 24 23 import org.expeditee.actions.Misc; 24 import org.expeditee.core.Colour; 25 import org.expeditee.core.Font; 26 import org.expeditee.gio.gesture.StandardGestureActions; 27 import org.expeditee.gui.DisplayController; 25 28 import org.expeditee.gui.Frame; 26 29 import org.expeditee.gui.FrameIO; 27 import org.expeditee.gui.FrameMouseActions;28 30 import org.expeditee.gui.FrameUtils; 29 31 import org.expeditee.items.Item; … … 41 43 import com.mxgraph.model.mxGraphModel; 42 44 import com.mxgraph.view.mxGraph; 43 import java.awt.Font;44 45 45 46 /** … … 74 75 String resultsFramesetName = "LinksGraphResults"; 75 76 76 Colo r vertColor = new Color(51,145,148);77 Colo r unlinkedVertColor = new Color(251,107,65);78 Colo r outgoingVertColor = new Color(246,216,107);79 Colo r lineColor = new Color(0,0,0, 20);77 Colour vertColor = Colour.FromRGB255(51,145,148); 78 Colour unlinkedVertColor = Colour.FromRGB255(251,107,65); 79 Colour outgoingVertColor = Colour.FromRGB255(246,216,107); 80 Colour lineColor = Colour.FromRGBA255(0,0,0, 20); 80 81 81 82 try { … … 220 221 } 221 222 222 Font keyFont = Font.decode(Font.SANS_SERIF + " 14"); 223 Font keyFont = new Font("SansSerif"); 224 keyFont.setSize(14); 223 225 224 226 Text keyLink = resultsFrame.addText(0, 0, "\u2192 = Link", null); … … 228 230 229 231 keyLink.setFont(keyFont); 230 keyLink.setColor(Colo r.DARK_GRAY);232 keyLink.setColor(Colour.DARK_GREY); 231 233 232 234 keyFrame.setFont(keyFont);; … … 239 241 keyFrameOutgoing.setColor(outgoingVertColor); 240 242 241 keyFrameOutgoing.setAnchorBottom(10 f);242 keyFrameUnlinked.setAnchorBottom(30 f);243 keyFrame.setAnchorBottom(50 f);244 keyLink.setAnchorBottom(70 f);245 246 keyFrameOutgoing.setAnchorLeft(10 f);247 keyFrameUnlinked.setAnchorLeft(10 f);248 keyFrame.setAnchorLeft(10 f);249 keyLink.setAnchorLeft(10 f);243 keyFrameOutgoing.setAnchorBottom(10); 244 keyFrameUnlinked.setAnchorBottom(30); 245 keyFrame.setAnchorBottom(50); 246 keyLink.setAnchorBottom(70); 247 248 keyFrameOutgoing.setAnchorLeft(10); 249 keyFrameUnlinked.setAnchorLeft(10); 250 keyFrame.setAnchorLeft(10); 251 keyLink.setAnchorLeft(10); 250 252 251 253 // Moving to the area of the frame that contains the graph … … 256 258 Text link = new Text(toProcessFramesetName + " graph"); 257 259 link.setLink(resultsFrame.getName()); 258 link.setPosition( FrameMouseActions.getPosition());259 FrameMouseActions.pickup(link);260 link.setPosition(DisplayController.getMousePosition()); 261 StandardGestureActions.pickup(link); 260 262 return null; 261 263 } -
trunk/src/org/expeditee/agents/ScaleFrameset.java
r919 r1102 21 21 import java.util.Collection; 22 22 23 import org.expeditee.gio.gesture.StandardGestureActions; 23 24 import org.expeditee.gui.Frame; 24 25 import org.expeditee.gui.FrameIO; 25 import org.expeditee.gui.FrameKeyboardActions;26 26 import org.expeditee.gui.Vector; 27 27 import org.expeditee.items.Item; … … 62 62 63 63 // TODO make this thread safe! 64 FrameKeyboardActions.Refresh();64 StandardGestureActions.Refresh(); 65 65 66 66 return null; … … 102 102 continue; 103 103 // if (!(item instanceof Line)) 104 item. updatePolygon();104 item.invalidateBounds(); 105 105 106 106 if (item instanceof Line) { -
trunk/src/org/expeditee/agents/SearchAgent.java
r1069 r1102 21 21 import java.util.Collection; 22 22 23 import org.expeditee.gui.DisplayController; 23 24 import org.expeditee.gui.Frame; 24 25 import org.expeditee.gui.FrameCreator; 25 import org.expeditee.gui.FrameGraphics;26 26 import org.expeditee.gui.FrameIO; 27 27 import org.expeditee.io.Conversion; … … 126 126 } 127 127 128 public static boolean searchFrame(FrameCreator results, String frameName, 129 String pattern, String replacementString){130 int oldMode = FrameGraphics.getMode();131 FrameGraphics.forceXRayMode(false);128 public static boolean searchFrame(FrameCreator results, String frameName, String pattern, String replacementString) 129 { 130 boolean wasXrayMode = DisplayController.isXRayMode(); 131 if (!wasXrayMode) DisplayController.ToggleXRayMode(); 132 132 Frame frameToSearch = FrameIO.LoadFrame(frameName); 133 FrameGraphics.setMode(oldMode, false);133 if (!wasXrayMode) DisplayController.ToggleXRayMode(); 134 134 if (frameToSearch == null) 135 135 return false; … … 142 142 } 143 143 } 144 FrameGraphics.requestRefresh(true);144 DisplayController.requestRefresh(true); 145 145 FrameIO.SaveFrame(frameToSearch, false); 146 146 return true; … … 177 177 _results.addText(surrogate.toString(), null, 178 178 frameName, null, false); 179 FrameGraphics.requestRefresh(true);179 DisplayController.requestRefresh(true); 180 180 } 181 181 } -
trunk/src/org/expeditee/agents/SearchGreenstone.java
r919 r1102 23 23 import java.util.Vector; 24 24 25 import org.expeditee.gio.gesture.StandardGestureActions; 25 26 import org.expeditee.greenstone.Greenstone3Connection; 26 27 import org.expeditee.greenstone.Query; … … 29 30 import org.expeditee.greenstone.ResultDocument; 30 31 import org.expeditee.gui.AttributeValuePair; 31 import org.expeditee.gui.Display IO;32 import org.expeditee.gui.DisplayController; 32 33 import org.expeditee.gui.Frame; 33 34 import org.expeditee.gui.FrameCreator; 34 35 import org.expeditee.gui.FrameGraphics; 35 import org.expeditee.gui.FrameMouseActions;36 36 import org.expeditee.gui.MessageBay; 37 37 import org.expeditee.items.Text; … … 175 175 doQuery(_pattern); 176 176 } else if (_currentResultSet != null) { 177 Text newText = DisplayIO.getCurrentFrame().createNewText( 178 getCursorText()); 177 Text newText = DisplayController.getCurrentFrame().createNewText(getCursorText()); 179 178 _clicked = newText; 180 FrameMouseActions.pickup(newText);179 StandardGestureActions.pickup(newText); 181 180 } 182 181 … … 389 388 false); 390 389 391 FrameGraphics.requestRefresh(true);390 DisplayController.requestRefresh(true); 392 391 } 393 392 -
trunk/src/org/expeditee/agents/SearchTreeAndReplace.java
r919 r1102 22 22 import java.util.HashSet; 23 23 24 import org.expeditee.gui.DisplayController; 24 25 import org.expeditee.gui.Frame; 25 import org.expeditee.gui.FrameGraphics;26 26 import org.expeditee.gui.FrameIO; 27 27 import org.expeditee.items.Text; … … 79 79 } 80 80 } 81 FrameGraphics.requestRefresh(true);81 DisplayController.requestRefresh(true); 82 82 FrameIO.SaveFrame(frameToSearch, false); 83 83 return true; -
trunk/src/org/expeditee/agents/Sort.java
r919 r1102 19 19 package org.expeditee.agents; 20 20 21 import java.awt.Point;22 21 import java.util.ArrayList; 23 22 import java.util.Collection; … … 25 24 import java.util.Comparator; 26 25 26 import org.expeditee.core.Point; 27 import org.expeditee.gui.DisplayController; 27 28 import org.expeditee.gui.Frame; 28 import org.expeditee.gui.FrameGraphics;29 29 import org.expeditee.gui.FrameUtils; 30 30 import org.expeditee.items.Text; … … 68 68 // items will need to be resorted after this 69 69 start.setResort(true); 70 FrameGraphics.Repaint();70 DisplayController.requestRefresh(true); 71 71 72 72 return null; -
trunk/src/org/expeditee/agents/SwitchyardTree.java
r919 r1102 19 19 package org.expeditee.agents; 20 20 21 import java.awt.Color; 22 import java.awt.geom.Point2D; 23 21 import org.expeditee.core.Colour; 22 import org.expeditee.core.Point; 24 23 import org.expeditee.gui.Frame; 25 24 import org.expeditee.gui.FrameIO; … … 44 43 Frame childFrame = FrameIO.LoadFrame(link); 45 44 if (childFrame != null) { 46 Point 2D.FloatlastItemEnd = textItem.getParagraphEndPosition();45 Point lastItemEnd = textItem.getParagraphEndPosition(); 47 46 for (Text childItem : childFrame.getBodyTextItems(false)) { 48 47 // look for red items (remember get color may be null 49 if (Colo r.RED.equals(childItem.getPaintColor())) {48 if (Colour.RED.equals(childItem.getPaintColor())) { 50 49 // make a copy and add to parent frame 51 50 Text itemCopy = childItem.copy(); 52 51 // add to the right of parent item 53 lastItemEnd.set Location(lastItemEnd.x + 20, lastItemEnd.y);52 lastItemEnd.set(lastItemEnd.x + 20, lastItemEnd.y); 54 53 itemCopy.setPosition(lastItemEnd.x, lastItemEnd.y); 55 54 lastItemEnd = itemCopy -
trunk/src/org/expeditee/agents/mail/MailSession.java
r919 r1102 19 19 package org.expeditee.agents.mail; 20 20 21 import java.awt.Color;22 import java.awt.Point;23 21 import java.io.BufferedReader; 24 22 import java.io.InputStream; … … 48 46 import javax.mail.internet.MimeMessage; 49 47 48 import org.expeditee.core.Colour; 49 import org.expeditee.core.Point; 50 import org.expeditee.gio.DragAndDropManager; 50 51 import org.expeditee.gui.AttributeValuePair; 52 import org.expeditee.gui.DisplayController; 51 53 import org.expeditee.gui.Frame; 52 54 import org.expeditee.gui.FrameCreator; 53 import org.expeditee.gui.FrameGraphics;54 55 import org.expeditee.gui.MessageBay; 55 import org.expeditee.importer.FrameDNDTransferHandler;56 56 import org.expeditee.items.Text; 57 57 … … 208 208 try { 209 209 MessageBay.displayMessage("New mail message!", 210 null, Colo r.green, true, "getMailByID "210 null, Colour.GREEN, true, "getMailByID " 211 211 + _folder.getMessageCount()); 212 212 /* … … 247 247 248 248 MessageBay.displayMessage("Mail connection complete", 249 Colo r.GREEN);249 Colour.GREEN); 250 250 251 251 displayUnreadMailCount(); … … 262 262 int unreadCount = getUnreadCount(); 263 263 Text text = new Text(-1, unreadCount + UNREAD_MESSAGE 264 + (unreadCount == 1 ? "" : "s"), Colo r.BLUE, null);264 + (unreadCount == 1 ? "" : "s"), Colour.BLUE, null); 265 265 if (unreadCount > 0) 266 266 text.addAction("getUnreadMail " + unreadCount); … … 517 517 final Frame frame, final Point point) { 518 518 519 final Text source = FrameDNDTransferHandler.importString( 520 "Reading message " + messageNo + "...", point); 519 final Text source = DragAndDropManager.importString("Reading message " + messageNo + "...", point); 521 520 522 521 new Thread() { … … 598 597 frames.save(); 599 598 source.setLink(frames.getName()); 600 FrameGraphics.requestRefresh(true);599 DisplayController.requestRefresh(true); 601 600 } catch (MessageRemovedException mre) { 602 601 source.setText("Message removed from inbox"); -
trunk/src/org/expeditee/gui/AttributeUtils.java
r1048 r1102 19 19 package org.expeditee.gui; 20 20 21 import java.awt.Color;22 import java.awt.Font;23 import java.awt.Point;24 21 import java.lang.reflect.InvocationTargetException; 25 22 import java.lang.reflect.Method; … … 28 25 import java.util.List; 29 26 27 import org.expeditee.core.Colour; 28 import org.expeditee.core.Font; 29 import org.expeditee.core.Point; 30 30 import org.expeditee.io.Conversion; 31 31 import org.expeditee.items.DotType; … … 33 33 import org.expeditee.items.Justification; 34 34 import org.expeditee.items.PermissionPair; 35 import org.expeditee.items.Picture;36 35 import org.expeditee.items.Text; 37 36 import org.expeditee.simple.IncorrectTypeException; … … 137 136 Class<?>[] pFloat = { float.class }; 138 137 Class<?>[] pFloatO = { Float.class }; 139 Class<?>[] pColor = { Color.class }; 138 Class<?>[] pDouble = {double.class }; 139 Class<?>[] pColor = { Colour.class }; 140 140 Class<?>[] pBool = { boolean.class }; 141 141 //Class[] pDouble = { double.class }; … … 214 214 Item.class.getMethod("setBorderColor", pColor)); 215 215 _Attrib.put("AnchorLeft", Item.class.getMethod("getAnchorLeft"), 216 Item.class.getMethod("setAnchorLeft", p FloatO));216 Item.class.getMethod("setAnchorLeft", pIntO)); 217 217 _Attrib.put("AnchorRight", Item.class.getMethod("getAnchorRight"), 218 Item.class.getMethod("setAnchorRight", p FloatO));218 Item.class.getMethod("setAnchorRight", pIntO)); 219 219 _Attrib.put("AnchorTop", Item.class.getMethod("getAnchorTop"), 220 Item.class.getMethod("setAnchorTop", p FloatO));220 Item.class.getMethod("setAnchorTop", pIntO)); 221 221 _Attrib.put("AnchorBottom", Item.class.getMethod("getAnchorBottom"), 222 Item.class.getMethod("setAnchorBottom", p FloatO));222 Item.class.getMethod("setAnchorBottom", pIntO)); 223 223 _Attrib.put("Position", Item.class.getMethod("getPosition"), 224 224 Item.class.getMethod("setPosition", pPoint)); … … 248 248 Item.class.getMethod("setGradientColor", pColor)); 249 249 _Attrib.put("GradientAngle", Item.class.getMethod("getGradientAngle"), 250 Item.class.getMethod("setGradientAngle", p Int));250 Item.class.getMethod("setGradientAngle", pDouble)); 251 251 _Attrib.put("FillPattern", Item.class.getMethod("getFillPattern"), 252 252 Item.class.getMethod("setFillPattern", pString)); … … 417 417 418 418 // create the text Item 419 Frame current = Display IO.getCurrentFrame();419 Frame current = DisplayController.getCurrentFrame(); 420 420 Item attribs = current.getStatsTextItem(attributes.toString()); 421 421 return attribs; … … 486 486 if (((Double) o) < 0.0001) 487 487 return null; 488 } else if (o instanceof Colo r) {488 } else if (o instanceof Colour) { 489 489 // converts the color to the Expeditee code 490 o = Conversion.getExpediteeColorCode((Colo r) o);490 o = Conversion.getExpediteeColorCode((Colour) o); 491 491 if (o == null) 492 492 return null; … … 497 497 Font f = (Font) o; 498 498 499 String s = f.get Name() + "-";499 String s = f.getFamilyName() + "-"; 500 500 if (f.isPlain()) 501 501 s += "Plain"; -
trunk/src/org/expeditee/gui/Browser.java
r1075 r1102 19 19 package org.expeditee.gui; 20 20 21 import java.awt.Color;22 import java.awt.Dimension;23 import java.awt.Graphics;24 import java.awt.Graphics2D;25 import java.awt.Image;26 import java.awt.MouseInfo;27 import java.awt.Point;28 import java.awt.RenderingHints;29 import java.awt.Toolkit;30 import java.awt.event.ComponentEvent;31 import java.awt.event.ComponentListener;32 import java.awt.event.WindowEvent;33 import java.awt.event.WindowListener;34 import java.awt.event.WindowStateListener;35 21 import java.io.File; 36 22 import java.net.Authenticator; 37 import java.net.URL;38 23 import java.util.ArrayList; 39 24 import java.util.Collection; 40 import java.util.LinkedList; 41 42 import javax.swing.JFrame; 43 import javax.swing.RepaintManager; 44 import javax.swing.SwingUtilities; 45 46 import org.expeditee.AbsoluteLayout; 25 47 26 import org.expeditee.actions.Actions; 48 27 import org.expeditee.actions.Simple; 49 28 import org.expeditee.agents.mail.MailSession; 50 import org.expeditee.importer.FrameDNDTransferHandler; 29 import org.expeditee.core.BlockingRunnable; 30 import org.expeditee.core.Colour; 31 import org.expeditee.core.Dimension; 32 import org.expeditee.core.Point; 33 import org.expeditee.gio.EcosystemManager; 34 import org.expeditee.gio.EcosystemManager.Ecosystem; 35 import org.expeditee.gio.GraphicsManager; 36 import org.expeditee.gio.InputManager; 37 import org.expeditee.gio.InputManager.WindowEventListener; 38 import org.expeditee.gio.InputManager.WindowEventType; 39 import org.expeditee.gio.gesture.StandardGestureActions; 51 40 import org.expeditee.io.ProxyAuth; 52 41 import org.expeditee.items.Item; 42 import org.expeditee.items.ItemUtils; 53 43 import org.expeditee.items.Text; 54 44 import org.expeditee.items.widgets.WidgetCacheManager; … … 68 58 * processes any Events. 69 59 * 60 * TODO List: 61 * 62 * Back to standard: 63 * - JavaFX Text-hitting (requires JFX1.9) 64 * - Overlays and Vectors review 65 * - Pop-ups (unused in base Expeditee, only in Apollo) 66 * - Apollo input (test) 67 * - The rest of Apollo 68 * - Make sure clipping/invalidation takes twin-frames into account 69 * - Reinstate Simple input commands 70 * - Test LinkedTrack.paintInFreeSpace() 71 * - Test EmulatedTextItem.onMouseReleased(MouseEvent) (removed emulatedSource mouse button check) 72 * - Constrained placement of items 73 * 74 * Extra: 75 * - Self-describing input 76 * - Thread safety (most stuff on GIO event thread but Agents can start new threads) 77 * - Touch input 78 * - Better reflection??? (currently changes to the code break reflection as it relies on names) 79 * - JavaFX lag (always rendering to images doesn't gel well with JavaFX) 80 * - Swing widgets in JFX 81 * - JavaFX Widgets (exception on drawing?) 82 * - Reduce reliance on into-image rendering to improve JavaFX performance (utilise enforced-clip) 83 * - Block Swing ecosystem setup until window is available, or... 84 * - Reconfigure window-resized code so things are properly resized (PREFERRED). 85 * - Swing alpha-compositing of colours (currently alpha is ignored e.g. drop-shadow in transition). 86 * - Overly-thick extrusion lines (seems to depend on number of connected lines...) 87 * - Make FreeItems control pickup etc. 88 * - Remove MouseEventRouter 89 * - Highlighting (should be controlled by the items themselves) 90 * - Make Widgets into fully-fledged items (maybe???) 91 * - Merge Widget and HeavyDutyWidget 92 * - Redefine TextLayouts (relative/absolute layouts) 93 * - Settings exceptions (Password widget in JFX) (currently fixed with hack) 94 * - MessageBay (what did I mean by this specifically?) 95 * - Order-dependency of start-up code 96 * - MessageBay not refreshing at start-up 97 * - Invalidation hierarchy (item => frame => display controller area => window) 98 * - Add gesture data type checking 99 * - Paintable interface 100 * - EcosystemSpecific interface (utilise to enable/disable features based on ecosystem) 101 * - Remove/modify Mutable class (in Apollo.util, change to InOutReference) 102 * - Convert BlockingRunnable to interface 103 * - Modify Metronome to utilise Timeouts 104 * - Need AWT in FastAlphaEffect??? 105 * 106 * General: 107 * - Tidy FrameGraphics 108 * - Comment 109 * - UserSettings.DEFAULT_PROFILE_NAME not actually a user setting 110 * 111 * Done: 112 * - Timers 113 * - Timer input animations 114 * - Finish DisplayController/FrameGraphics separation 115 * - Anchor constraints (create class) 116 * - Make MessageBay take lead from DisplayController 117 * - Make message bay display again (to do with above) 118 * - Tooltips (layout broken in Swing as window size not correct when tooltips laid out) 119 * - Frame transitions 120 * - Frame transitions in twin-frames mode drawing over each other 121 * - JFX DnD manager 122 * - Reinstate Simple 123 * - Reinstate exclude source 124 * - Reinstate commented code 125 * - Twin-frames division 0 at startup 126 * - Twin frames off-by-one frame size (draws a line of erroneous pixels) 127 * - MessageBay delays showing messages on start-up 128 * - JFX Antialiasing done on theScene??? Doesn't apply for our situation 129 * - Incorporate Clip class into code 130 * - Enforced clip 131 * 132 * @author cts16 70 133 * @author jdm18 71 *72 134 */ 73 public class Browser extends JFrame implements ComponentListener, 74 WindowListener, WindowStateListener, SaveStateChangedEventListener { 75 76 /** 77 * Default version - just to stop eclipse from complaining about it. 78 */ 79 private static final long serialVersionUID = 1L; 80 81 // private static final JScrollPane scrollPane = new JScrollPane(); 135 public class Browser implements SaveStateChangedEventListener { 136 137 public static final Ecosystem ECOSYSTEM_TYPE = Ecosystem.Swing; 82 138 83 139 public static Browser _theBrowser = null; … … 86 142 87 143 public static boolean _hasExited = false; 88 89 protected MouseEventRouter _mouseEventRouter; 90 91 // A flag which is set once the application is exiting. 144 145 /** A flag which is set once the application is exiting. */ 92 146 protected boolean _isExiting = false; 93 94 protected boolean _minimum_version6 = false;95 96 public boolean isMinimumVersion6() {97 return _minimum_version6;98 }99 147 100 148 protected static boolean _initComplete = false; … … 107 155 * @param args 108 156 */ 109 public static void main(String[] args) { 110 157 public static void main(String[] args) 158 { 159 // Parse the starting frame command-line argument 111 160 if(args.length > 0) { 112 161 _startFrame = args[0]; 113 if(! Character.isDigit(_startFrame.charAt(_startFrame.length() - 1))) 114 _startFrame = _startFrame + "1"; 115 } 116 else { 162 if(!Character.isDigit(_startFrame.charAt(_startFrame.length() - 1))) _startFrame = _startFrame + "1"; 163 } else { 117 164 _startFrame = "home1"; 118 165 } 119 166 120 // Prepare all expeditee and swing data on the AWT event thread. 121 SwingUtilities.invokeLater(new Runnable() { 122 public void run() { 123 // MessageBay.supressMessages(true); 124 125 // MessageBay.supressMessages(false); 126 127 _theBrowser = new Browser(); 128 129 DisplayIO.refreshCursor(); 130 _theBrowser.requestFocus(); 131 FrameMouseActions.MouseX = MouseInfo.getPointerInfo() 132 .getLocation().x 133 - _theBrowser.getOrigin().x; 134 FrameMouseActions.MouseY = MouseInfo.getPointerInfo() 135 .getLocation().y 136 - _theBrowser.getOrigin().y; 137 _initComplete = true; 138 139 Authenticator.setDefault(proxyAuth); 140 } 141 }); 142 143 } 144 145 public Point getOrigin() { 146 return getContentPane().getLocationOnScreen(); 147 } 148 149 /** 150 * @return The mouse event router used for this browser. Never null after 151 * browser constructed. 152 */ 153 public MouseEventRouter getMouseEventRouter() { 154 return _mouseEventRouter; 167 // Window icon must be set before initialisation 168 GraphicsManager.setWindowIcon(DisplayController.ICON_IMAGE); 169 170 // Setup the GIO ecosystem so it is ready when we need it 171 EcosystemManager.createEcosystem(ECOSYSTEM_TYPE); 172 173 try { 174 EcosystemManager.getMiscManager().runOnGIOThread(new BlockingRunnable() { 175 @Override 176 public void execute() { 177 init(); 178 } 179 }); 180 } catch (Throwable e) { 181 e.printStackTrace(System.err); 182 System.exit(1); 183 } 184 185 MessageBay.showDelayedMessages(); 186 } 187 188 public static void init() 189 { 190 _theBrowser = new Browser(); 191 192 EcosystemManager.getGraphicsManager().requestFocus(); 193 194 Authenticator.setDefault(proxyAuth); 195 196 _initComplete = true; 155 197 } 156 198 … … 165 207 * 166 208 */ 167 public boolean isExi sting() {209 public boolean isExiting() { 168 210 return _isExiting; 169 211 } … … 173 215 } 174 216 175 public void setSizes(Dimension size) { 176 setSize(size); 177 setPreferredSize(size); 178 Dimension paneSize = getContentPane().getSize(); 179 FrameGraphics.setMaxSize(paneSize); 180 } 181 182 protected Browser() { 217 protected Browser() 218 { 183 219 // center the frame on the screen 184 Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); 185 double xpos = screen.getWidth() / 2; 186 double ypos = screen.getHeight() / 2; 187 setLocation((int) (xpos - (UserSettings.InitialWidth.get() / 2)), 188 (int) (ypos - (UserSettings.InitialHeight.get() / 2))); 189 190 addWindowListener(this); 191 addWindowStateListener(this); 192 193 DisplayIO.addDisplayIOObserver(WidgetCacheManager.getInstance()); 194 DisplayIO.addDisplayIOObserver(PopupManager.getInstance()); 195 196 197 // set up the image used for the icon 198 try 199 { 200 URL iconURL = ClassLoader.getSystemResource("org/expeditee/assets/icons/expediteeicon128.png"); 201 if (iconURL != null) 202 { 203 Image localImage = Toolkit.getDefaultToolkit().getImage(iconURL); 204 this.setIconImage(localImage); 205 } 206 } 207 catch (Exception e) 208 { 209 e.printStackTrace(); 210 } 211 212 setSizes(new Dimension(UserSettings.InitialWidth.get(), UserSettings.InitialHeight.get())); 213 214 // set the layout to absolute layout for widgets 215 // => this used to be done here, but now has been moved to later in the method 216 // as is works better when put in a JFXPanel 217 //this.getContentPane().setLayout(new AbsoluteLayout()); 218 219 _mouseEventRouter = new MouseEventRouter(getJMenuBar(), 220 getContentPane()); 221 222 // enable the glasspane-for capturing all mouse events 223 this.setGlassPane(_mouseEventRouter); 224 225 this.getGlassPane().setVisible(true); 226 this.getContentPane().setBackground(Color.white); 227 this.getContentPane().setFocusTraversalKeysEnabled(false); 228 229 addComponentListener(this); 230 pack(); 231 this.getContentPane().setLayout(new AbsoluteLayout()); // moved to here to work with JFXPanel 232 220 GraphicsManager g = EcosystemManager.getGraphicsManager(); 221 Dimension screen = g.getScreenSize(); 222 double xpos = (screen.width - UserSettings.InitialWidth.get()) / 2.0; 223 double ypos = (screen.height - UserSettings.InitialHeight.get()) / 2.0; 224 g.setWindowLocation(new Point((int) xpos, (int) ypos)); 225 226 DisplayController.Init(); 227 228 DisplayController.addDisplayObserver(WidgetCacheManager.getInstance()); 229 if (ECOSYSTEM_TYPE == Ecosystem.Swing) { 230 DisplayController.addDisplayObserver(PopupManager.getInstance()); 231 } 232 233 setInputManagerWindowRoutines(); 234 233 235 // Reset windows to user specified size 234 // Must be done after initialising the content pane above! 235 setSizes(new Dimension(UserSettings.InitialWidth.get(), UserSettings.InitialHeight.get())); 236 237 // UserSettings.ProfileName.set(FrameIO.ConvertToValidFramesetName(System.getProperty("user.name"))); 238 String userName = UserSettings.ProfileName.get(); 239 //UserSettings.UserName.set(UserSettings.ProfileName.get()); 236 Dimension initialWindowSize = new Dimension(UserSettings.InitialWidth.get(), UserSettings.InitialHeight.get()); 237 g.setWindowSize(initialWindowSize); 240 238 241 239 // Load documentation and start pages 242 240 FrameUtils.extractResources(false); 241 243 242 // Load fonts before loading any frames so the items on the frames will be able to access their fonts 244 243 Text.InitFonts(); 245 246 Frame profile = loadProfile(userName); 247 248 // Need to display errors once things have been init otherwise 249 // exceptions occur if there are more than four messages neededing to be 250 // displayed. 251 252 Frame defaultProfile = loadProfile(UserSettings.DEFAULT_PROFILE_NAME); 253 254 Collection<String> warningMessages = new LinkedList<String>(); 255 warningMessages.addAll(FrameUtils.ParseProfile(defaultProfile)); 256 //Save the cursor if the defaultProfile had a custom cursor 257 Collection<Item> cursor = null; 258 if(FreeItems.hasCursor()){ 259 cursor = new ArrayList<Item>(); 260 cursor.addAll(FreeItems.getCursor()); 261 } 262 warningMessages.addAll(FrameUtils.ParseProfile(profile)); 263 if(cursor != null && !FreeItems.hasCursor()){ 264 FreeItems.setCursor(cursor); 265 } 266 267 /* 268 * See Java bug ID 4016934. They say that window closed events are 269 * called once the JFrame is disposed. 270 */ 271 setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 272 273 // Expeditee handles its own repainting of AWT/Swing components 274 RepaintManager.setCurrentManager(ExpediteeRepaintManager.getInstance()); 244 245 Frame userProfile = loadProfiles(); 275 246 276 247 // Listen for save status to display during and after runtime 277 248 EntitySaveManager.getInstance().addSaveStateChangedEventListener(this); 278 279 String full_version = System.getProperty("java.version"); 280 String[] version_parts = full_version.split("\\."); 281 if (version_parts.length>=2) { 282 String version_str = version_parts[0] + "." + version_parts[1]; 283 double version = Double.parseDouble(version_str); 284 285 if (version >= 1.6) { 286 // Set the drag and drop handler 287 _minimum_version6 = true; 288 setTransferHandler(FrameDNDTransferHandler.getInstance()); 289 } else { 290 System.err.println("Upgrade to a (minimum) of Java 1.6 to enable drag and drop support in Expeditee"); 291 } 292 } 293 else { 294 System.err.println("Unable to parse Java version number " + full_version + " to determin if Drag and Drop supported"); 295 296 } 297 298 249 299 250 try { 300 warningMessages.addAll(Actions.Init());251 MessageBay.warningMessages(Actions.Init()); 301 252 302 253 Settings.Init(); 303 304 DisplayIO.Init(this);305 // Set visible must be just after DisplayIO.Init for the message box306 // to307 // be the right size308 setVisible(true);309 310 setupGraphics();311 312 // required to accept TAB key313 setFocusTraversalKeysEnabled(false);314 315 // Must be loaded after setupGraphics if images are on the frame316 // Turn off XRay mode and load the first frame317 FrameGraphics.setMode(FrameGraphics.MODE_NORMAL, false);318 254 319 255 // Go to the start frame if specified, otherwise go to the profile frame … … 321 257 if(_startFrame == null) { 322 258 _startFrame = UserSettings.StartFrame.get(); 323 if(_startFrame != null && !Character.isDigit(_startFrame.charAt(_startFrame.length() - 1))) 259 if(_startFrame != null && !Character.isDigit(_startFrame.charAt(_startFrame.length() - 1))) { 324 260 _startFrame = _startFrame + "1"; 325 } 261 } 262 } 263 326 264 if((start = FrameIO.LoadFrame(_startFrame)) != null) { 327 265 // Make sure HomeFrame gets set 328 266 UserSettings.HomeFrame.set(start.getName()); 329 //if (UserSettings.HomeFrame.get() == null) { 330 //UserSettings.HomeFrame.set(profile.getName()); 331 332 //} 333 // Make sure the user can get back to the profile frame easily 334 //DisplayIO.addToBack(profile); 267 335 268 // Go to the start frame 336 Display IO.setCurrentFrame(start, true);269 DisplayController.setCurrentFrame(start, true); 337 270 } else { 338 271 // If an invalid start frame was specified, show a warning 339 if(_startFrame != null) { 340 warningMessages.add("Unknown frame: " + _startFrame); 341 } 272 if(_startFrame != null) MessageBay.warningMessage("Unknown frame: " + _startFrame); 273 342 274 // Go to the profile frame 343 FrameUtils.loadFirstFrame( profile);275 FrameUtils.loadFirstFrame(userProfile); 344 276 } 345 DisplayIO.UpdateTitle(); 346 347 /* 348 * I think this can be moved back up to the top of the Go method 349 * now... It used to crash the program trying to print error 350 * messages up the top 351 */ 352 for (String message : warningMessages) 353 MessageBay.warningMessage(message); 354 355 this.getContentPane().addKeyListener(FrameKeyboardActions.getInstance()); 356 this.addKeyListener(FrameKeyboardActions.getInstance()); 357 358 _mouseEventRouter.addExpediteeMouseListener(FrameMouseActions.getInstance()); 359 _mouseEventRouter.addExpediteeMouseMotionListener(FrameMouseActions.getInstance()); 360 _mouseEventRouter.addExpediteeMouseWheelListener(FrameMouseActions.getInstance()); 361 362 // Dont refresh for the profile frame otherwise error messages are shown twice 363 if (!DisplayIO.getCurrentFrame().equals(profile)) { 364 FrameKeyboardActions.Refresh(); 277 278 DisplayController.updateTitle(); 279 280 // Don't refresh for the profile frame otherwise error messages are shown twice 281 if (!DisplayController.getCurrentFrame().equals(userProfile)) { 282 StandardGestureActions.Refresh(); 365 283 // If it's the profile frame just reparse it in order to display images/circles/widgets correctly 366 284 } else { 367 FrameUtils.Parse(profile); 368 } 369 // setVisible(true); 285 FrameUtils.Parse(userProfile); 286 } 370 287 } catch (Exception e) { 371 288 e.printStackTrace(); … … 374 291 } 375 292 293 public void saveCompleted(SaveStateChangedEvent event) 294 { 295 MessageBay.displayMessage("Save finished!", Colour.BLUE); 296 } 297 298 public void saveStarted(SaveStateChangedEvent event) 299 { 300 String name = event.getEntity().getSaveName(); 301 if (name == null) name = "data"; 302 MessageBay.displayMessage("Saving " + name + "...", Colour.BLUE); 303 } 304 376 305 /** 377 * @param userName 306 * Closes the browser and ends the application. Performs saving operations - 307 * halting until saves have completed. Feedback is given to the user while 308 * the application is exiting. Must call on the swing thread. 309 */ 310 public void exit() { 311 312 // Set exiting flag 313 _isExiting = true; 314 315 MessageBay.displayMessage("System exiting..."); 316 317 /** 318 * TODO: Prompt the user etc. 319 */ 320 321 // TODO: Should we should a popup with a progress bar for user feedback? 322 // this would be nice and easy to do. 323 // Exit on a dedicated thread so that feedback can be obtained 324 new Exiter().start(); // this will exit the application 325 } 326 327 /** 328 * The system must exit on a different thread other than the swing thread so 329 * that the save threads can fire save-feedback to the swing thread and thus 330 * provide user feedback on asynchronous save operations. 331 * 332 * @author Brook Novak 333 * 334 */ 335 private class Exiter extends Thread { 336 337 @Override 338 public void run() { 339 340 // The final save point for saveable entities 341 EntitySaveManager.getInstance().saveAll(); 342 try { 343 EntitySaveManager.getInstance().waitUntilAllSavingFinished(); 344 } catch (InterruptedException e) { 345 e.printStackTrace(); 346 } 347 348 // Stop any agents or simple programs 349 Simple.stop(); 350 Actions.stopAgent(); 351 // Wait for them to stop 352 try { 353 // Only stop if need to... 354 // Brook: What purpose does this serve? 355 MessageBay.displayMessage("Stopping Simple programs..."); 356 while (Simple.isProgramRunning()) { 357 Thread.sleep(100); 358 } 359 360 MessageBay.displayMessage("Stopping Agents..."); 361 /* TODO: Only stop if need to... */ 362 while (Actions.isAgentRunning()) { 363 Thread.sleep(100); // Brook: What purpose does this serve? 364 } 365 } catch (Exception e) { 366 367 } 368 369 MessageBay.displayMessage("Saving current frame..."); 370 FrameIO.SaveFrame(DisplayController.getCurrentFrame()); 371 372 MessageBay.displayMessage("Saving stats..."); 373 StatsLogger.WriteStatsFile(); 374 375 if (MailSession.getInstance() != null) { 376 if (MailSession.getInstance().finalise()) { 377 // TODO display this message before the finalising 378 // is done but only if the mail needs closing 379 MessageBay.displayMessage("Closed ExpMail..."); 380 } 381 } 382 383 if (FrameShare.getInstance() != null) { 384 MessageBay.displayMessage("Stopping FrameServer..."); 385 FrameShare.getInstance().finalise(); 386 } 387 388 MessageBay.displayMessage("System exited"); 389 390 // Finally remove the messages frameset 391 FrameIO.moveFrameset("messages", FrameIO.MESSAGES_PATH); 392 393 /* 394 * Create a new messages folder so that it doesn't throw 395 * Exceptions when two Expeditee's open at once and the 396 * second tries to save its messages 397 */ 398 File file = new File(FrameIO.MESSAGES_PATH + "messages"); 399 file.mkdirs(); 400 401 Browser._hasExited = true; 402 403 System.exit(0); 404 } 405 } 406 407 /** 408 * Used to set up the the browser for use in testing. 409 * 378 410 * @return 379 411 */ 380 protected Frame loadProfile(String userName) { 412 public static Browser initializeForTesting() 413 { 414 if (Browser._theBrowser == null) { 415 FrameShare.disableNetworking = true; 416 MailSession._autoConnect = false; 417 418 Browser.main(new String[]{}); 419 try { 420 while (!isInitComplete()) { 421 Thread.sleep(10); 422 } 423 } catch (Exception e) { 424 } 425 } 426 return _theBrowser; 427 } 428 429 private static void setInputManagerWindowRoutines() 430 { 431 InputManager manager = EcosystemManager.getInputManager(); 432 433 // Refresh the layout when the window resizes 434 manager.addWindowEventListener(new WindowEventListener() { 435 @Override 436 public void onWindowEvent(WindowEventType type) 437 { 438 if (type != WindowEventType.WINDOW_RESIZED) return; 439 DisplayController.refreshWindowSize(); 440 FrameIO.RefreshCacheImages(); 441 for (Frame frame : DisplayController.getFrames()) { 442 if (frame != null) { 443 ItemUtils.Justify(frame); 444 frame.refreshSize(); 445 } 446 } 447 DisplayController.requestRefresh(false); 448 } 449 }); 450 451 manager.addWindowEventListener(new WindowEventListener() { 452 @Override 453 public void onWindowEvent(WindowEventType type) 454 { 455 if (type != WindowEventType.MOUSE_EXITED_WINDOW) return; 456 StandardGestureActions.mouseExitedWindow(); 457 } 458 }); 459 460 manager.addWindowEventListener(new WindowEventListener() { 461 @Override 462 public void onWindowEvent(WindowEventType type) 463 { 464 if (type != WindowEventType.MOUSE_ENTERED_WINDOW) return; 465 StandardGestureActions.mouseEnteredWindow(); 466 } 467 }); 468 469 manager.addWindowEventListener(new WindowEventListener() { 470 @Override 471 public void onWindowEvent(WindowEventType type) 472 { 473 if (type != WindowEventType.WINDOW_CLOSED) return; 474 if (Browser._theBrowser != null) Browser._theBrowser.exit(); 475 } 476 }); 477 } 478 479 /** 480 * @return The user's profile frame. 481 */ 482 private static Frame loadProfiles() 483 { 484 String defaultProfileName = UserSettings.DEFAULT_PROFILE_NAME; 485 String userName = UserSettings.ProfileName.get(); 486 487 Frame defaultProfile = loadProfile(defaultProfileName); 488 Frame userProfile = loadProfile(userName); 489 490 MessageBay.warningMessages(FrameUtils.ParseProfile(defaultProfile)); 491 492 // Save the cursor if the defaultProfile had a custom cursor 493 Collection<Item> cursor = null; 494 if(FreeItems.hasCursor()) { 495 cursor = new ArrayList<Item>(); 496 cursor.addAll(FreeItems.getCursor()); 497 } 498 499 MessageBay.warningMessages(FrameUtils.ParseProfile(userProfile)); 500 501 if (cursor != null && !FreeItems.hasCursor()) FreeItems.setCursor(cursor); 502 503 return userProfile; 504 } 505 506 protected static Frame loadProfile(String userName) 507 { 381 508 Frame profile = FrameIO.LoadProfile(userName); 509 382 510 if (profile == null) { 383 511 try { … … 392 520 return profile; 393 521 } 394 395 public Graphics2D g;396 397 protected void setupGraphics() {398 if (g != null)399 g.dispose();400 g = (Graphics2D) this.getContentPane().getGraphics();401 assert (g != null);402 g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,403 RenderingHints.VALUE_TEXT_ANTIALIAS_ON);404 g.setFont(g.getFont().deriveFont(40f));405 FrameGraphics.setDisplayGraphics(g);406 }407 408 // private int count = 0;409 @Override410 public void paint(Graphics g) {411 // All this does is make sure the screen is repainted when the browser412 // is moved so that some of the window is off the edge of the display413 // then moved back into view414 super.paint(g);415 FrameGraphics.ForceRepaint();416 // System.out.println("Paint " + count++);417 }418 419 /**420 * @inheritDoc421 */422 public void componentResized(ComponentEvent e) {423 setSizes(this.getSize());424 setupGraphics();425 FrameIO.RefreshCasheImages();426 FrameGraphics.ForceRepaint();427 }428 429 /**430 * @inheritDoc431 */432 public void componentMoved(ComponentEvent e) {433 // FrameGraphics.setMaxSize(this.getSize());434 }435 436 /**437 * @inheritDoc438 */439 public void componentShown(ComponentEvent e) {440 DisplayIO.fullScreenTransitionPending=false;441 }442 443 /**444 * @inheritDoc445 */446 public void componentHidden(ComponentEvent e) {447 }448 449 public void windowClosing(WindowEvent e) {450 }451 452 public void windowClosed(WindowEvent e) {453 if (!DisplayIO.fullScreenTransitionPending) {454 exit();455 }456 }457 458 public void windowOpened(WindowEvent e) {459 }460 461 public void windowIconified(WindowEvent e) {462 }463 464 public void windowDeiconified(WindowEvent e) {465 }466 467 public void windowActivated(WindowEvent e) {468 }469 470 public void windowDeactivated(WindowEvent e) {471 }472 473 public void windowStateChanged(WindowEvent e) {474 }475 476 public int getDrawingAreaX() {477 // return scrollPane.getLocationOnScreen().x;478 return this.getLocationOnScreen().x;479 }480 481 public int getDrawingAreaY() {482 // return scrollPane.getLocationOnScreen().y;483 return this.getLocationOnScreen().y;484 }485 486 public void saveCompleted(SaveStateChangedEvent event) {487 // if (isExisting()) {488 489 // } else {490 MessageBay.displayMessage("Save finished!", Color.BLUE);491 // }492 }493 494 public void saveStarted(SaveStateChangedEvent event) {495 // if (isExisting()) {496 497 // } else {498 String name = event.getEntity().getSaveName();499 if (name == null)500 name = "data";501 MessageBay.displayMessage("Saving " + name + "...", Color.BLUE);502 // }503 }504 505 /**506 * Closes the browser and ends the application. Performs saving operations -507 * halting until saves have completed. Feedback is given to the user while508 * the application is exiting. Must call on the swing thread.509 */510 public void exit() {511 512 // Set exiting flag513 _isExiting = true;514 515 MessageBay.displayMessage("System exiting...");516 517 /**518 * TODO: Prompt the user etc.519 */520 521 // TODO: Should we should a popup with a progress bar for user feedback?522 // this would be nice and easy to do.523 // Exit on a dedicated thread so that feedback can be obtained524 new Exiter().start(); // this will exit the application525 }526 527 /**528 * The system must exit on a different thread other than the swing thread so529 * that the save threads can fire save-feedback to the swing thread and thus530 * provide user feedback on asynchronous save operations.531 *532 * @author Brook Novak533 *534 */535 private class Exiter extends Thread {536 537 @Override538 public void run() {539 540 // The final save point for saveable entities541 EntitySaveManager.getInstance().saveAll();542 try {543 EntitySaveManager.getInstance().waitUntilAllSavingFinished();544 } catch (InterruptedException e) {545 e.printStackTrace();546 }547 548 // The final phase must save on the swing thread since dealing with549 // the expeditee data model550 SwingUtilities.invokeLater(new Runnable() {551 public void run() {552 553 // Stop any agents or simple programs554 Simple.stop();555 Actions.stopAgent();556 // Wait for them to stop557 try {558 MessageBay559 .displayMessage("Stopping Simple programs..."); // TODO:560 /**561 * Only stop if need to...562 */563 while (Simple.isProgramRunning()) {564 Thread.sleep(100);565 /* Brook: What purpose does this serve? */566 }567 MessageBay.displayMessage("Stopping Agents...");568 /* TODO: Only stop if need to... */569 while (Actions.isAgentRunning()) {570 Thread.sleep(100); // Brook: What purpose does this571 // serve?572 }573 } catch (Exception e) {574 575 }576 577 MessageBay.displayMessage("Saving current frame...");578 FrameIO.SaveFrame(DisplayIO.getCurrentFrame());579 580 MessageBay.displayMessage("Saving stats...");581 StatsLogger.WriteStatsFile();582 583 if (MailSession.getInstance() != null) {584 if (MailSession.getInstance().finalise()) {585 // TODO display this message before the finalising586 // is done but only if the mail needs closing587 MessageBay.displayMessage("Closed ExpMail...");588 }589 }590 591 if (FrameShare.getInstance() != null) {592 MessageBay.displayMessage("Stopping FrameServer...");593 FrameShare.getInstance().finalise();594 }595 596 MessageBay.displayMessage("System exited");597 598 // Finally remove the messages frameset599 FrameIO.moveFrameset("messages", FrameIO.MESSAGES_PATH);600 601 /*602 * Create a new messages folder so that it doesn't throw603 * Exceptions when two Expeditee's open at once and the604 * second tries to save its messages605 */606 File file = new File(FrameIO.MESSAGES_PATH + "messages");607 file.mkdirs();608 609 Browser._hasExited = true;610 611 System.exit(0);612 }613 });614 }615 }616 617 /**618 * Used to set up the the browser for use in testing.619 *620 * @return621 */622 public static Browser initializeForTesting() {623 if (Browser._theBrowser == null) {624 FrameShare.disableNetworking = true;625 MailSession._autoConnect = false;626 627 Browser.main(new String[]{});628 try {629 while (!isInitComplete()) {630 Thread.sleep(10);631 }632 } catch (Exception e) {633 }634 }635 return _theBrowser;636 }637 638 522 } -
trunk/src/org/expeditee/gui/ColorUtils.java
r919 r1102 19 19 package org.expeditee.gui; 20 20 21 import java.awt.Color;21 import org.expeditee.core.Colour; 22 22 23 23 public class ColorUtils { … … 36 36 * @return the next color on the color wheel 37 37 */ 38 public static Colo r getNextColor(Color color, Color[] wheel, Color skip) {38 public static Colour getNextColor(Colour color, Colour[] wheel, Colour skip) { 39 39 if (color == null) { 40 40 color = wheel[0]; -
trunk/src/org/expeditee/gui/Frame.java
r998 r1102 19 19 package org.expeditee.gui; 20 20 21 import java.awt.Color;22 import java.awt.Image;23 import java.awt.Polygon;24 import java.awt.image.ImageObserver;25 import java.awt.image.VolatileImage;26 21 import java.sql.Time; 27 22 import java.util.ArrayList; … … 37 32 38 33 import org.expeditee.actions.Simple; 34 import org.expeditee.core.Colour; 35 import org.expeditee.core.Image; 36 import org.expeditee.core.bounds.PolygonBounds; 37 import org.expeditee.gio.gesture.StandardGestureActions; 38 import org.expeditee.gio.input.StandardInputEventListeners; 39 import org.expeditee.gio.input.KBMInputEvent.Key; 39 40 import org.expeditee.io.Conversion; 40 41 import org.expeditee.items.Constraint; … … 50 51 import org.expeditee.items.UserAppliedPermission; 51 52 import org.expeditee.items.XRayable; 52 import org.expeditee.items.widgets. InteractiveWidget;53 import org.expeditee.items.widgets.Widget; 53 54 import org.expeditee.items.widgets.WidgetCorner; 54 55 import org.expeditee.settings.UserSettings; … … 66 67 * 67 68 */ 68 public class Frame implements ImageObserver { 69 public class Frame { 70 71 /** The frame number to indicate this is a virtual frame. */ 72 public static final int VIRTUAL_FRAME_NUMBER = -1; 73 74 /** The background colour the frame name should take if the frame has user permission level 'none'. */ 75 public static final Colour FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_NONE = Colour.FromRGB255(255, 220, 220); 76 /** The background colour the frame name should take if the frame has user permission level 'followLinks'. */ 77 public static final Colour FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_FOLLOW_LINKS = Colour.FromRGB255(255, 230, 135); 78 /** The background colour the frame name should take if the frame has user permission level 'copy'. */ 79 public static final Colour FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_COPY = Colour.FromRGB255(255, 255, 155); 80 /** The background colour the frame name should take if the frame has user permission level 'createFrames'. */ 81 public static final Colour FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_CREATE_FRAMES = Colour.FromRGB255(220, 255, 220); 82 /** The background colour the frame name should take if the frame has user permission level 'full'. */ 83 public static final Colour FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_FULL = null; 69 84 70 85 private boolean _protectionChanged = false; 71 72 public boolean isReadOnly() {73 return !_frameName.hasPermission(UserAppliedPermission.full)74 && !_protectionChanged;75 }76 86 77 87 // The various attributes of this Frame … … 95 105 96 106 // Background color is clear 97 private Colo r _background = null;107 private Colour _background = null; 98 108 99 109 // Foreground color is automatic by default 100 private Colo r _foreground = null;110 private Colour _foreground = null; 101 111 102 112 private String path; … … 105 115 106 116 private boolean _sorted = true; 107 108 // The items contained in this Frame 109 // records whether a change has been made to this Frame (for saving 110 // purposes). 117 118 /** Whether the frame has changed and therefore needs saving. */ 111 119 private boolean _change = false; 112 120 121 /** Whether the frame has been saved. */ 113 122 private boolean _saved = false; 114 115 private static final class History {116 public enum Type {117 deletion,118 movement119 }120 public final List<Item> items;121 public final Type type;122 123 public History(Collection<Item> items, Type type) {124 this.items = new LinkedList<Item>(items);125 this.type = type;126 }127 128 public String toString() {129 return this.type.toString() + ":\n" + this.items.toString();130 }131 }132 123 133 124 // list of deleted items that can be restored … … 141 132 142 133 // for drawing purposes 143 private List< InteractiveWidget> _iWidgets = new ArrayList<InteractiveWidget>();134 private List<Widget> _iWidgets = new ArrayList<Widget>(); 144 135 145 136 private int _lineCount = 0; … … 170 161 private Text _dotTemplate = TemplateSettings.DotTemplate.get().copy(); 171 162 172 /** 173 * Default constructor, nothing is set. 174 */ 175 public Frame() { 176 } 177 178 public void reset() { 163 Map<String, Text> _annotations = null; 164 165 private Collection<FrameObserver> _observers = new HashSet<FrameObserver>(); 166 167 /** Default constructor, nothing is set. */ 168 public Frame() 169 { 170 } 171 172 public boolean isReadOnly() 173 { 174 return !_frameName.hasPermission(UserAppliedPermission.full) && !_protectionChanged; 175 } 176 177 public void reset() 178 { 179 179 refreshItemPermissions(UserAppliedPermission.full); 180 //System.out.println("Reset");181 180 resetDot(); 182 181 SessionStats.NewFrameSession(); 183 182 } 184 183 185 private void resetDot() { 184 private void resetDot() 185 { 186 186 _dotTemplate.setColor(TemplateSettings.ColorWheel.getSafe(1)); 187 187 _dotTemplate.setFillColor(TemplateSettings.FillColorWheel.getSafe(0)); 188 188 } 189 189 190 public void nextDot() { 191 _dotTemplate.setFillColor(ColorUtils.getNextColor(_dotTemplate 192 .getFillColor(), TemplateSettings.FillColorWheel.get(), null)); 193 _dotTemplate.setColor(ColorUtils.getNextColor(_dotTemplate.getColor(), 194 TemplateSettings.ColorWheel.get(), null)); 195 196 if (_dotTemplate.getColor() == null || _dotTemplate.getColor().equals(Color.white)) { 197 resetDot(); 198 } 199 } 200 201 public Image getBuffer() { 190 public void nextDot() 191 { 192 _dotTemplate.setFillColor(ColorUtils.getNextColor(_dotTemplate.getFillColor(), TemplateSettings.FillColorWheel.get(), null)); 193 _dotTemplate.setColor(ColorUtils.getNextColor(_dotTemplate.getColor(), TemplateSettings.ColorWheel.get(), null)); 194 if (_dotTemplate.getColor() == null || _dotTemplate.getColor().equals(Colour.WHITE)) resetDot(); 195 } 196 197 public Image getBuffer() 198 { 202 199 return _buffer; 203 200 } 204 201 205 public void setBuffer(Image newBuffer) { 202 public void setBuffer(Image newBuffer) 203 { 206 204 _buffer = newBuffer; 207 205 } 208 206 209 public boolean isBufferValid() { 210 if (_buffer == null 211 || (_buffer instanceof VolatileImage && ((VolatileImage) _buffer) 212 .contentsLost())) 213 return false; 207 public boolean isBufferValid() 208 { 209 if (_buffer == null) return false; 214 210 215 211 return _validBuffer; 216 212 } 217 213 218 private void setBufferValid(boolean newValue) { 214 private void setBufferValid(boolean newValue) 215 { 219 216 _validBuffer = newValue; 220 217 } 221 218 222 public int getNextItemID() { 219 public int getNextItemID() 220 { 223 221 return ++_itemCount; 224 222 } 225 223 226 public void updateIDs(List<Item> items) { 227 for (Item i : items) 228 if (!(i instanceof Line)) 224 public void updateIDs(List<Item> items) 225 { 226 for (Item i : items) { 227 if (!(i instanceof Line)) { 229 228 i.setID(getNextItemID()); 230 else229 } else { 231 230 i.setID(++_lineCount); 231 } 232 } 232 233 } 233 234 … … 237 238 * Hence it excludes free-widgets. Returns a copy 238 239 */ 239 public List<InteractiveWidget> getInteractiveWidgets() { 240 LinkedList<InteractiveWidget> clone = new LinkedList<InteractiveWidget>(); 240 public List<Widget> getInteractiveWidgets() 241 { 242 LinkedList<Widget> clone = new LinkedList<Widget>(); 241 243 clone.addAll(this._iWidgets); 242 244 return clone; … … 248 250 * @return True if this Frame has been altered, false otherwise. 249 251 */ 250 public boolean hasChanged() { 252 public boolean hasChanged() 253 { 251 254 // virtual frames are never saved 252 if (_number == -1) 253 return false; 255 if (_number == VIRTUAL_FRAME_NUMBER) return false; 254 256 255 257 return _change; … … 260 262 * 261 263 * @param value 262 * False if this Frame should be saved to disk, False otherwise. 263 */ 264 public void setChanged(boolean value) { 265 // System.out.println(getName() + " " + value); 266 boolean oldValue = _change; 267 268 // if (value) { 269 // notifyObservers(); 270 // } 271 272 if (oldValue == value) 273 return; 264 * True if this Frame should be saved to disk, False otherwise. 265 */ 266 public void setChanged(boolean value) 267 { 268 if (_change == value) return; 274 269 275 270 _change = value; … … 281 276 } 282 277 283 // private static int updateCount = 0;284 285 278 /** 286 279 * Notify items observing the data on this frame that the frame content has … … 290 283 * true if the frame should be recalculated first. 291 284 */ 292 public void notifyObservers(boolean bRecalculate) { 293 if (bRecalculate) { 294 recalculate(); 295 } 285 public void notifyObservers(boolean bRecalculate) 286 { 287 if (bRecalculate) recalculate(); 296 288 // Notify the frame listeners that the frame has changed 297 289 /* … … 301 293 * changing this frames observer list. 302 294 */ 303 Collection<FrameObserver> observersCopy = new LinkedList<FrameObserver>( 304 _observers); 295 Collection<FrameObserver> observersCopy = new LinkedList<FrameObserver>(_observers); 305 296 // System.out.println(++updateCount + " update"); 306 297 307 298 for (FrameObserver fl : observersCopy) { 308 if (/* !Item.isLocked(fl) && */fl.isVisible()) 309 fl.update(); 299 if (fl.isVisible()) fl.update(); 310 300 } 311 301 } 312 302 313 303 // indicates the frame has changed 314 public void change() { 304 public void change() 305 { 315 306 setChanged(true); 316 307 _interactableItems.clear(); … … 323 314 * @return The list of Item objects that are on this Frame. 324 315 */ 325 public List<Item> getItems(boolean visible) { 316 public List<Item> getItems(boolean visible) 317 { 326 318 if (!_sorted) { 327 for(int i = 0; i < _body.size();) 328 if(_body.get(i) == null) _body.remove(i); 329 else i++; 319 for(int i = 0; i < _body.size();) { 320 if(_body.get(i) == null) { 321 _body.remove(i); 322 } else { 323 i++; 324 } 325 } 330 326 Collections.sort(_body); 331 327 _sorted = true; … … 335 331 336 332 for (Item i : _body) { 337 if (i == null) 338 continue;333 if (i == null) continue; 334 339 335 if (i.isVisible() || (!visible && !i.isDeleted())) { 340 336 items.add(i); … … 345 341 } 346 342 347 public List<Item> getItems() { 343 /** TODO: Comment. cts16 */ 344 public List<Item> getItems() 345 { 348 346 return getItems(false); 349 347 } … … 354 352 * @return True if this frame contains i. 355 353 */ 356 public boolean containsItem(Item i) { 357 if (i == null) 358 throw new NullPointerException("i"); 354 public boolean containsItem(Item i) 355 { 356 if (i == null) throw new NullPointerException("i"); 357 359 358 return _body.contains(i); 360 359 } … … 372 371 * @return the list of body text items. 373 372 */ 374 public List<Text> getBodyTextItems(boolean includeAnnotations) { 373 public List<Text> getBodyTextItems(boolean includeAnnotations) 374 { 375 375 List<Text> bodyTextItems = new ArrayList<Text>(); 376 376 377 for (Item i : getItems(true)) { 377 378 // only add up normal body text items 378 if ((i instanceof Text) 379 && ((includeAnnotations && !((Text) i) 380 .isSpecialAnnotation()) || !i.isAnnotation()) 381 && !i.isLineEnd()) { 379 if ((i instanceof Text) && ((includeAnnotations && !((Text) i).isSpecialAnnotation()) || !i.isAnnotation()) && !i.isLineEnd()) { 382 380 bodyTextItems.add((Text) i); 383 381 } 384 382 } 383 385 384 bodyTextItems.remove(getTitleItem()); 386 385 … … 388 387 } 389 388 390 public Collection<Item> getNonAnnotationItems(boolean removeTitle) { 389 public Collection<Item> getNonAnnotationItems(boolean removeTitle) 390 { 391 391 Collection<Item> items = new ArrayList<Item>(); 392 392 for (Item i : getItems(true)) { 393 393 // only add up normal body text items 394 if (!i.isAnnotation()) { 395 items.add(i); 396 } 397 } 394 if (!i.isAnnotation()) items.add(i); 395 } 396 398 397 if (removeTitle) { 399 398 items.remove(getTitleItem()); 400 399 } 400 401 401 return items; 402 402 } … … 408 408 * @return the last non annotation text item. 409 409 */ 410 public Item getLastNonAnnotationTextItem() { 410 public Item getLastNonAnnotationTextItem() 411 { 411 412 List<Item> items = getItems(); 412 413 … … 431 432 * found. 432 433 */ 433 public Item getItemWithID(int id) { 434 for (Item i : _body) 435 if (i.getID() == id) 434 public Item getItemWithID(int id) 435 { 436 for (Item i : _body) { 437 if (i.getID() == id) { 436 438 return i; 437 439 } 440 } 438 441 return null; 439 442 } … … 445 448 * The title to assign to this Frame 446 449 */ 447 public void setTitle(String title) {448 if (title == null || title.equals(""))449 450 public void setTitle(String title) 451 { 452 if (title == null || title.equals("")) return; 450 453 451 454 boolean oldchange = _change; … … 476 479 // title = ItemUtils.StripTagSymbol(title); 477 480 frameTitle.setText(title); 478 // If the @ symbol is followed by numbering or a bullet remove that 479 // too 480 String autoBulletText = FrameKeyboardActions.getAutoBullet(title); 481 // If the @ symbol is followed by numbering or a bullet remove that too 482 String autoBulletText = StandardGestureActions.getAutoBullet(title); 481 483 if (autoBulletText.length() > 0) 482 484 frameTitle.stripFirstWord(); … … 485 487 // Brook: Cannot figure what is going on above... widget annot titles 486 488 // should be stripped always 487 if (ItemUtils.startsWithTag(frameTitle, ItemUtils 488 .GetTag(ItemUtils.TAG_IWIDGET))) { 489 if (ItemUtils.startsWithTag(frameTitle, ItemUtils.GetTag(ItemUtils.TAG_IWIDGET))) { 489 490 frameTitle.stripFirstWord(); 490 491 } … … 496 497 } 497 498 498 public Text getTitleItem() { 499 public Text getTitleItem() 500 { 499 501 List<Item> items = getVisibleItems(); 502 500 503 for (Item i : items) { 501 if (i instanceof Text && i.getX() < UserSettings.TitlePosition.get() 502 && i.getY() < UserSettings.TitlePosition.get()) 504 if (i instanceof Text && i.getX() < UserSettings.TitlePosition.get() && i.getY() < UserSettings.TitlePosition.get()) { 503 505 return (Text) i; 506 } 504 507 } 505 508 … … 507 510 } 508 511 509 public String getTitle() { 512 public String getTitle() 513 { 510 514 Text title = getTitleItem(); 511 if (title == null) 512 return getName(); 515 if (title == null) return getName(); 513 516 514 517 return title.getFirstLine(); 515 518 } 516 519 517 public Item getNameItem() { 520 public Item getNameItem() 521 { 518 522 return _frameName; 519 523 } 520 524 521 public Text getItemTemplate() {522 return getTemplate(TemplateSettings.ItemTemplate.get(),523 524 } 525 526 public Text getAnnotationTemplate() {527 Text t = getTemplate(TemplateSettings.AnnotationTemplate.get(),528 525 public Text getItemTemplate() 526 { 527 return getTemplate(TemplateSettings.ItemTemplate.get(), ItemUtils.TAG_ITEM_TEMPLATE); 528 } 529 530 public Text getAnnotationTemplate() 531 { 532 Text t = getTemplate(TemplateSettings.AnnotationTemplate.get(), ItemUtils.TAG_ANNOTATION_TEMPLATE); 529 533 530 534 if (t == null) { … … 535 539 } 536 540 537 public Text getStatTemplate() { 541 public Text getStatTemplate() 542 { 538 543 SessionStats.CreatedText(); 539 Text t = getTemplate(TemplateSettings.StatTemplate.get(), 540 ItemUtils.TAG_STAT_TEMPLATE); 544 Text t = getTemplate(TemplateSettings.StatTemplate.get(), ItemUtils.TAG_STAT_TEMPLATE); 541 545 542 546 if (t == null) { … … 547 551 } 548 552 549 public Item getTooltipTextItem(String tooltipText) { 553 public Item getTooltipTextItem(String tooltipText) 554 { 550 555 return getTextItem(tooltipText, TemplateSettings.TooltipTemplate.get().copy()); 551 556 } 552 557 553 public Item getStatsTextItem(String itemText) { 558 public Item getStatsTextItem(String itemText) 559 { 554 560 return getTextItem(itemText, getStatTemplate()); 555 561 } 556 562 557 public Item getTextItem(String itemText) { 563 public Item getTextItem(String itemText) 564 { 558 565 return getTextItem(itemText, getItemTemplate()); 559 566 } 560 567 561 private Item getTextItem(String itemText, Text template) { 568 private Item getTextItem(String itemText, Text template) 569 { 562 570 Text t = template; 563 571 // We dont want the stats to wrap at all 564 572 // t.setMaxWidth(Integer.MAX_VALUE); 565 t.setPosition(Display IO.getMouseX(), FrameMouseActions.getY());573 t.setPosition(DisplayController.getMousePosition()); 566 574 // The next line is needed to make sure the item is removed from the 567 575 // frame when picked up … … 571 579 } 572 580 573 public Text getCodeCommentTemplate() {574 Text t = getTemplate(TemplateSettings.CommentTemplate.get(),575 581 public Text getCodeCommentTemplate() 582 { 583 Text t = getTemplate(TemplateSettings.CommentTemplate.get(), ItemUtils.TAG_CODE_COMMENT_TEMPLATE); 576 584 577 585 if (t == null) { … … 592 600 * Item.intersects(shape) return true. 593 601 */ 594 public Collection<Item> getItemsWithin(Polygon poly) { 602 public Collection<Item> getItemsWithin(PolygonBounds poly) 603 { 595 604 Collection<Item> results = new LinkedHashSet<Item>(); 596 605 for (Item i : getVisibleItems()) { … … 606 615 } 607 616 608 for (Overlay o : _overlays.keySet()) 617 for (Overlay o : _overlays.keySet()) { 609 618 results.addAll(o.Frame.getItemsWithin(poly)); 610 619 } 620 611 621 for (Item i : getVectorItems()) { 612 622 if (i.intersects(poly)) { … … 626 636 * The name to use for this Frame. 627 637 */ 628 public void setFrameset(String name) { 638 public void setFrameset(String name) 639 { 629 640 _frameset = name; 630 641 } 631 642 632 public void setName(String framename) { 643 public void setName(String framename) 644 { 633 645 int num = Conversion.getFrameNumber(framename); 634 646 String frameset = Conversion.getFramesetName(framename, false); … … 643 655 * The number to set as the frame number 644 656 */ 645 public void setFrameNumber(int number) { 657 public void setFrameNumber(int number) 658 { 646 659 assert (number >= 0); 647 660 648 if (_number == number) 649 return; 661 if (_number == number) return; 650 662 651 663 _number = number; … … 659 671 id = -1 * getNextItemID(); 660 672 } 673 661 674 _frameName = new Text(id); 662 675 _frameName.setParent(this); … … 671 684 * @return The Frame number of this Frame or -1 if it is not set. 672 685 */ 673 public int getNumber() { 686 public int getNumber() 687 { 674 688 return _number; 675 689 } … … 681 695 * The version to use for this Frame. 682 696 */ 683 public void setVersion(int version) { 697 public void setVersion(int version) 698 { 684 699 _version = version; 685 700 } … … 691 706 * The protection to use for this Frame. 692 707 */ 693 public void setPermission(PermissionPair permission) { 694 if (_permissionPair != null && _permissionPair.getPermission(this._owner).equals(permission)) 708 public void setPermission(PermissionPair permission) 709 { 710 if (_permissionPair != null && _permissionPair.getPermission(this._owner).equals(permission)) { 695 711 _protectionChanged = true; 712 } 696 713 697 714 _permissionPair = new PermissionPair(permission); 698 715 699 if (_body.size() > 0) 700 refreshItemPermissions(permission.getPermission(_owner)); 716 if (_body.size() > 0) refreshItemPermissions(permission.getPermission(_owner)); 701 717 } 702 718 … … 707 723 * The owner to use for this Frame. 708 724 */ 709 public void setOwner(String owner) { 725 public void setOwner(String owner) 726 { 710 727 _owner = owner; 711 728 } … … 717 734 * The date to use for this Frame. 718 735 */ 719 public void setDateCreated(String date) { 736 public void setDateCreated(String date) 737 { 720 738 _creationDate = date; 721 739 _modifiedDate = date; … … 729 747 * 730 748 */ 731 public void resetDateCreated() { 749 public void resetDateCreated() 750 { 732 751 setDateCreated(Formatter.getDateTime()); 733 752 resetTimes(); … … 735 754 } 736 755 737 private void resetTimes() { 756 private void resetTimes() 757 { 738 758 setActiveTime(new Time(0)); 739 759 setDarkTime(new Time(0)); … … 746 766 * The user to set as the last modifying user. 747 767 */ 748 public void setLastModifyUser(String user) { 768 public void setLastModifyUser(String user) 769 { 749 770 _modifiedUser = user; 750 771 } … … 756 777 * The date to set as the last modified date. 757 778 */ 758 public void setLastModifyDate(String date) { 779 public void setLastModifyDate(String date) 780 { 759 781 _modifiedDate = date; 760 782 } … … 766 788 * The date to set as the last frozen date. 767 789 */ 768 public void setFrozenDate(String date) { 790 public void setFrozenDate(String date) 791 { 769 792 _frozenDate = date; 770 793 } 771 794 772 public void setResort(boolean value) { 795 public void setResort(boolean value) 796 { 773 797 _sorted = !value; 774 798 } … … 780 804 * The Item to add to this Frame. 781 805 */ 782 public void addItem(Item item) { 806 public void addItem(Item item) 807 { 783 808 addItem(item, true); 784 809 } 785 810 786 public void addItem(Item item, boolean recalculate) {787 if (item == null || item.equals(_frameName) || _body.contains(item))788 811 public void addItem(Item item, boolean recalculate) 812 { 813 if (item == null || item.equals(_frameName) || _body.contains(item)) return; 789 814 790 815 // When an annotation item is anchored the annotation list must be … … 794 819 } 795 820 796 if (item instanceof Line) 797 _lineCount++; 821 if (item instanceof Line) _lineCount++; 798 822 799 823 _itemCount = Math.max(_itemCount, item.getID()); … … 816 840 // add widget items to the list of widgets 817 841 if (item instanceof WidgetCorner) { 818 InteractiveWidget iw = ((WidgetCorner) item).getWidgetSource();842 Widget iw = ((WidgetCorner) item).getWidgetSource(); 819 843 if (!this._iWidgets.contains(iw)) { // A set would have been 820 if ( FrameMouseActions.isControlDown())844 if (StandardInputEventListeners.kbmStateListener.isKeyDown(Key.CTRL)) { 821 845 _iWidgets.add(iw); 822 else846 } else { 823 847 _iWidgets.add(0, iw); 824 }825 }826 827 item.onParentStateChanged(new ItemParentStateChangedEvent(this, 828 848 } 849 } 850 } 851 852 item.onParentStateChanged(new ItemParentStateChangedEvent(this, ItemParentStateChangedEvent.EVENT_TYPE_ADDED)); 829 853 830 854 // if (recalculate && item.recalculateWhenChanged()) … … 834 858 } 835 859 836 public void refreshSize() {837 // assert (size != null);860 public void refreshSize() 861 { 838 862 boolean bReparse = false; 863 839 864 for (Item i : getItems()) { 840 FloatanchorLeft = i.getAnchorLeft();841 FloatanchorRight = i.getAnchorRight();842 FloatanchorTop = i.getAnchorTop();843 FloatanchorBottom = i.getAnchorBottom();865 Integer anchorLeft = i.getAnchorLeft(); 866 Integer anchorRight = i.getAnchorRight(); 867 Integer anchorTop = i.getAnchorTop(); 868 Integer anchorBottom = i.getAnchorBottom(); 844 869 845 870 … … 885 910 } 886 911 887 public void addAllItems(Collection<Item> toAdd) { 912 public void addAllItems(Collection<Item> toAdd) 913 { 888 914 for (Item i : toAdd) { 889 915 // If an annotation is being deleted clear the annotation list 890 if (i.isAnnotation()) 891 i.getParentOrCurrentFrame().clearAnnotations(); 916 if (i.isAnnotation()) i.getParentOrCurrentFrame().clearAnnotations(); 892 917 // TODO Improve efficiency when addAll is called 893 918 addItem(i); … … 895 920 } 896 921 897 public void removeAllItems(Collection<Item> toRemove) { 922 public void removeAllItems(Collection<Item> toRemove) 923 { 898 924 for (Item i : toRemove) { 899 925 // If an annotation is being deleted clear the annotation list 900 if (i.isAnnotation()) 901 i.getParentOrCurrentFrame().clearAnnotations(); 926 if (i.isAnnotation()) i.getParentOrCurrentFrame().clearAnnotations(); 902 927 removeItem(i); 903 928 } 904 929 } 905 930 906 public void removeItem(Item item) { 931 public void removeItem(Item item) 932 { 907 933 removeItem(item, true); 908 934 } 909 935 910 public void removeItem(Item item, boolean recalculate) { 936 public void removeItem(Item item, boolean recalculate) 937 { 911 938 // If an annotation is being deleted clear the annotation list 912 if (item.isAnnotation()) 913 item.getParentOrCurrentFrame().clearAnnotations(); 939 if (item.isAnnotation()) item.getParentOrCurrentFrame().clearAnnotations(); 914 940 915 941 if (_body.remove(item)) { … … 917 943 // Remove widgets from the widget list 918 944 if (item != null) { 919 item.onParentStateChanged(new ItemParentStateChangedEvent(this, 920 ItemParentStateChangedEvent.EVENT_TYPE_REMOVED));945 item.onParentStateChanged(new ItemParentStateChangedEvent(this, ItemParentStateChangedEvent.EVENT_TYPE_REMOVED)); 946 921 947 if (item instanceof WidgetCorner) { 922 948 _iWidgets.remove(((WidgetCorner) item).getWidgetSource()); 923 949 } 950 924 951 item.invalidateCommonTrait(ItemAppearence.Removed); 925 952 } … … 937 964 * @param type The type of event that occurred 938 965 */ 939 private void addToUndo(Collection<Item> items, History.Type type) { 940 if (items.size() < 1) 941 return; 942 943 // System.out.println("Added: " + items); 966 private void addToUndo(Collection<Item> items, History.Type type) 967 { 968 if (items.size() < 1) return; 944 969 945 970 _undo.push(new History(items, type)); 946 971 } 947 972 948 public void addToUndoDelete(Collection<Item> items) { 973 public void addToUndoDelete(Collection<Item> items) 974 { 949 975 addToUndo(items, History.Type.deletion); 950 976 } 951 public void addToUndoMove(Collection<Item> items) { 977 978 public void addToUndoMove(Collection<Item> items) 979 { 952 980 addToUndo(items, History.Type.movement); 953 981 } 954 982 955 public void undo() { 983 public void undo() 984 { 956 985 boolean bReparse = false; 957 986 boolean bRecalculate = false; 958 987 959 if (_undo.size() <= 0) 960 return; 988 if (_undo.size() <= 0) return; 961 989 962 990 History undo = _undo.pop(); … … 992 1020 break; 993 1021 } 1022 994 1023 change(); 995 FrameMouseActions.getInstance().refreshHighlights(); 1024 1025 StandardGestureActions.refreshHighlights(); 1026 996 1027 if (bReparse) { 997 1028 FrameUtils.Parse(this, false, false); … … 999 1030 notifyObservers(bRecalculate); 1000 1031 } 1032 1001 1033 // always request a refresh otherwise filled shapes 1002 1034 // that were broken by a deletion and then reconnected by the undo 1003 1035 // don't get filled until the user otherwise causes them to redraw 1004 FrameGraphics.requestRefresh(false); 1005 FrameGraphics.Repaint(); 1036 DisplayController.requestRefresh(false); 1006 1037 // ItemUtils.EnclosedCheck(_body); 1007 1038 ItemUtils.Justify(this); 1008 1039 } 1009 1040 1010 public void redo() { 1041 public void redo() 1042 { 1011 1043 boolean bReparse = false; 1012 1044 boolean bRecalculate = false; 1013 1045 1014 if (_redo.size() <= 0) 1015 return; 1046 if (_redo.size() <= 0) return; 1016 1047 1017 1048 History redo = _redo.pop(); … … 1047 1078 break; 1048 1079 } 1080 1049 1081 change(); 1050 FrameMouseActions.getInstance().refreshHighlights(); 1082 1083 StandardGestureActions.refreshHighlights(); 1084 1051 1085 if (bReparse) { 1052 1086 FrameUtils.Parse(this, false, false); … … 1054 1088 notifyObservers(bRecalculate); 1055 1089 } 1090 1056 1091 // always request a refresh otherwise filled shapes 1057 1092 // that were broken by a deletion and then reconnected by the undo 1058 1093 // don't get filled until the user otherwise causes them to redraw 1059 FrameGraphics.requestRefresh(false); 1060 FrameGraphics.Repaint(); 1094 DisplayController.requestRefresh(false); 1061 1095 // ItemUtils.EnclosedCheck(_body); 1062 1096 ItemUtils.Justify(this); … … 1068 1102 * @return The name of this Frame's frameset. 1069 1103 */ 1070 public String getFramesetName() { 1104 public String getFramesetName() 1105 { 1071 1106 return _frameset; 1072 1107 } 1073 1108 1074 public String getName() { 1109 public String getName() 1110 { 1075 1111 return getFramesetName() + _number; 1076 1112 } … … 1081 1117 * @return The version of this Frame. 1082 1118 */ 1083 public int getVersion() { 1119 public int getVersion() 1120 { 1084 1121 return _version; 1085 1122 } 1086 1123 1087 public PermissionPair getPermission() { 1124 public PermissionPair getPermission() 1125 { 1088 1126 return _permissionPair; 1089 1127 } 1090 1128 1091 public UserAppliedPermission getUserAppliedPermission() { 1129 public UserAppliedPermission getUserAppliedPermission() 1130 { 1092 1131 return getUserAppliedPermission(UserAppliedPermission.full); 1093 1132 } 1094 1133 1095 public UserAppliedPermission getUserAppliedPermission(UserAppliedPermission defaultPermission) {1096 if (_permissionPair == null)1097 1134 public UserAppliedPermission getUserAppliedPermission(UserAppliedPermission defaultPermission) 1135 { 1136 if (_permissionPair == null) return defaultPermission; 1098 1137 1099 1138 return _permissionPair.getPermission(_owner); 1100 1139 } 1101 1140 1102 1103 public String getOwner(){1141 public String getOwner() 1142 { 1104 1143 return _owner; 1105 1144 } 1106 1145 1107 public String getDateCreated() { 1146 public String getDateCreated() 1147 { 1108 1148 return _creationDate; 1109 1149 } 1110 1150 1111 public String getLastModifyUser() { 1151 public String getLastModifyUser() 1152 { 1112 1153 return _modifiedUser; 1113 1154 } 1114 1155 1115 public String getLastModifyDate() { 1156 public String getLastModifyDate() 1157 { 1116 1158 return _modifiedDate; 1117 1159 } 1118 1160 1119 public String getFrozenDate() { 1161 public String getFrozenDate() 1162 { 1120 1163 return _frozenDate; 1121 1164 } 1122 1165 1123 public void setBackgroundColor(Color back) { 1166 public void setBackgroundColor(Colour back) 1167 { 1124 1168 _background = back; 1169 1125 1170 change(); 1126 1171 1127 if (this == DisplayIO.getCurrentFrame()) { 1128 FrameGraphics.refresh(false); 1129 } 1130 } 1131 1132 public Color getBackgroundColor() { 1172 if (this == DisplayController.getCurrentFrame()) { 1173 DisplayController.requestRefresh(false); 1174 } 1175 } 1176 1177 public Colour getBackgroundColor() 1178 { 1133 1179 return _background; 1134 1180 } 1135 1181 1136 public Color getPaintBackgroundColor() { 1182 public Colour getPaintBackgroundColor() 1183 { 1137 1184 // If null... return white 1138 1185 if (_background == null) { … … 1143 1190 } 1144 1191 1145 public void setForegroundColor(Color front) { 1192 public void setForegroundColor(Colour front) 1193 { 1146 1194 _foreground = front; 1195 1147 1196 change(); 1148 // FrameGraphics.Repaint();1149 } 1150 1151 public Color getForegroundColor(){1197 } 1198 1199 public Colour getForegroundColor() 1200 { 1152 1201 return _foreground; 1153 1202 } 1154 1203 1155 public Color getPaintForegroundColor() { 1156 final int GRAY = Color.gray.getBlue(); 1157 final int THRESHOLD = 10; 1204 public Colour getPaintForegroundColor() 1205 { 1206 final int GRAY = Colour.GREY.getBlue(); 1207 final int THRESHOLD = Colour.FromComponent255(10); 1158 1208 1159 1209 if (_foreground == null) { 1160 Colo r back = getPaintBackgroundColor();1210 Colour back = getPaintBackgroundColor(); 1161 1211 if (Math.abs(back.getRed() - GRAY) < THRESHOLD 1162 1212 && Math.abs(back.getBlue() - GRAY) < THRESHOLD 1163 1213 && Math.abs(back.getGreen() - GRAY) < THRESHOLD) 1164 return Color.WHITE;1165 1166 Color fore = new Color(1167 Math.abs(Conversion.RGB_MAX - back.getRed()), Math1168 .abs(Conversion.RGB_MAX - back.getGreen()), Math1169 .abs(Conversion.RGB_MAX - back.getBlue()));1214 { 1215 return Colour.WHITE; 1216 } 1217 1218 Colour fore = back.inverse(); 1219 1170 1220 return fore; 1171 1221 } … … 1174 1224 } 1175 1225 1176 public String toString() { 1226 public String toString() 1227 { 1177 1228 StringBuilder s = new StringBuilder(); 1178 1229 s.append(String.format("Name: %s%d%n", _frameset, _number)); … … 1187 1238 } 1188 1239 1189 public Text getTextAbove(Text current) { 1240 public Text getTextAbove(Text current) 1241 { 1190 1242 Collection<Text> currentTextItems = FrameUtils.getCurrentTextItems(); 1191 1243 List<Text> toCheck = new ArrayList<Text>(); 1244 1192 1245 if (currentTextItems.contains(current)) { 1193 1246 toCheck.addAll(currentTextItems); … … 1195 1248 toCheck.addAll(getTextItems()); 1196 1249 } 1250 1197 1251 // Make sure the items are sorted 1198 1252 Collections.sort(toCheck); 1199 1253 1200 1254 int ind = toCheck.indexOf(current); 1201 if (ind == -1) 1202 return null; 1255 if (ind == -1) return null; 1203 1256 1204 1257 // loop through all items above this one, return the first match 1205 1258 for (int i = ind - 1; i >= 0; i--) { 1206 1259 Text check = toCheck.get(i); 1207 if (FrameUtils.inSameColumn(check, current)) 1208 return check; 1260 if (FrameUtils.inSameColumn(check, current)) return check; 1209 1261 } 1210 1262 1211 1263 return null; 1212 1264 } 1213 1214 /** 1215 * Updates any Images that require it from their ImageObserver (Principally 1216 * Animated GIFs) 1217 */ 1218 public boolean imageUpdate(Image img, int infoflags, int x, int y, 1219 int width, int height) { 1220 FrameGraphics.ForceRepaint(); 1221 1222 if (DisplayIO.getCurrentFrame() == this) 1223 return true; 1224 1225 return false; 1226 } 1227 1265 1228 1266 /** 1229 1267 * Gets the text items that are in the same column and below a specified … … 1233 1271 * The Item to get the column for. 1234 1272 */ 1235 public List<Text> getColumn(Item from) { 1273 public List<Text> getColumn(Item from) 1274 { 1236 1275 // Check that this item is on the current frame 1237 if (!_body.contains(from)) 1238 return null; 1276 if (!_body.contains(from)) return null; 1239 1277 1240 1278 if (from == null) { … … 1242 1280 } 1243 1281 1244 if (from == null) 1245 return null; 1282 if (from == null) return null; 1246 1283 1247 1284 // Get the enclosedItems 1248 1285 Collection<Text> enclosed = FrameUtils.getCurrentTextItems(); 1249 1286 List<Text> toCheck = null; 1287 1250 1288 if (enclosed.contains(from)) { 1251 1289 toCheck = new ArrayList<Text>(); … … 1256 1294 1257 1295 List<Text> column = new ArrayList<Text>(); 1296 1258 1297 if (toCheck.size() > 0) { 1259 1260 1298 // Make sure the items are sorted 1261 1299 Collections.sort(toCheck); … … 1266 1304 1267 1305 // If its the title index will be 0 1268 if (index < 0) 1269 index = 0; 1306 if (index < 0) index = 0; 1270 1307 1271 1308 for (int i = index; i < toCheck.size(); i++) { 1272 1309 Text item = toCheck.get(i); 1273 if (FrameUtils.inSameColumn(from, item)) 1274 column.add(item); 1310 if (FrameUtils.inSameColumn(from, item)) column.add(item); 1275 1311 } 1276 1312 } … … 1289 1325 * If overlay is null. 1290 1326 */ 1291 protected boolean addVector(Vector toAdd) { 1327 protected boolean addVector(Vector toAdd) 1328 { 1292 1329 // make sure we dont add this frame as an overlay of itself 1293 if (toAdd.Frame == this) 1294 return false;1330 if (toAdd.Frame == this) return false; 1331 1295 1332 _vectors.add(toAdd); 1333 1296 1334 // Items must be notified that they have been added or removed from this 1297 1335 // frame via the vector... 1298 1336 int maxX = 0; 1299 1337 int maxY = 0; 1338 1300 1339 HighlightMode mode = toAdd.Source.getHighlightMode(); 1301 if (mode != HighlightMode.None) 1302 mode = HighlightMode.Connected; 1303 Color highlightColor = toAdd.Source.getHighlightColor(); 1340 if (mode != HighlightMode.None) mode = HighlightMode.Connected; 1341 1342 Colour highlightColor = toAdd.Source.getHighlightColor(); 1343 1304 1344 for (Item i : ItemUtils.CopyItems(toAdd.Frame.getVectorItems(), toAdd)) { 1305 i.onParentStateChanged(new ItemParentStateChangedEvent(this, 1306 ItemParentStateChangedEvent.EVENT_TYPE_ADDED_VIA_OVERLAY, 1307 toAdd.permission)); 1345 i.onParentStateChanged(new ItemParentStateChangedEvent(this, ItemParentStateChangedEvent.EVENT_TYPE_ADDED_VIA_OVERLAY, toAdd.permission)); 1308 1346 i.setEditTarget(toAdd.Source); 1309 i.setHighlightMode (mode, highlightColor);1347 i.setHighlightModeAndColour(mode, highlightColor); 1310 1348 _vectorItems.add(i); 1311 1349 i.invalidateAll(); 1312 1350 i.invalidateFill(); 1351 1313 1352 // Get the right most x and bottom most y pos 1314 1353 int itemRight = i.getX() + i.getBoundsWidth(); 1315 if (itemRight > maxX) 1316 maxX = itemRight;1354 if (itemRight > maxX) maxX = itemRight; 1355 1317 1356 int itemBottom = i.getY() + i.getBoundsHeight(); 1318 if (itemBottom > maxY) 1319 maxY = itemBottom;1320 }1357 if (itemBottom > maxY) maxY = itemBottom; 1358 } 1359 1321 1360 toAdd.setSize(maxX, maxY); 1361 1322 1362 return true; 1323 1363 } 1324 1364 1325 public Collection<Vector> getVectors() { 1365 public Collection<Vector> getVectors() 1366 { 1326 1367 Collection<Vector> l = new LinkedList<Vector>(); 1327 1368 l.addAll(_vectors); … … 1329 1370 } 1330 1371 1331 public Collection<Overlay> getOverlays() { 1372 public Collection<Overlay> getOverlays() 1373 { 1332 1374 return new LinkedList<Overlay>(_overlays.keySet()); 1333 1375 } 1334 1376 1335 1377 /** 1336 * @return All vectosr seen by this frame (including its vector's vectors). 1337 */ 1338 public List<Vector> getVectorsDeep() { 1378 * @return All vectors seen by this frame (including its vector's vectors). 1379 */ 1380 public List<Vector> getVectorsDeep() 1381 { 1339 1382 List<Vector> l = new LinkedList<Vector>(); 1340 1383 getVectorsDeep(l, this, new LinkedList<Frame>()); … … 1342 1385 } 1343 1386 1344 private boolean getVectorsDeep(List<Vector> vectors, Frame vector, 1345 List<Frame> seenVectors) { 1346 1347 if (seenVectors.contains(vector)) 1348 return false; 1387 private boolean getVectorsDeep(List<Vector> vectors, Frame vector, List<Frame> seenVectors) 1388 { 1389 if (seenVectors.contains(vector)) return false; 1349 1390 1350 1391 seenVectors.add(vector); 1351 1392 1352 for (Vector o: vector.getVectors()) {1353 if (getVectorsDeep(vectors, o.Frame, seenVectors)) {1354 vectors.add( o);1393 for (Vector v : vector.getVectors()) { 1394 if (getVectorsDeep(vectors, v.Frame, seenVectors)) { 1395 vectors.add(v); 1355 1396 } 1356 1397 } … … 1359 1400 } 1360 1401 1361 // private boolean getOverlaysDeep(List<Overlay> overlays, Frame overlay, 1362 // List<Frame> seenOverlays) { 1363 // 1364 // if (seenOverlays.contains(overlay)) 1365 // return false; 1366 // 1367 // seenOverlays.add(overlay); 1368 // 1369 // for (Overlay o : overlay.getOverlays()) { 1370 // if (getOverlaysDeep(overlays, o.Frame, seenOverlays)) { 1371 // overlays.add(o); 1372 // } 1373 // } 1374 // 1375 // return true; 1376 // } 1402 public List<Overlay> getOverlaysDeep() 1403 { 1404 List<Overlay> ret = new LinkedList<Overlay>(); 1405 1406 getOverlaysDeep(ret, new LinkedList<Frame>()); 1407 1408 return ret; 1409 } 1410 1411 private boolean getOverlaysDeep(List<Overlay> overlays, List<Frame> seenOverlays) 1412 { 1413 if (seenOverlays.contains(this)) return false; 1414 1415 seenOverlays.add(this); 1416 1417 for (Overlay o : this.getOverlays()) { 1418 if (o.Frame.getOverlaysDeep(overlays, seenOverlays)) { 1419 overlays.add(o); 1420 } 1421 } 1422 return true; 1423 } 1424 1425 /** 1426 * Recursive function similar to AddAllOverlayItems. 1427 * 1428 * @param widgets 1429 * The collection the widgets will be added to 1430 * @param overlay 1431 * An "overlay" frame - this initially will be the parent frame 1432 * @param seenOverlays 1433 * Used for state in the recursion stack. Pass as an empty 1434 * (non-null) list. 1435 */ 1436 public List<Widget> getAllOverlayWidgets() 1437 { 1438 List<Widget> widgets = new LinkedList<Widget>(); 1439 1440 for (Overlay o : getOverlaysDeep()) widgets.addAll(o.Frame.getInteractiveWidgets()); 1441 1442 return widgets; 1443 } 1377 1444 1378 1445 /** … … 1381 1448 * @param item 1382 1449 * The item - must not be null. 1383 * @return The overlay that contains the it m. Null if no overlay owns the1450 * @return The overlay that contains the item. Null if no overlay owns the 1384 1451 * item. 1385 1452 */ 1386 public Overlay getOverlayOwner(Item item) {1387 if (item == null)1388 1453 public Overlay getOverlayOwner(Item item) 1454 { 1455 if (item == null) throw new NullPointerException("item"); 1389 1456 1390 1457 for (Overlay l : getOverlays()) { 1391 if (item.getParent() == l.Frame) 1392 return l; 1458 if (item.getParent() == l.Frame) return l; 1393 1459 } 1394 1460 1395 1461 // TODO return the correct vector... not just the first vector matching 1396 // the vector Frame1462 // the vector frame 1397 1463 for (Vector v : getVectors()) { 1398 if (item.getParent() == v.Frame) 1399 return v; 1464 if (item.getParent() == v.Frame) return v; 1400 1465 } 1401 1466 … … 1403 1468 } 1404 1469 1405 public void clearVectors() { 1470 public void clearVectors() 1471 { 1406 1472 _vectors.clear(); 1407 1473 … … 1414 1480 } 1415 1481 1416 protected boolean removeVector(Vector toRemove) { 1417 if (!_vectors.remove(toRemove)) 1418 return false; 1482 protected boolean removeVector(Vector toRemove) 1483 { 1484 if (!_vectors.remove(toRemove)) return false; 1485 1419 1486 for (Item i : toRemove.Frame.getVectorItems()) { 1420 1487 i.invalidateAll(); … … 1426 1493 1427 1494 } 1495 1428 1496 return true; 1429 1497 } 1430 1498 1431 public void clearOverlays() { 1499 public void clearOverlays() 1500 { 1432 1501 for (Overlay o : _overlays.keySet()) { 1433 1502 for (Item i : o.Frame.getItems()) { 1434 i 1435 .onParentStateChanged(new ItemParentStateChangedEvent( 1503 i.onParentStateChanged(new ItemParentStateChangedEvent( 1436 1504 this, 1437 1505 ItemParentStateChangedEvent.EVENT_TYPE_REMOVED_VIA_OVERLAY, … … 1444 1512 } 1445 1513 1446 protected boolean removeOverlay(Frame f) { 1514 protected boolean removeOverlay(Frame f) 1515 { 1447 1516 for (Overlay o : _overlays.keySet()) { 1448 1517 if (o.Frame == f) { 1449 1518 _overlays.remove(o); 1519 1450 1520 for (Item i : f.getItems()) { 1451 1521 _overlayItems.remove(i); 1452 i 1453 .onParentStateChanged(new ItemParentStateChangedEvent( 1522 i.onParentStateChanged(new ItemParentStateChangedEvent( 1454 1523 this, 1455 1524 ItemParentStateChangedEvent.EVENT_TYPE_REMOVED_VIA_OVERLAY, 1456 1525 o.permission)); 1457 1526 } 1527 1458 1528 return true; 1459 1529 } 1460 1530 } 1531 1461 1532 return false; 1462 1533 } 1463 1534 1464 public void addAllVectors(List<Vector> vectors) { 1535 public void addAllVectors(List<Vector> vectors) 1536 { 1465 1537 for (Vector v : vectors) { 1466 1538 addVector(v); … … 1468 1540 } 1469 1541 1470 public void addAllOverlays(Collection<Overlay> overlays) { 1542 public void addAllOverlays(Collection<Overlay> overlays) 1543 { 1471 1544 for (Overlay o : overlays) { 1472 1545 addOverlay(o); … … 1474 1547 } 1475 1548 1476 protected boolean addOverlay(Overlay toAdd) { 1549 protected boolean addOverlay(Overlay toAdd) 1550 { 1477 1551 // make sure we dont add this frame as an overlay of itself 1478 if (toAdd.Frame == this) 1479 return false;1552 if (toAdd.Frame == this) return false; 1553 1480 1554 // Dont add the overlay if there is already one for this frame 1481 if (_overlays.values().contains(toAdd.Frame)) 1482 return false;1555 if (_overlays.values().contains(toAdd.Frame)) return false; 1556 1483 1557 // Add the overlay to the map of overlays on this frame 1484 1558 _overlays.put(toAdd, toAdd.Frame); 1559 1485 1560 // Add all the overlays from the overlay frame to this frame 1486 for (Overlay o : toAdd.Frame.getOverlays())1487 1561 // TODO: Can this cause a recursion loop? If A and B are overlays of each other? cts16 1562 for (Overlay o : toAdd.Frame.getOverlays()) addOverlay(o); 1488 1563 1489 1564 // Add all the vectors from the overlay frame to this frame 1490 for (Vector v : toAdd.Frame.getVectors()) 1491 addVector(v); 1565 for (Vector v : toAdd.Frame.getVectors()) addVector(v); 1492 1566 1493 1567 // Now add the items for this overlay 1494 UserAppliedPermission permission = UserAppliedPermission.min(toAdd.Frame.getUserAppliedPermission(), toAdd.permission);1568 UserAppliedPermission permission = UserAppliedPermission.min(toAdd.Frame.getUserAppliedPermission(), toAdd.permission); 1495 1569 1496 1570 // Items must be notified that they have been added or removed from this 1497 1571 // frame via the overlay... 1498 1572 for (Item i : toAdd.Frame.getVisibleItems()) { 1499 i.onParentStateChanged(new ItemParentStateChangedEvent(this, 1500 ItemParentStateChangedEvent.EVENT_TYPE_ADDED_VIA_OVERLAY, 1501 permission)); 1502 // i.setPermission(permission); 1573 i.onParentStateChanged(new ItemParentStateChangedEvent(this, ItemParentStateChangedEvent.EVENT_TYPE_ADDED_VIA_OVERLAY, permission)); 1503 1574 _overlayItems.add(i); 1504 1575 } … … 1508 1579 1509 1580 @Override 1510 public boolean equals(Object o) { 1581 public boolean equals(Object o) 1582 { 1511 1583 if (o instanceof String) { 1512 return (String.CASE_INSENSITIVE_ORDER 1513 .compare((String) o, getName()) == 0); 1584 return (String.CASE_INSENSITIVE_ORDER.compare((String) o, getName()) == 0); 1514 1585 } 1515 1586 … … 1526 1597 * @param toMergeWith 1527 1598 */ 1528 private void merge(Frame toMergeWith) {1529 if (toMergeWith == null)1530 1599 private void merge(Frame toMergeWith) 1600 { 1601 if (toMergeWith == null) return; 1531 1602 1532 1603 List<Item> copies = ItemUtils.CopyItems(toMergeWith.getItems()); … … 1548 1619 * @return the items that cant be merged 1549 1620 */ 1550 public List<Item> merge(List<Item> toMerge) { 1621 public List<Item> merge(List<Item> toMerge) 1622 { 1551 1623 ArrayList<Item> remain = new ArrayList<Item>(0); 1552 1624 1553 1625 for (Item i : toMerge) { 1554 if (!(i instanceof Text)) 1626 if (!(i instanceof Text)) { 1555 1627 remain.add(i); 1556 else {1628 } else { 1557 1629 if (!AttributeUtils.setAttribute(this, (Text) i)) { 1558 if (i.getLink() != null) 1630 if (i.getLink() != null) { 1559 1631 merge(FrameIO.LoadFrame(i.getAbsoluteLink())); 1560 else if (FrameIO 1561 .isValidFrameName(((Text) i).getFirstLine())) { 1632 } else if (FrameIO.isValidFrameName(((Text) i).getFirstLine())) { 1562 1633 // If we get hear we are merging frames 1563 1634 merge(FrameIO.LoadFrame(((Text) i).getFirstLine())); … … 1574 1645 * items are added to the backup-stack. 1575 1646 */ 1576 public void clear(boolean keepAnnotations) { 1647 public void clear(boolean keepAnnotations) 1648 { 1577 1649 List<Item> newBody = new ArrayList<Item>(0); 1650 1578 1651 Item title = getTitleItem(); 1652 1579 1653 if (title != null) { 1580 1654 newBody.add(title); 1581 1655 _body.remove(title); 1582 1656 } 1657 1583 1658 if (keepAnnotations) { 1584 1659 for (Item i : _body) { 1585 if (i.isAnnotation()) 1586 newBody.add(i);1587 1588 }1660 if (i.isAnnotation()) newBody.add(i); 1661 } 1662 } 1663 1589 1664 _body.removeAll(newBody); 1590 1665 addToUndoDelete(_body); … … 1592 1667 change(); 1593 1668 1594 if (!keepAnnotations && _annotations != null) 1595 _annotations.clear(); 1669 if (!keepAnnotations && _annotations != null) _annotations.clear(); 1596 1670 } 1597 1671 … … 1602 1676 * @return 1603 1677 */ 1604 public Text createNewText(String text) { 1678 public Text createNewText(String text) 1679 { 1605 1680 Text t = createBlankText(text); 1606 1681 t.setText(text); … … 1615 1690 * @return The newly created Text Item 1616 1691 */ 1617 public Text createBlankText(String templateType) { 1692 public Text createBlankText(String templateType) 1693 { 1618 1694 SessionStats.CreatedText(); 1619 1695 Text t; 1620 if (templateType.length() == 0) 1696 1697 if (templateType.length() == 0) { 1621 1698 t = getItemTemplate().copy(); 1622 else1699 } else { 1623 1700 t = getItemTemplate(templateType.charAt(0)); 1624 1701 } 1702 1625 1703 // reset attributes 1626 1704 t.setID(getNextItemID()); 1627 t.setPosition(Display IO.getMouseX(), FrameMouseActions.getY());1705 t.setPosition(DisplayController.getMousePosition()); 1628 1706 t.setText(""); 1629 1707 t.setParent(this); … … 1648 1726 } 1649 1727 1650 public Item createDot() {1651 Item dot = new Dot(DisplayIO.getMouseX(), FrameMouseActions.getY(),1652 1728 public Item createDot() 1729 { 1730 Item dot = new Dot(DisplayController.getMouseX(), DisplayController.getMouseY(), getNextItemID()); 1653 1731 1654 1732 Item template = getTemplate(_dotTemplate, ItemUtils.TAG_DOT_TEMPLATE); 1655 1733 float thickness = template.getThickness(); 1656 if (thickness > 0) 1657 dot.setThickness(template.getThickness()); 1658 if (template.getLinePattern() != null) 1659 dot.setLinePattern(template.getLinePattern()); 1734 if (thickness > 0) dot.setThickness(template.getThickness()); 1735 if (template.getLinePattern() != null) dot.setLinePattern(template.getLinePattern()); 1660 1736 dot.setColor(template.getColor()); 1661 1737 dot.setFillColor(template.getFillColor()); … … 1665 1741 } 1666 1742 1667 private Text getTemplate(Text defaultTemplate, int templateTag) { 1743 private Text getTemplate(Text defaultTemplate, int templateTag) 1744 { 1668 1745 Text t = null; 1669 1746 … … 1677 1754 1678 1755 if (t == null) { 1679 if (defaultTemplate == null) { 1680 return null; 1681 } 1756 if (defaultTemplate == null) return null; 1757 1682 1758 t = defaultTemplate; 1683 1759 } … … 1685 1761 // If the item is linked apply any attribute pairs on the child frame 1686 1762 String link = t.getAbsoluteLink(); 1763 1687 1764 // need to get link first because copy doesnt copy the link 1688 1765 t = t.copy(); … … 1701 1778 } 1702 1779 1703 public Text getItemTemplate(char firstChar) { 1780 /** 1781 * TODO: Comment. cts16 1782 * TODO: Remove magic constants. cts16 1783 */ 1784 public Text getItemTemplate(char firstChar) 1785 { 1704 1786 switch (firstChar) { 1705 case '@': 1706 return getAnnotationTemplate(); 1707 case '/': 1708 case '#': 1709 return getCodeCommentTemplate(); 1710 default: 1711 return getItemTemplate(); 1712 } 1713 } 1714 1715 public Text createNewText() { 1787 case '@': 1788 return getAnnotationTemplate(); 1789 case '/': 1790 case '#': 1791 return getCodeCommentTemplate(); 1792 default: 1793 return getItemTemplate(); 1794 } 1795 } 1796 1797 public Text createNewText() 1798 { 1716 1799 return createNewText(""); 1717 1800 } 1718 1801 1719 public Text addText(int x, int y, String text, String action) { 1802 public Text addText(int x, int y, String text, String action) 1803 { 1720 1804 Text t = createNewText(text); 1721 1805 t.setPosition(x, y); … … 1724 1808 } 1725 1809 1726 public Item addText(int x, int y, String text, String action, String link) { 1727 Item t = addText(x, y, text, action); 1810 public Text addText(int x, int y, String text, String action, String link) 1811 { 1812 Text t = addText(x, y, text, action); 1728 1813 t.setLink(link); 1729 1814 return t; 1730 1815 } 1731 1816 1732 public Item addDot(int x, int y) { 1733 Item d = new Dot(x, y, getNextItemID()); 1817 public Dot addDot(int x, int y) 1818 { 1819 Dot d = new Dot(x, y, getNextItemID()); 1734 1820 addItem(d); 1735 1821 return d; … … 1754 1840 * Color to fill the rectangle with 1755 1841 */ 1756 public List<Item> addRectangle(int x, int y, int width, int height, float borderThickness, Color borderColor, Color fillColor) { 1842 public List<Item> addRectangle(int x, int y, int width, int height, float borderThickness, Colour borderColor, Colour fillColor) 1843 { 1757 1844 List<Item> rectComponents = new ArrayList<Item>(); 1758 1845 Item[] corners = new Item[4]; … … 1796 1883 List<Item> rect = new ArrayList<Item>(rectComponents); 1797 1884 this.addAllItems(rectComponents); 1798 FrameMouseActions.anchor(rectComponents);1885 StandardGestureActions.anchor(rectComponents); 1799 1886 return rect; 1800 // rectComponents.clear();1801 } 1802 1803 public boolean isSaved(){1887 } 1888 1889 public boolean isSaved() 1890 { 1804 1891 return _saved; 1805 1892 } 1806 1893 1807 public void setSaved() {1808 // System.out.println(getName() + " saved");1894 public void setSaved() 1895 { 1809 1896 _saved = true; 1810 1897 _change = false; 1811 1898 } 1812 1899 1813 public static boolean rubberbandingLine() {1814 return FreeItems.getInstance().size() == 21815 && (FreeItems.getInstance().get(0) instanceof Line || FreeItems1816 1900 public static boolean rubberbandingLine() 1901 { 1902 return FreeItems.getInstance().size() == 2 && 1903 (FreeItems.getInstance().get(0) instanceof Line || FreeItems.getInstance().get(1) instanceof Line); 1817 1904 } 1818 1905 … … 1825 1912 * @return true if the item is a normal text item 1826 1913 */ 1827 public boolean isNormalTextItem(Item it) {1828 if (it instanceof Text && it != getTitleItem() && it != _frameName1829 1914 public boolean isNormalTextItem(Item it) 1915 { 1916 if (it instanceof Text && it != getTitleItem() && it != _frameName && !((Text) it).isSpecialAnnotation()) { 1830 1917 return true; 1831 1918 } … … 1839 1926 * @param index 1840 1927 */ 1841 public boolean moveMouseToTextItem(int index) { 1928 public boolean moveMouseToTextItem(int index) 1929 { 1842 1930 List<Item> items = getItems(); 1843 1931 int itemsFound = 0; 1844 1932 for (int i = 0; i < items.size(); i++) { 1845 1933 Item it = items.get(i); 1846 if (isNormalTextItem(it)) 1847 itemsFound++; 1934 if (isNormalTextItem(it)) itemsFound++; 1848 1935 if (itemsFound > index) { 1849 DisplayIO.setCursorPosition(((Text) it) 1850 .getParagraphEndPosition().x, it.getY()); 1851 DisplayIO.resetCursorOffset(); 1852 FrameGraphics.Repaint(); 1936 DisplayController.setCursorPosition(((Text) it).getParagraphEndPosition().x, it.getY()); 1937 DisplayController.resetCursorOffset(); 1938 DisplayController.requestRefresh(true); 1853 1939 return true; 1854 1940 } … … 1857 1943 return false; 1858 1944 } 1859 1860 /*1861 * public boolean moveMouseToNextTextItem(int index) { List<Item> items =1862 * getItems(); int itemsFound = 0; for (int i = 0; i < items.size(); i++) {1863 * Item it = items.get(i); if ( isNormalTextItem(it)) itemsFound++; if1864 * (itemsFound > index) {1865 * DisplayIO.setCursorPosition(((Text)it).getEndParagraphPosition().x,1866 * it.getY()); DisplayIO.resetCursorOffset(); FrameGraphics.Repaint();1867 * return true; } }1868 *1869 * return false; }1870 */1871 1945 1872 1946 /** 1873 1947 * Searches for an annotation item called start to be used as the default 1874 1948 * cursor location when TDFC occurs. 1875 */ 1876 public boolean moveMouseToDefaultLocation() { 1949 * 1950 * TODO: Remove magic constants. cts16 1951 */ 1952 public boolean moveMouseToDefaultLocation() 1953 { 1877 1954 List<Item> items = getItems(); 1878 1955 … … 1880 1957 if (it instanceof Text) { 1881 1958 Text t = (Text) it; 1882 if (t.getText().toLowerCase().startsWith("@start") 1883 || t.getText().toLowerCase().equals("@start:")) { 1959 if (t.getText().toLowerCase().startsWith("@start") || t.getText().toLowerCase().equals("@start:")) { 1884 1960 // Used to allow users the option of putting an initial 1885 1961 // bullet after the @start … … 1888 1964 t.setText(""); 1889 1965 1890 if (t.getText().equals("")) 1891 DisplayIO.getCurrentFrame().removeItem(t); 1892 if (!FreeItems.itemsAttachedToCursor()) { 1893 DisplayIO.setCursorPosition(((Text) it) 1894 .getParagraphEndPosition()); 1895 DisplayIO.resetCursorOffset(); 1966 if (t.getText().equals("")) DisplayController.getCurrentFrame().removeItem(t); 1967 1968 if (!FreeItems.hasItemsAttachedToCursor()) { 1969 DisplayController.setCursorPosition(((Text) it).getParagraphEndPosition()); 1970 DisplayController.resetCursorOffset(); 1896 1971 } 1897 FrameGraphics.Repaint(); 1972 1973 DisplayController.requestRefresh(true); 1974 1898 1975 return true; 1899 1976 } … … 1911 1988 * name of the frame if the tag isnt on the frame. 1912 1989 */ 1913 public String getExportFileName() { 1990 public String getExportFileName() 1991 { 1914 1992 String fileName = getExportFileTagValue(); 1915 1993 … … 1925 2003 } 1926 2004 1927 public void toggleBackgroundColor() { 1928 setBackgroundColor(ColorUtils.getNextColor(_background, 1929 TemplateSettings.BackgroundColorWheel.get(), null)); 1930 } 1931 1932 public void setName(String frameset, int i) { 2005 public void toggleBackgroundColor() 2006 { 2007 setBackgroundColor(ColorUtils.getNextColor(_background, TemplateSettings.BackgroundColorWheel.get(), null)); 2008 } 2009 2010 public void setName(String frameset, int i) 2011 { 1933 2012 setFrameset(frameset); 1934 2013 setFrameNumber(i); … … 1940 2019 * 1941 2020 */ 1942 public void refreshItemPermissions(UserAppliedPermission maxPermission) {1943 if(_frameName == null)1944 2021 public void refreshItemPermissions(UserAppliedPermission maxPermission) 2022 { 2023 if(_frameName == null) return; 1945 2024 1946 2025 UserAppliedPermission permission = UserAppliedPermission.min(maxPermission, getUserAppliedPermission()); … … 1948 2027 switch (permission) { 1949 2028 case none: 1950 _frameName.setBackgroundColor( new Color(255, 220, 220));2029 _frameName.setBackgroundColor(FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_NONE); 1951 2030 break; 1952 2031 case followLinks: 1953 _frameName.setBackgroundColor( new Color(255, 230, 135));2032 _frameName.setBackgroundColor(FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_FOLLOW_LINKS); 1954 2033 break; 1955 2034 case copy: 1956 _frameName.setBackgroundColor( new Color(255, 255, 155));2035 _frameName.setBackgroundColor(FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_COPY); 1957 2036 break; 1958 2037 case createFrames: 1959 _frameName.setBackgroundColor( new Color(220, 255, 220));2038 _frameName.setBackgroundColor(FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_CREATE_FRAMES); 1960 2039 break; 1961 2040 case full: 1962 _frameName.setBackgroundColor( null);2041 _frameName.setBackgroundColor(FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_FULL); 1963 2042 break; 1964 2043 default: … … 1975 2054 } 1976 2055 1977 public boolean isTestFrame() { 2056 public boolean isTestFrame() 2057 { 1978 2058 Text title = getTitleItem(); 1979 if (title == null) 1980 return false; 2059 if (title == null) return false; 1981 2060 String action = title.getFirstAction(); 1982 if (action == null) 1983 return false; 2061 if (action == null) return false; 1984 2062 action = action.toLowerCase(); 1985 return action.startsWith(Simple.RUN_FRAME_ACTION) 1986 || action.startsWith(Simple.DEBUG_FRAME_ACTION);1987 } 1988 1989 public void setActiveTime(String activeTime){2063 return action.startsWith(Simple.RUN_FRAME_ACTION) || action.startsWith(Simple.DEBUG_FRAME_ACTION); 2064 } 2065 2066 public void setActiveTime(String activeTime) 2067 { 1990 2068 try { 1991 _activeTime = new Time(Time.valueOf(activeTime).getTime() + 12 * 60 1992 * 60 * 1000); 2069 _activeTime = new Time(Time.valueOf(activeTime).getTime() + 12 * 60 * 60 * 1000); 1993 2070 } catch (Exception e) { 1994 2071 _activeTime = new Time(0); … … 1996 2073 } 1997 2074 1998 public void setActiveTime(Time activeTime) { 2075 public void setActiveTime(Time activeTime) 2076 { 1999 2077 _activeTime = activeTime; 2000 2078 } 2001 2079 2002 public void setDarkTime(Time darkTime) { 2080 public void setDarkTime(Time darkTime) 2081 { 2003 2082 _darkTime = darkTime; 2004 2083 } 2005 2084 2006 public void setDarkTime(String darkTime) { 2085 public void setDarkTime(String darkTime) 2086 { 2007 2087 try { 2008 _darkTime = new Time(Time.valueOf(darkTime).getTime() + 12 * 60 2009 * 60 * 1000); 2088 _darkTime = new Time(Time.valueOf(darkTime).getTime() + 12 * 60 * 60 * 1000); 2010 2089 } catch (Exception e) { 2011 2090 _darkTime = new Time(0); … … 2018 2097 * @return the backup frame for this frame 2019 2098 */ 2020 public Frame getBackupFrame() { 2099 public Frame getBackupFrame() 2100 { 2021 2101 Text backupTag = _annotations.get("old"); 2022 if (backupTag == null) 2023 return null;2102 if (backupTag == null) return null; 2103 2024 2104 // TODO want another way to deal with updating of annotations items 2025 2105 // without F12 refresh … … 2031 2111 return getBackupFrame(); 2032 2112 } 2113 2033 2114 // Now return the name of the backed up frame 2034 2115 String link = backupTag.getAbsoluteLink(); 2035 if (link == null || link.equalsIgnoreCase(getName())) 2036 return null; 2116 if (link == null || link.equalsIgnoreCase(getName())) return null; 2037 2117 2038 2118 Frame backup = FrameIO.LoadFrame(link); … … 2040 2120 } 2041 2121 2042 public Time getDarkTime() { 2122 public Time getDarkTime() 2123 { 2043 2124 return _darkTime; 2044 2125 } 2045 2126 2046 public Time getActiveTime() { 2127 public Time getActiveTime() 2128 { 2047 2129 return _activeTime; 2048 2130 } … … 2054 2136 * @return the number of frames in the backed up comet 2055 2137 */ 2056 public int getCometLength() { 2138 public int getCometLength() 2139 { 2057 2140 Frame backup = getBackupFrame(); 2058 2141 return 1 + (backup == null ? 0 : backup.getCometLength()); 2059 2142 } 2060 2143 2061 public void addAnnotation(Text item) { 2144 public void addAnnotation(Text item) 2145 { 2062 2146 if (_annotations == null) { 2063 2147 _annotations = new HashMap<String, Text>(); 2064 2148 } 2149 2065 2150 // Check if this item has already been processed 2066 2151 String[] tokens = item.getProcessedText(); … … 2074 2159 String text = item.getText().trim(); 2075 2160 assert (text.charAt(0) == '@'); 2161 2076 2162 // Ignore annotations with spaces after the tag symbol 2077 2163 if (text.length() < 2 || !Character.isLetter(text.charAt(1))) { … … 2079 2165 return; 2080 2166 } 2167 2081 2168 // The separator char must come before the first non letter otherwise we 2082 2169 // ignore the annotation item … … 2101 2188 } 2102 2189 } 2190 2103 2191 // If it was nothing but letters and digits save the tag 2104 2192 String lowerCaseText = text.substring(1).toLowerCase(); … … 2107 2195 } 2108 2196 2109 public boolean hasAnnotation(String annotation) { 2110 if (_annotations == null) 2111 refreshAnnotationList(); 2197 public boolean hasAnnotation(String annotation) 2198 { 2199 if (_annotations == null) refreshAnnotationList(); 2200 2112 2201 return _annotations.containsKey(annotation.toLowerCase()); 2113 2202 } … … 2121 2210 * is not on the frame or has no value. 2122 2211 */ 2123 public String getAnnotationValue(String annotation) {2124 if (_annotations == null)2125 2212 public String getAnnotationValue(String annotation) 2213 { 2214 if (_annotations == null) refreshAnnotationList(); 2126 2215 2127 2216 Text text = _annotations.get(annotation.toLowerCase()); 2128 if (text == null) 2129 return null; 2217 if (text == null) return null; 2130 2218 2131 2219 String[] tokens = text.getProcessedText(); 2132 if (tokens != null && tokens.length > 1) 2133 return tokens[1]; 2220 2221 if (tokens != null && tokens.length > 1) return tokens[1]; 2222 2134 2223 return null; 2135 2224 } 2136 2225 2137 Map<String, Text> _annotations = null; 2138 2139 private Collection<FrameObserver> _observers = new HashSet<FrameObserver>(); 2140 2141 public void clearAnnotations() { 2226 public void clearAnnotations() 2227 { 2142 2228 _annotations = null; 2143 2229 } 2144 2230 2145 public List<Item> getVisibleItems() { 2231 public List<Item> getVisibleItems() 2232 { 2146 2233 return getItems(true); 2147 2234 } 2148 2235 2149 private void refreshAnnotationList() { 2150 if (_annotations == null) 2236 private void refreshAnnotationList() 2237 { 2238 if (_annotations == null) { 2151 2239 _annotations = new HashMap<String, Text>(); 2152 else2240 } else { 2153 2241 _annotations.clear(); 2242 } 2243 2154 2244 for (Text text : getTextItems()) { 2155 2245 if (text.isAnnotation()) { … … 2159 2249 } 2160 2250 2161 public Collection<Text> getAnnotationItems() { 2251 public Collection<Text> getAnnotationItems() 2252 { 2162 2253 if (_annotations == null) { 2163 2254 refreshAnnotationList(); 2164 2255 } 2256 2165 2257 return _annotations.values(); 2166 2258 } … … 2171 2263 * @return the list of items to be saved to a text file 2172 2264 */ 2173 public List<Item> getItemsToSave() {2174 2265 public List<Item> getItemsToSave() 2266 { 2175 2267 if (!_sorted) { 2176 2268 Collections.sort(_body); … … 2179 2271 2180 2272 // iWidgets are handled specially since 8 items are written as one 2181 Collection< InteractiveWidget> seenWidgets = new LinkedHashSet<InteractiveWidget>();2273 Collection<Widget> seenWidgets = new LinkedHashSet<Widget>(); 2182 2274 2183 2275 List<Item> toSave = new ArrayList<Item>(); 2184 2276 2185 2277 for (Item i : _body) { 2186 if (i == null || i.dontSave()) { 2187 continue; 2188 } 2278 if (i == null || i.dontSave()) continue; 2189 2279 2190 2280 // Ensure only one of the WidgetCorners represent a single widget 2191 2281 if (i instanceof WidgetCorner) { 2192 InteractiveWidget iw = ((WidgetCorner) i).getWidgetSource(); 2193 if (seenWidgets.contains(iw)) 2194 continue; 2282 Widget iw = ((WidgetCorner) i).getWidgetSource(); 2283 if (seenWidgets.contains(iw)) continue; 2195 2284 seenWidgets.add(iw); 2196 2285 toSave.add(iw.getSource()); … … 2198 2287 XRayable x = (XRayable) i; 2199 2288 toSave.addAll(x.getItemsToSave()); 2200 }// Circle centers are items with attached enclosures2201 else if (i.hasEnclosures()) {2289 // Circle centers are items with attached enclosures 2290 } else if (i.hasEnclosures()) { 2202 2291 continue; 2203 2292 } else { … … 2213 2302 } 2214 2303 2215 public Collection<Item> getOverlayItems() { 2304 public Collection<Item> getOverlayItems() 2305 { 2216 2306 return _overlayItems; 2217 2307 } … … 2223 2313 * @return 2224 2314 */ 2225 public boolean hasOverlay(Frame frame) { 2315 public boolean hasOverlay(Frame frame) 2316 { 2226 2317 return _overlays.containsValue(frame); 2227 2318 } 2228 2319 2229 public Collection<Item> getAllItems() { 2320 public Collection<Item> getAllItems() 2321 { 2230 2322 Collection<Item> allItems = new LinkedHashSet<Item>(_body); 2231 2323 allItems.addAll(_overlayItems); … … 2234 2326 } 2235 2327 2236 public Collection<Item> getVectorItems() { 2328 public Collection<Item> getVectorItems() 2329 { 2237 2330 Collection<Item> vectorItems = new LinkedHashSet<Item>(_vectorItems); 2238 2331 vectorItems.addAll(getNonAnnotationItems(false)); … … 2245 2338 * @return 2246 2339 */ 2247 public Collection<Text> getTextItems() { 2340 public Collection<Text> getTextItems() 2341 { 2248 2342 Collection<Text> textItems = new ArrayList<Text>(); 2343 2249 2344 for (Item i : getItems(true)) { 2250 2345 // only add up normal body text items … … 2253 2348 } 2254 2349 } 2350 2255 2351 return textItems; 2256 2352 } 2257 2353 2258 public Text getAnnotation(String annotation) {2259 if (_annotations == null)2260 2354 public Text getAnnotation(String annotation) 2355 { 2356 if (_annotations == null) refreshAnnotationList(); 2261 2357 2262 2358 return _annotations.get(annotation.toLowerCase()); 2263 2359 } 2264 2360 2265 public void recalculate() {2266 2361 public void recalculate() 2362 { 2267 2363 for (Item i : getItems()) { 2268 2364 if (i.hasFormula() && !i.isAnnotation()) { … … 2272 2368 } 2273 2369 2274 public void removeObserver(FrameObserver observer) { 2370 public void removeObserver(FrameObserver observer) 2371 { 2275 2372 _observers.remove(observer); 2276 2373 } 2277 2374 2278 public void addObserver(FrameObserver observer) { 2375 public void addObserver(FrameObserver observer) 2376 { 2279 2377 _observers.add(observer); 2280 2378 } 2281 2379 2282 public void clearObservers() { 2380 public void clearObservers() 2381 { 2283 2382 for (FrameObserver fl : _observers) { 2284 2383 fl.removeSubject(this); 2285 2384 } 2385 2286 2386 // The frame listener will call the frames removeListener method 2287 2387 assert (_observers.size() == 0); 2288 2388 } 2289 2389 2290 public Collection<Text> getNonAnnotationText(boolean removeTitle) { 2390 public Collection<Text> getNonAnnotationText(boolean removeTitle) 2391 { 2291 2392 Collection<Text> items = new LinkedHashSet<Text>(); 2393 2292 2394 for (Item i : getItems(true)) { 2293 2395 // only add up normal body text items … … 2296 2398 } 2297 2399 } 2400 2298 2401 if (removeTitle) { 2299 2402 items.remove(getTitleItem()); 2300 2403 } 2404 2301 2405 return items; 2302 2406 } 2303 2407 2304 public void dispose() { 2408 public void dispose() 2409 { 2305 2410 clearObservers(); 2411 2306 2412 for (Item i : _body) { 2307 2413 i.dispose(); 2308 2414 } 2415 2309 2416 _frameName.dispose(); 2310 2417 _body = null; … … 2312 2419 } 2313 2420 2314 public void parse() { 2421 public void parse() 2422 { 2315 2423 for (Overlay o : getOverlays()) { 2316 2424 o.Frame.parse(); 2317 2425 } 2426 2318 2427 // Must parse the frame AFTER the overlays 2319 2428 FrameUtils.Parse(this); 2320 2429 } 2321 2430 2322 public void setPath(String path) { 2431 public void setPath(String path) 2432 { 2323 2433 this.path = path; 2324 2434 } 2325 2435 2326 public String getPath() { 2436 public String getPath() 2437 { 2327 2438 return path; 2328 2439 } 2329 2440 2330 public void setLocal(boolean isLocal) { 2441 public void setLocal(boolean isLocal) 2442 { 2331 2443 this._isLocal = isLocal; 2332 2444 } 2333 2445 2334 public boolean isLocal() { 2446 public boolean isLocal() 2447 { 2335 2448 return _isLocal; 2336 2449 } 2337 2450 2338 public String getExportFileTagValue() { 2451 public String getExportFileTagValue() 2452 { 2339 2453 return getAnnotationValue("file"); 2340 2454 } 2341 2455 2342 public void assertEquals(Frame frame2) { 2456 public void assertEquals(Frame frame2) 2457 { 2343 2458 // Check that all the items on the frame are the same 2344 2459 List<Item> items1 = getVisibleItems(); 2345 2460 List<Item> items2 = frame2.getVisibleItems(); 2461 2346 2462 if (items1.size() != items2.size()) { 2347 throw new UnitTestFailedException(items1.size() + " items", items2 2348 .size() 2349 + " items"); 2463 throw new UnitTestFailedException(items1.size() + " items", items2.size() + " items"); 2350 2464 } else { 2351 2465 for (int i = 0; i < items1.size(); i++) { … … 2361 2475 } 2362 2476 2363 public boolean hasObservers() { 2477 public boolean hasObservers() 2478 { 2364 2479 return _observers != null && _observers.size() > 0; 2365 2480 } 2366 2481 2367 public Collection<? extends Item> getInteractableItems() { 2482 public Collection<? extends Item> getInteractableItems() 2483 { 2368 2484 /* 2369 2485 * TODO: Cache the interactableItems list so we dont have to recreate it 2370 2486 * every time this method is called 2371 2487 */ 2372 if (_interactableItems.size() > 0) 2373 return _interactableItems; 2488 if (_interactableItems.size() > 0) return _interactableItems; 2374 2489 2375 2490 for (Item i : _body) { 2376 if (i == null) { 2377 continue; 2378 } 2491 if (i == null) continue; 2379 2492 if (i.isVisible()) { 2380 2493 _interactableItems.add(i); … … 2386 2499 _interactableItems.add(i); 2387 2500 } 2388 2389 2390 2501 } 2391 2502 … … 2398 2509 return _interactableItems; 2399 2510 } 2511 2512 private static final class History { 2513 2514 public enum Type { 2515 deletion, 2516 movement 2517 } 2518 2519 public final List<Item> items; 2520 2521 public final Type type; 2522 2523 public History(Collection<Item> items, Type type) 2524 { 2525 this.items = new LinkedList<Item>(items); 2526 this.type = type; 2527 } 2528 2529 public String toString() 2530 { 2531 return this.type.toString() + ":\n" + this.items.toString(); 2532 } 2533 } 2400 2534 } -
trunk/src/org/expeditee/gui/FrameCreator.java
r1063 r1102 19 19 package org.expeditee.gui; 20 20 21 import java. awt.Color;22 import java.util. *;21 import java.util.LinkedList; 22 import java.util.List; 23 23 24 24 import org.expeditee.agents.ExistingFramesetException; 25 import org.expeditee.core.Colour; 25 26 import org.expeditee.items.Item; 26 27 import org.expeditee.items.Text; 27 28 28 29 public class FrameCreator { 30 29 31 public static final int INDENT_FROM_TITLE = 20; 30 32 … … 60 62 61 63 public FrameCreator(String frameTitle) { 62 this(Display IO.getCurrentFrame().getFramesetName(), DisplayIO64 this(DisplayController.getCurrentFrame().getFramesetName(), DisplayController 63 65 .getCurrentFrame().getPath(), frameTitle, false, false); 64 66 } … … 83 85 * @return the newly created button. 84 86 */ 85 public static Item createButton(String text, Float x, Float y, Floatright,86 Floatbottom) {87 public static Item createButton(String text, Integer x, Integer y, Integer right, 88 Integer bottom) { 87 89 Text button = new Text(text); 88 90 89 button.setBackgroundColor(Colo r.LIGHT_GRAY);90 button.setBorderColor(Colo r.DARK_GRAY);91 button.setBackgroundColor(Colour.LIGHT_GREY); 92 button.setBorderColor(Colour.DARK_GREY); 91 93 button.setThickness(2.0F); 92 94 if (bottom != null) … … 99 101 button.setY(y); 100 102 101 button. updatePolygon();103 button.invalidateBounds(); 102 104 103 105 return button; 104 106 } 105 107 106 public FrameCreator(String name, String path, String frameTitle, 107 boolean recreate, boolean multiColumn){108 public FrameCreator(String name, String path, String frameTitle, boolean recreate, boolean multiColumn) 109 { 108 110 _multiColumn = multiColumn; 109 _Mnext = createButton("@Next", null, null, 10 F, 15F);111 _Mnext = createButton("@Next", null, null, 10, 15); 110 112 111 113 _Mprev = createButton("@Previous", null, null, _Mnext.getBoundsWidth() 112 + _Mnext.getAnchorRight() + 20 F, 15F);114 + _Mnext.getAnchorRight() + 20, 15); 113 115 114 116 _Mfirst = createButton("@First", null, null, _Mprev.getBoundsWidth() 115 + _Mprev.getAnchorRight() + 20 F, 15F);117 + _Mprev.getAnchorRight() + 20, 15); 116 118 117 119 Frame toUse = null; … … 180 182 } 181 183 182 private void resetGlobals(Frame toUse) { 184 private void resetGlobals(Frame toUse) 185 { 183 186 Text title = toUse.getTitleItem(); 184 187 START_X = INDENT_FROM_TITLE + title.getX(); … … 217 220 // new frame 218 221 if (!_multiColumn 219 || toAdd.getBoundsWidth() + _lastX > FrameGraphics 220 .getMaxSize().width) { 222 || toAdd.getBoundsWidth() + _lastX > DisplayController.getFramePaintArea().getWidth()) { 221 223 // Make sure text items that are created on the current 222 224 // frame are removed … … 229 231 toAdd.setOffset(0, 0); 230 232 toAdd.setID(_current.getNextItemID()); 231 toAdd.setRightMargin( FrameGraphics.getMaxFrameSize().width, true);233 toAdd.setRightMargin(DisplayController.getFramePaintArea().getWidth(), true); 232 234 233 235 _current.addItem(toAdd); … … 245 247 } 246 248 247 public Text addText(String toAdd, Colo r c, String link, String action,249 public Text addText(String toAdd, Colour c, String link, String action, 248 250 boolean bSave) { 249 251 Text text = _current.createNewText(toAdd); -
trunk/src/org/expeditee/gui/FrameGraphics.java
r1064 r1102 19 19 package org.expeditee.gui; 20 20 21 import java.awt.Color;22 import java.awt.Dimension;23 import java.awt.EventQueue;24 import java.awt.Graphics;25 import java.awt.Graphics2D;26 import java.awt.GraphicsDevice;27 import java.awt.GraphicsEnvironment;28 import java.awt.Image;29 import java.awt.Polygon;30 import java.awt.Rectangle;31 import java.awt.RenderingHints;32 import java.awt.geom.Area;33 import java.lang.reflect.Method;34 import java.awt.image.BufferedImage;35 21 import java.util.Collection; 36 22 import java.util.Collections; … … 41 27 import java.util.ListIterator; 42 28 29 import org.expeditee.core.Clip; 30 import org.expeditee.core.Colour; 31 import org.expeditee.core.Dimension; 32 import org.expeditee.core.Image; 33 import org.expeditee.core.bounds.PolygonBounds; 34 import org.expeditee.gio.EcosystemManager; 35 import org.expeditee.gio.input.StandardInputEventListeners; 36 import org.expeditee.gio.input.KBMInputEvent.Key; 43 37 import org.expeditee.items.Circle; 44 38 import org.expeditee.items.Dot; 45 39 import org.expeditee.items.Item; 46 import org.expeditee.items.ItemUtils;47 40 import org.expeditee.items.Line; 48 41 import org.expeditee.items.UserAppliedPermission; 49 42 import org.expeditee.items.XRayable; 50 43 import org.expeditee.items.Item.HighlightMode; 51 import org.expeditee.items.widgets. InteractiveWidget;44 import org.expeditee.items.widgets.Widget; 52 45 import org.expeditee.items.widgets.WidgetEdge; 53 46 import org.expeditee.settings.UserSettings; … … 55 48 public class FrameGraphics { 56 49 57 // the graphics used to paint with58 private static Graphics2D _DisplayGraphics;59 60 // the maximum size that can be used to paint on61 private static Dimension _MaxSize = null;62 63 50 // Final passes to rendering the current frame 64 51 private static LinkedList<FrameRenderPass> _frameRenderPasses = new LinkedList<FrameRenderPass>(); 65 66 // modes67 protected static final int MODE_NORMAL = 0;68 69 protected static final int MODE_AUDIENCE = 1;70 71 protected static final int MODE_XRAY = 2;72 52 73 protected static final int MODE_AUDIENCE_FULLSCREEN = 4; 74 75 76 // The following used to be true in the past: 77 // Start in XRay mode so that errors aren't thrown when parsing the profile 78 // frame if it has images on it 79 // More recently, so Exploratory Search starts up correctly with images 80 // rendered (rather than their @i form) the following assignment was changed 81 // to MODE_NORMAL. No issue of parse errors has not been seen 82 private static int _Mode = MODE_NORMAL; 83 84 private FrameGraphics() { 85 // util constructor 86 } 87 88 /** 89 * If Audience Mode is on this method will toggle it to be off, or 90 * vice-versa. This results in the Frame being re-parsed and repainted. 91 */ 92 public static void ToggleAudienceMode() { 93 Frame current = DisplayIO.getCurrentFrame(); 94 if (_Mode == MODE_XRAY) { 95 ToggleXRayMode(); 96 } 97 98 99 if (_Mode == MODE_AUDIENCE_FULLSCREEN) { 100 _Mode = MODE_NORMAL; 101 DisplayIO.leaveFullScreenMode(); 102 } 103 else if (_Mode == MODE_AUDIENCE) { 104 if (DisplayIO.fullScreenCapable()) { 105 // Don't need to worry about UpdateConnectedToAnnotations, as this 106 // will have already been taken care of going to the 'first stage' of 107 // audience mode (MODE_AUDIENCE) 108 _Mode = MODE_AUDIENCE_FULLSCREEN; 109 DisplayIO.enterFullScreenMode(); 110 } 111 else { 112 // return to normal mode 113 _Mode = MODE_NORMAL; 114 } 115 } 116 else { // must currently be in regular mode => move to audience mode 117 _Mode = MODE_AUDIENCE; 118 ItemUtils.UpdateConnectedToAnnotations(current.getItems()); 119 for (Overlay o : current.getOverlays()) { 120 ItemUtils.UpdateConnectedToAnnotations(o.Frame.getItems()); 121 } 122 for (Vector v : current.getVectorsDeep()) { 123 ItemUtils.UpdateConnectedToAnnotations(v.Frame.getItems()); 124 } 125 } 126 FrameUtils.Parse(current); 127 DisplayIO.UpdateTitle(); 128 setMaxSize(new Dimension(_MaxSize.width, MessageBay 129 .getMessageBufferHeight() 130 + _MaxSize.height)); 131 refresh(false); 132 } 133 134 /** 135 * If X-Ray Mode is on this method will toggle it to be off, or vice-versa. 136 * This results in the Frame being re-parsed and repainted. 137 */ 138 public static void ToggleXRayMode() { 139 if (_Mode == MODE_AUDIENCE) { 140 ToggleAudienceMode(); 141 } 142 143 if (_Mode == MODE_XRAY) { 144 setMode(MODE_NORMAL, true); 145 } else { 146 setMode(MODE_XRAY, true); 147 } 148 DisplayIO.getCurrentFrame().refreshSize(); 149 DisplayIO.UpdateTitle(); 150 FrameMouseActions.getInstance().refreshHighlights(); 151 FrameMouseActions.updateCursor(); 152 refresh(false); 153 } 154 155 public static void setMode(int mode, boolean parse) { 156 if (_Mode == mode) 157 return; 158 _Mode = mode; 159 if (parse) { 160 Frame current = DisplayIO.getCurrentFrame(); 161 current.parse(); 162 } 163 } 164 165 public static void forceXRayMode(boolean parse) { 166 setMode(MODE_XRAY,parse); 167 } 168 169 /** 170 * @return True if Audience Mode is currently on, False otherwise. 171 */ 172 public static boolean isAudienceMode() { 173 return (_Mode == MODE_AUDIENCE) || (_Mode == MODE_AUDIENCE_FULLSCREEN); 174 } 175 176 /** 177 * @return True if X-Ray Mode is currently on, False otherwise. 178 */ 179 public static boolean isXRayMode() { 180 return _Mode == MODE_XRAY; 181 } 182 183 public static void setMaxSize(Dimension max) { 184 if (_MaxSize == null) 185 _MaxSize = max; 186 187 // Hide the message buffer if in audience mode 188 int newMaxHeight = max.height 189 - (isAudienceMode() ? 0 : MessageBay.MESSAGE_BUFFER_HEIGHT); 190 if (newMaxHeight > 0) { 191 _MaxSize.setSize(max.width, newMaxHeight); 192 } 193 Frame current = DisplayIO.getCurrentFrame(); 194 if (current != null) { 195 current.setBuffer(null); 196 current.refreshSize(); 197 if (DisplayIO.isTwinFramesOn()) { 198 Frame opposite = DisplayIO.getOppositeFrame(); 199 200 /* When running the test suite opposite may be null! */ 201 if (opposite != null) { 202 opposite.setBuffer(null); 203 opposite.refreshSize(); 204 } 205 } 206 } 207 208 if (newMaxHeight > 0) { 209 MessageBay.updateSize(); 210 } 211 } 212 213 public static Dimension getMaxSize() { 214 return _MaxSize; 215 } 216 217 public static Dimension getMaxFrameSize() { 218 if (DisplayIO.isTwinFramesOn()) { 219 return new Dimension((_MaxSize.width / 2), _MaxSize.height); 220 } else 221 return _MaxSize; 222 } 223 224 /** 225 * Sets the Graphics2D object that should be used for all painting tasks. 226 * Note: Actual painting is done by using g.create() to create temporary 227 * instances that are then disposed of using g.dispose(). 228 * 229 * @param g 230 * The Graphics2D object to use for all painting 231 */ 232 public static void setDisplayGraphics(Graphics2D g) { 233 _DisplayGraphics = g; 234 } 235 236 /* 237 * Displays the given Item on the screen 238 */ 239 static void PaintItem(Graphics2D g, Item i) { 240 if (i == null || g == null) 241 return; 242 243 // do not paint annotation items in audience mode 244 if (!isAudienceMode() 245 || (isAudienceMode() && !i.isConnectedToAnnotation() && !i 246 .isAnnotation()) || i == FrameUtils.getLastEdited()) { 247 248 Graphics2D tg = (Graphics2D) g.create(); 249 i.paint(tg); 250 tg.dispose(); 251 } 252 } 253 254 /** 255 * Adds all the scaled vector items for a frame into a list. It uses 256 * recursion to get the items from nested vector frames. 257 * 258 * @param items 259 * the list into which the vector items will be placed. 260 * @param vector 261 * the frame containing vecor items. 262 * @param seenVectors 263 * the vectors which should be ignored to prevent infinate loops. 264 * @param origin 265 * start point for this frame or null if it is a top level frame. 266 * @param scale 267 * the factor by which the item on the vector frame are to be 268 * scaled. 269 */ 270 // public static void AddAllVectorItems(List<Item> items, Vector vector, 271 // Collection<Frame> seenVectors) { 272 // // Check all the vector items and add the items on the vectors 273 // if (seenVectors.contains(vector)) 274 // return; 275 // seenVectors.add(vector); 276 // 277 // float originX = origin == null ? 0 : origin.x; 278 // float originY = origin == null ? 0 : origin.y; 279 // 280 // for (Vector o : vector.getVectors()) 281 // AddAllVectorItems(items, o.Frame, new HashSet<Frame>(seenVectors), 282 // new Point2D.Float(originX + o.Origin.x * scale, originY 283 // + o.Origin.y * scale), o.Scale * scale, 284 // o.Foreground, o.Background); 285 // // if its the original frame then were done 286 // if (origin == null) { 287 // ItemUtils.EnclosedCheck(items); 288 // return; 289 // } 290 // // Put copies of the items shifted to the origin of the VectorTag 291 // items.addAll(ItemUtils 292 // .CopyItems(vector.getNonAnnotationItems(), vector)); 293 // 294 // } 295 /** 296 * Recursive function similar to AddAllOverlayItems. 297 * 298 * @param widgets 299 * The collection the widgets will be added to 300 * @param overlay 301 * An "overlay" frame - this intially will be the parent frame 302 * @param seenOverlays 303 * Used for state in the recursion stack. Pass as an empty 304 * (non-null) list. 305 */ 306 public static void AddAllOverlayWidgets(List<InteractiveWidget> widgets, 307 Frame overlay, List<Frame> seenOverlays) { 308 if (seenOverlays.contains(overlay)) 309 return; 310 311 seenOverlays.add(overlay); 312 313 for (Overlay o : overlay.getOverlays()) 314 AddAllOverlayWidgets(widgets, o.Frame, seenOverlays); 315 316 widgets.addAll(overlay.getInteractiveWidgets()); 317 } 318 319 private static Image Paint(Frame toPaint, Area clip) { 320 return Paint(toPaint, clip, true, true); 321 } 322 323 /** 324 * 325 * @param toPaint 326 * @param clip 327 * If null, then no clip applied. 328 * @param isActualFrame 329 * @return 330 */ 331 private static Image Paint(Frame toPaint, Area clip, boolean isActualFrame, 332 boolean createVolitile) { 333 if (toPaint == null) 334 return null; 53 private static Item _lastToolTippedItem = null; 54 55 /** Static-only class. */ 56 private FrameGraphics() 57 { 58 } 59 60 /** 61 * Gets an image of the given frame that has the given dimensions. If clip 62 * is not null, only the areas inside clip are guaranteed to be drawn. 63 */ 64 public static Image getFrameImage(Frame toPaint, Clip clip, Dimension size) 65 { 66 return getFrameImage(toPaint, clip, size, true, true); 67 } 68 69 /** 70 * Gets an image of the given frame that has the given dimensions. If clip 71 * is not null, only the areas inside clip are guaranteed to be drawn. 72 */ 73 public static Image getFrameImage(Frame toPaint, Clip clip, Dimension size, boolean isActualFrame, boolean createVolatile) 74 { 75 if (toPaint == null) return null; 335 76 336 77 // the buffer is not valid, so it must be recreated 337 78 if (!toPaint.isBufferValid()) { 79 338 80 Image buffer = toPaint.getBuffer(); 339 if (buffer == null) { 340 GraphicsEnvironment ge = GraphicsEnvironment 341 .getLocalGraphicsEnvironment(); 342 if (createVolitile) { 343 buffer = ge.getDefaultScreenDevice() 344 .getDefaultConfiguration() 345 .createCompatibleVolatileImage(_MaxSize.width, 346 _MaxSize.height); 81 // Get the size if it hasn't been given 82 if (size == null) { 83 // Can't get the size if there is no buffer 84 if (buffer == null) { 85 return null; 347 86 } else { 348 buffer = new BufferedImage(_MaxSize.width, _MaxSize.height, 349 BufferedImage.TYPE_INT_ARGB); 350 } 87 size = buffer.getSize(); 88 } 89 } 90 91 if (buffer == null || !buffer.getSize().equals(size)) { 92 buffer = Image.createImage(size.width, size.height, createVolatile); 351 93 toPaint.setBuffer(buffer); 352 } 353 354 Graphics2D bg = (Graphics2D) buffer.getGraphics(); 355 paintFrame(toPaint, clip, isActualFrame, createVolitile, bg); 356 357 bg.dispose(); 94 clip = null; 95 } 96 97 EcosystemManager.getGraphicsManager().pushDrawingSurface(buffer); 98 EcosystemManager.getGraphicsManager().pushClip(clip); 99 paintFrame(toPaint, isActualFrame, createVolatile); 100 EcosystemManager.getGraphicsManager().popDrawingSurface(); 358 101 } 359 102 … … 361 104 } 362 105 363 /** 364 * @param toPaint 365 * @param clip 366 * @param isActualFrame 367 * @param createVolitile 368 * @param bg 369 */ 370 public static void paintFrame(Frame toPaint, Area clip, 371 boolean isActualFrame, boolean createVolitile, Graphics2D bg) { 372 106 /** TODO: Comment. cts16 */ 107 public static void paintFrame(Frame toPaint, boolean isActualFrame, boolean createVolitile) 108 { 109 Clip clip = EcosystemManager.getGraphicsManager().peekClip(); 110 373 111 // Prepare render passes 374 112 if (isActualFrame) { 375 currentClip = clip;376 113 for (FrameRenderPass pass : _frameRenderPasses) { 377 currentClip = pass.paintStarted(currentClip); 378 clip = currentClip; 379 } 380 } 381 382 bg.setClip(clip); 114 clip = pass.paintStarted(clip); 115 } 116 } 383 117 384 118 // TODO: Revise images and clip - VERY IMPORTANT … … 386 120 // Nicer looking lines, but may be too jerky while 387 121 // rubber-banding on older machines 388 if (UserSettings.AntiAlias.get()) 389 bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 390 RenderingHints.VALUE_ANTIALIAS_ON); 391 // If we are doing @f etc... then have a clear background if its the 392 // default background color 393 Color backgroundColor = null; 122 if (UserSettings.AntiAlias.get()) EcosystemManager.getGraphicsManager().setAntialiasing(true); 123 124 // If we are doing @f etc... then have a clear background if its the default background color 125 Colour backgroundColor = null; 126 394 127 // Need to allow transparency for frameImages 395 128 if (createVolitile) { … … 397 130 } else { 398 131 backgroundColor = toPaint.getBackgroundColor(); 399 if (backgroundColor == null) 400 backgroundColor = Item.TRANSPARENT; 401 } 402 403 // if(isActual) 404 bg.setColor(backgroundColor); 405 if (isActualFrame) { 406 // bg.setColor(Color.white); // TODO: TEMP FOR DEBUGGING 407 408 // System.out.println("paintPic"); 409 } 410 bg.fillRect(0, 0, _MaxSize.width, _MaxSize.height); 132 if (backgroundColor == null) backgroundColor = Item.TRANSPARENT; 133 } 134 135 EcosystemManager.getGraphicsManager().clear(backgroundColor); 411 136 412 137 List<Item> visibleItems = new LinkedList<Item>(); 413 List< InteractiveWidget> paintWidgets;138 List<Widget> paintWidgets; 414 139 415 140 if (isActualFrame) { … … 417 142 // frames 418 143 visibleItems.addAll(toPaint.getAllItems()); 419 paintWidgets = new LinkedList<InteractiveWidget>();420 AddAllOverlayWidgets(paintWidgets, toPaint, new LinkedList<Frame>());144 paintWidgets = toPaint.getAllOverlayWidgets(); 145 paintWidgets.addAll(toPaint.getInteractiveWidgets()); 421 146 } else { 422 147 visibleItems.addAll(toPaint.getVisibleItems()); … … 425 150 } 426 151 427 428 HashSet<Item> paintedFillsAndLines = new HashSet<Item>(); 152 HashSet<Item> paintedFillsAndLines = new HashSet<Item>(); 429 153 // FIRST: Paint widgets swing gui (not expeditee gui) . 430 154 // Note that these are the anchored widgets 431 ListIterator<InteractiveWidget> widgetItor = paintWidgets 432 .listIterator(paintWidgets.size()); 155 ListIterator<Widget> widgetItor = paintWidgets.listIterator(paintWidgets.size()); 433 156 while (widgetItor.hasPrevious()) { 434 157 // Paint first-in-last-serve ordering - like swing 435 158 // If it is done the other way around then widgets are covered up by 436 159 // the box that is supposed to be underneath 437 InteractiveWidget iw = widgetItor.previous();438 if (clip == null || clip. intersects(iw.getComponant().getBounds())) {160 Widget iw = widgetItor.previous(); 161 if (clip == null || clip.getBounds() == null || clip.getBounds().intersects(iw.getBounds())) { 439 162 paintedFillsAndLines.addAll(iw.getItems()); 440 163 //iw.paint(bg); … … 457 180 paintItems = new LinkedList<Item>(); 458 181 for (Item i : visibleItems) { 459 if ( i.isInDrawingArea(clip)) {182 if (clip == null || i.isInDrawingArea(clip.getBounds())) { 460 183 paintItems.add(i); 461 184 } else if (i.isEnclosed()) { … … 469 192 } 470 193 } 471 // Only paint files and lines once ... between anchored AND free472 // items473 PaintPictures( bg,paintItems, fillOnlyItems, paintedFillsAndLines);474 PaintLines( bg,visibleItems);194 195 // Only paint files and lines once ... between anchored AND free items 196 PaintPictures(paintItems, fillOnlyItems, paintedFillsAndLines); 197 PaintLines(visibleItems); 475 198 476 199 … … 480 203 // If it is done the other way around then widgets are covered up by 481 204 // the box that is supposed to be underneath 482 InteractiveWidget iw = widgetItor.previous();483 if (clip == null || clip.i ntersects(iw.getComponant().getBounds())) {484 iw.paint( bg);485 PaintItem( bg,iw.getItems().get(4));205 Widget iw = widgetItor.previous(); 206 if (clip == null || clip.isNotClipped() || clip.getBounds().intersects(iw.getBounds())) { 207 iw.paint(); 208 PaintItem(iw.getItems().get(4)); 486 209 } 487 210 } … … 494 217 // Dont paint the free items for the other frame in twin frames mode 495 218 // if (toPaint == DisplayIO.getCurrentFrame()) { 496 if (clip == null ) {219 if (clip == null || clip.isNotClipped()) { 497 220 freeItemsToPaint = FreeItems.getInstance(); 498 221 } else { … … 500 223 fillOnlyItems.clear(); 501 224 for (Item i : FreeItems.getInstance()) { 502 if (i.isInDrawingArea(clip )) {225 if (i.isInDrawingArea(clip.getBounds())) { 503 226 freeItemsToPaint.add(i); 504 227 } else if (i.isEnclosed()) { … … 509 232 // } 510 233 511 if (isActualFrame && toPaint == DisplayIO.getCurrentFrame()) 512 PaintPictures(bg, freeItemsToPaint, fillOnlyItems, 513 paintedFillsAndLines); 234 if (isActualFrame && toPaint == DisplayController.getCurrentFrame()) { 235 PaintPictures(freeItemsToPaint, fillOnlyItems, paintedFillsAndLines); 236 } 237 514 238 // TODO if we can get transparency with FreeItems.getInstance()... 515 239 // then text can be done before freeItems 516 PaintNonLinesNonPicture( bg,paintItems);240 PaintNonLinesNonPicture(paintItems); 517 241 518 242 // toPaint.setBufferValid(true); 519 243 520 if (isActualFrame && ! isAudienceMode()) {521 PaintItem( bg,toPaint.getNameItem());522 } 523 524 if (Display IO.isTwinFramesOn()) {244 if (isActualFrame && !DisplayController.isAudienceMode()) { 245 PaintItem(toPaint.getNameItem()); 246 } 247 248 if (DisplayController.isTwinFramesOn()) { 525 249 List<Item> lines = new LinkedList<Item>(); 526 250 for (Item i : freeItemsToPaint) { … … 528 252 Line line = (Line) i; 529 253 530 if (toPaint == Display IO.getCurrentFrame()) {254 if (toPaint == DisplayController.getCurrentFrame()) { 531 255 // If exactly one end of the line is floating... 532 256 … … 560 284 } 561 285 } 562 if (isActualFrame)563 PaintLines(bg,lines);286 287 if (isActualFrame) PaintLines(lines); 564 288 } else { 565 // Don't paint the 566 if (isActualFrame) 567 PaintLines(bg, freeItemsToPaint); 568 } 569 570 if (isActualFrame && toPaint == DisplayIO.getCurrentFrame()) 571 PaintNonLinesNonPicture(bg, freeItemsToPaint); 289 if (isActualFrame) PaintLines(freeItemsToPaint); 290 } 291 292 if (isActualFrame && toPaint == DisplayController.getCurrentFrame()) { 293 PaintNonLinesNonPicture(freeItemsToPaint); 294 } 572 295 573 296 // Repaint popups / drags... As well as final passes 574 297 if (isActualFrame) { 575 298 for (FrameRenderPass pass : _frameRenderPasses) { 576 pass.paintPreLayeredPanePass(bg); 577 } 578 PopupManager.getInstance().paintLayeredPane(bg, clip); 299 pass.paintPreLayeredPanePass(); 300 } 301 302 //if (PopupManager.getInstance() != null) PopupManager.getInstance().paintLayeredPane(clip == null ? null : clip.getBounds()); 303 579 304 for (FrameRenderPass pass : _frameRenderPasses) { 580 pass.paintFinalPass( bg);305 pass.paintFinalPass(); 581 306 } 582 307 } 583 308 584 309 // paint tooltip 585 if(!FreeItems. itemsAttachedToCursor()) {310 if(!FreeItems.hasItemsAttachedToCursor()) { 586 311 Item current = FrameUtils.getCurrentItem(); 587 if(current != null) { 588 current.paintTooltip(bg); 589 } //else { 590 // Item.clearTooltipOwner(); 591 // } 592 if(previous != null) previous.clearTooltips(); 593 previous = current; 594 } 595 596 if (FreeItems.hasCursor() 597 && DisplayIO.getCursor() == Item.DEFAULT_CURSOR) 598 PaintNonLinesNonPicture(bg, FreeItems.getCursor()); 599 } 600 601 private static Item previous = null; 602 603 // creates a new line so that lines are shown correctly when spanning 604 // across frames in TwinFrames mode 605 // private static Line TransposeLine(Line line, Item d, Frame toPaint, 606 // int base, int adj) { 607 // Line nl = null; 608 // 609 // if (toPaint != DisplayIO.getCurrentFrame() && d.getParent() == null 610 // && line.getOppositeEnd(d).getParent() == toPaint) { 611 // nl = line.copy(); 612 // if (d == line.getStartItem()) 613 // d = nl.getStartItem(); 614 // else 615 // d = nl.getEndItem(); 616 // 617 // if (DisplayIO.FrameOnSide(toPaint) == 0) 618 // d.setX(base); 619 // else 620 // d.setX(base + adj); 621 // 622 // } else if (toPaint == DisplayIO.getCurrentFrame() 623 // && d.getParent() == null 624 // && line.getOppositeEnd(d).getParent() != toPaint) { 625 // nl = line.copy(); 626 // 627 // if (d == line.getStartItem()) 628 // d = nl.getEndItem(); 629 // else 630 // d = nl.getStartItem(); 631 // 632 // if (DisplayIO.FrameOnSide(toPaint) == 1) 633 // d.setX(d.getX() - DisplayIO.getMiddle()); 634 // else 635 // d.setX(d.getX() + DisplayIO.getMiddle()); 636 // } 637 // if (nl != null) { 638 // nl.invalidateAll(); 639 // FrameGraphics.requestRefresh(true); 640 // } 641 // return nl; 642 // } 643 644 private static void Paint(Graphics g, Image left, Image right, 645 Color background) { 646 647 // Triggers a FrameTransition is this has been signalled 648 // through an '@frameTransition: xxxx' on the frame. The type of 649 // transition is specified in the 'xxxx' part 650 651 652 // if TwinFrames mode is on, then clipping etc has to be set 653 if (DisplayIO.isTwinFramesOn()) { 654 // draw the two lines down the middle of the window 655 if (left != null) 656 left.getGraphics().drawLine(DisplayIO.getMiddle() - 2, 0, 657 DisplayIO.getMiddle() - 2, _MaxSize.height); 658 659 if (right != null) 660 right.getGraphics().drawLine(0, 0, 0, _MaxSize.height); 661 662 // set the clipping area 663 ((Graphics2D) g).setClip(0, 0, DisplayIO.getMiddle() - 1, 664 _MaxSize.height); 665 g.drawImage(left, 0, 0, Item.DEFAULT_BACKGROUND, null); 666 ((Graphics2D) g).setClip(null); 667 g.drawImage(right, DisplayIO.getMiddle() + 1, 0, 668 Item.DEFAULT_BACKGROUND, null); 669 670 671 } 672 // otherwise, just draw whichever side is active 673 else { 674 if (DisplayIO.getCurrentSide() == 0) { 675 if (!paintTransition(g,left)) { 676 // Nothing fancy occurred, just need to render the next slide to screen 677 g.drawImage(left, 0, 0, Item.DEFAULT_BACKGROUND, null); 678 } 679 } 680 else { 681 if (!paintTransition(g,right)) { 682 // Nothing fancy occurred, just need to render the next slide to screen 683 g.drawImage(right, 0, 0, Item.DEFAULT_BACKGROUND, null); 684 } 685 } 686 } 687 688 } 689 690 691 private static boolean paintTransition(Graphics g, Image image) 692 { 693 boolean performed_transition = false; 694 695 //If we are doing a transition 696 if(FrameTransitions.getSlide() == true){ 697 698 String input = "org.expeditee.gui.FrameTransitions"; 699 String slide_mode_method = FrameTransitions.getslideModeMethod(); 700 701 try { 702 Class<?> c = Class.forName(input); 703 704 Class[] cArg = new Class[3]; 705 cArg[0] = Graphics.class; 706 cArg[1] = Image.class; 707 cArg[2] = Dimension.class; 708 709 //Gets the method of transition and calls it 710 Method lMethod = c.getDeclaredMethod(slide_mode_method, cArg); 711 712 if(lMethod != null){ 713 // calling static method, so no class parameter needed 714 Object o = lMethod.invoke(null, g, image, _MaxSize); 715 performed_transition = true; 716 717 } 718 else{ 719 System.err.println("Unable to locate the transition '" + slide_mode_method + "'"); 720 } 721 722 } catch (Exception e) { 723 724 System.err.println("An Reflection Exception occurred trying to invoke '" + slide_mode_method + "'"); 725 e.printStackTrace(); 726 } 727 } 728 //Tells the frame to only transition once 729 FrameTransitions.setSlideFalse(); 730 731 return performed_transition; 732 } 733 734 735 public static void Clear() { 736 Graphics g = _DisplayGraphics.create(); 737 g.setColor(Color.WHITE); 738 g.fillRect(0, 0, _MaxSize.width, _MaxSize.height); 739 g.dispose(); 740 } 741 742 private static void PaintNonLinesNonPicture(Graphics2D g, List<Item> toPaint) { 743 for (Item i : toPaint) 744 if (!(i instanceof Line) && !(i instanceof XRayable)) 745 PaintItem(g, i); 312 if(current != null) current.paintTooltip(); 313 if (_lastToolTippedItem != null) _lastToolTippedItem.clearTooltips(); 314 _lastToolTippedItem = current; 315 } 316 317 if (FreeItems.hasCursor() && DisplayController.getCursor() == Item.DEFAULT_CURSOR) { 318 PaintNonLinesNonPicture(FreeItems.getCursor()); 319 } 320 } 321 322 private static void PaintNonLinesNonPicture(List<Item> toPaint) 323 { 324 for (Item i : toPaint) { 325 if (!(i instanceof Line) && !(i instanceof XRayable)) { 326 PaintItem(i); 327 } 328 } 746 329 } 747 330 … … 752 335 * @param toPaint 753 336 */ 754 private static void PaintLines(Graphics2D g, List<Item> toPaint) { 337 private static void PaintLines(List<Item> toPaint) 338 { 755 339 // Use this set to keep track of the items that have been painted 756 340 Collection<Item> done = new HashSet<Item>(); 757 for (Item i : toPaint) 341 for (Item i : toPaint) { 758 342 if (i instanceof Line) { 759 343 Line l = (Line) i; 760 344 if (done.contains(l)) { 761 l.paintArrows( g);345 l.paintArrows(); 762 346 } else { 763 347 // When painting a line all connected lines are painted too 764 348 done.addAll(l.getAllConnected()); 765 if (l.getStartItem().getEnclosedArea() == 0) 766 PaintItem(g, i);767 768 349 if (l.getStartItem().getEnclosedArea() == 0) PaintItem(i); 350 } 351 } 352 } 769 353 } 770 354 … … 776 360 * @param toPaint 777 361 */ 778 private static void PaintPictures( Graphics2D g, List<Item> toPaint,779 HashSet<Item> fillOnlyItems, HashSet<Item> done){362 private static void PaintPictures(List<Item> toPaint, HashSet<Item> fillOnlyItems, HashSet<Item> done) 363 { 780 364 781 365 List<Item> toFill = new LinkedList<Item>(); … … 783 367 // Ignore items that have already been done! 784 368 // Also ignore invisible items.. 785 // TODO possibly ignore invisible items before coming to this 786 // method? 787 if (done.contains(i)) 788 continue; 369 // TODO possibly ignore invisible items before coming to this method? 370 if (done.contains(i)) continue; 371 789 372 if (i instanceof XRayable) { 790 373 toFill.add(i); … … 792 375 } else if (i.hasEnclosures()) { 793 376 for (Item enclosure : i.getEnclosures()) { 794 if (!toFill.contains(enclosure)) 795 toFill.add(enclosure); 377 if (!toFill.contains(enclosure)) toFill.add(enclosure); 796 378 } 797 379 done.addAll(i.getConnected()); 798 } else if (i.isLineEnd() 799 && (!isAudienceMode() || !i.isConnectedToAnnotation())) { 380 } else if (i.isLineEnd() && (!DisplayController.isAudienceMode() || !i.isConnectedToAnnotation())) { 800 381 toFill.add(i); 801 382 done.addAll(i.getAllConnected()); … … 805 386 if (fillOnlyItems != null) { 806 387 for (Item i : fillOnlyItems) { 807 if (done.contains(i)) 388 if (done.contains(i)) { 808 389 continue; 809 else if (!isAudienceMode() || !i.isConnectedToAnnotation()) {390 } else if (!DisplayController.isAudienceMode() || !i.isConnectedToAnnotation()) { 810 391 toFill.add(i); 811 392 } … … 821 402 int cmp = aArea.compareTo(bArea); 822 403 if (cmp == 0) { 823 // System.out.println(a.getEnclosureID() + " " +824 // b.getID());\825 404 // Shapes to the left go underneath 826 Polygon pA = a.getEnclosedShape(); 827 Polygon pB = b.getEnclosedShape(); 828 if (pA == null || pB == null) 829 return 0; 830 return new Integer(pA.getBounds().x).compareTo(pB 831 .getBounds().x); 405 PolygonBounds pA = a.getEnclosedShape(); 406 PolygonBounds pB = b.getEnclosedShape(); 407 if (pA == null || pB == null) return 0; 408 return new Integer(pA.getMinX()).compareTo(pB.getMinX()); 832 409 } 833 410 return cmp * -1; 834 411 } 835 412 }); 413 836 414 for (Item i : toFill) { 837 415 if (i instanceof XRayable) { 838 PaintItem( g,i);416 PaintItem(i); 839 417 } else { 840 418 // Paint the fill and lines 841 i.paintFill( g);419 i.paintFill(); 842 420 List<Line> lines = i.getLines(); 843 if (lines.size() > 0) 844 PaintItem(g, lines.get(0)); 845 } 421 if (lines.size() > 0) PaintItem(lines.get(0)); 422 } 423 } 424 } 425 426 /** Displays the given Item on the screen. */ 427 static void PaintItem(Item i) 428 { 429 if (i == null) return; 430 431 // do not paint annotation items in audience mode 432 if (!DisplayController.isAudienceMode() || (!i.isConnectedToAnnotation() && !i.isAnnotation()) || i == FrameUtils.getLastEdited()) 433 { 434 i.paint(); 846 435 } 847 436 } … … 862 451 // Check if within 20% of the end of the line 863 452 Line l = (Line) i; 864 Item toDisconnect = l.getEndPointToDisconnect(Math 865 .round(FrameMouseActions.MouseX), Math 866 .round(FrameMouseActions.MouseY)); 453 Item toDisconnect = l.getEndPointToDisconnect(DisplayController.getMousePosition()); 867 454 868 455 // Brook: Widget Edges do not have such a context 869 456 if (toDisconnect != null && !(i instanceof WidgetEdge)) { 870 457 Item.HighlightMode newMode = toDisconnect.getHighlightMode(); 871 if (FreeItems. itemsAttachedToCursor())458 if (FreeItems.hasItemsAttachedToCursor()) 872 459 newMode = Item.HighlightMode.Normal; 873 460 // unhighlight all the other dots 874 461 for (Item conn : toDisconnect.getAllConnected()) { 875 462 conn.setHighlightMode(Item.HighlightMode.None); 463 conn.setHighlightColorToDefault(); 876 464 } 877 465 l.setHighlightMode(newMode); 466 l.setHighlightColorToDefault(); 878 467 // highlight the dot that will be in disconnect mode 879 468 toDisconnect.setHighlightMode(newMode); 469 toDisconnect.setHighlightColorToDefault(); 880 470 i = toDisconnect; 881 471 } else { 882 if (FrameMouseActions.isShiftDown()) {472 if (StandardInputEventListeners.kbmStateListener.isKeyDown(Key.SHIFT)) { 883 473 for(Item j : i.getAllConnected()) { 884 474 if(j instanceof Dot && !j.equals(i)) { 885 475 j.setHighlightMode(HighlightMode.None); 476 j.setHighlightColorToDefault(); 886 477 } 887 478 } 888 479 l.getStartItem().setHighlightMode(HighlightMode.Connected); 480 l.getStartItem().setHighlightColorToDefault(); 889 481 l.getEndItem().setHighlightMode(HighlightMode.Connected); 482 l.getEndItem().setHighlightColorToDefault(); 890 483 } else { 891 484 for(Item j : i.getAllConnected()) { 892 485 if(j instanceof Dot && !j.equals(i)) { 893 486 j.setHighlightMode(HighlightMode.Connected); 487 j.setHighlightColorToDefault(); 894 488 } 895 489 } … … 902 496 } else if (i instanceof Circle) { 903 497 i.setHighlightMode(Item.HighlightMode.Connected); 498 i.setHighlightColorToDefault(); 904 499 } else if (!i.isVisible()) { 905 500 changeHighlightMode(i, Item.HighlightMode.Connected, null); … … 913 508 // highlight connected dots, but only if there aren't items being carried on the cursor 914 509 if(FreeItems.getInstance().size() == 0) { 915 if (FrameMouseActions.isShiftDown()) {510 if (StandardInputEventListeners.kbmStateListener.isKeyDown(Key.SHIFT)) { 916 511 for(Item j : i.getAllConnected()) { 917 512 if(j instanceof Dot && !j.equals(i)) { 918 513 j.setHighlightMode(HighlightMode.Connected); 514 j.setHighlightColorToDefault(); 919 515 } 920 516 } … … 923 519 if(j instanceof Dot && !j.equals(i)) { 924 520 j.setHighlightMode(HighlightMode.None); 521 j.setHighlightColorToDefault(); 925 522 } 926 523 } … … 928 525 Item j = l.getOppositeEnd(i); 929 526 j.setHighlightMode(HighlightMode.Connected); 527 j.setHighlightColorToDefault(); 930 528 } 931 529 } … … 936 534 // For polygons need to make sure all other endpoints are 937 535 // unHighlighted 938 if (i.hasPermission(UserAppliedPermission.full)) 939 changeHighlightMode(i, Item.HighlightMode.Normal, 940 Item.HighlightMode.None); 941 else 942 changeHighlightMode(i, Item.HighlightMode.Connected, 943 Item.HighlightMode.Connected); 944 } 945 Repaint(); 536 if (i.hasPermission(UserAppliedPermission.full)) { 537 changeHighlightMode(i, Item.HighlightMode.Normal, Item.HighlightMode.None); 538 } else { 539 changeHighlightMode(i, Item.HighlightMode.Connected, Item.HighlightMode.Connected); 540 } 541 } 542 DisplayController.requestRefresh(true); 946 543 return i; 947 544 } 948 545 949 public static void changeHighlightMode(Item item, Item.HighlightMode newMode) { 546 public static void changeHighlightMode(Item item, Item.HighlightMode newMode) 547 { 950 548 changeHighlightMode(item, newMode, newMode); 951 549 } 952 550 953 public static void changeHighlightMode(Item item, 954 Item.HighlightMode newMode, Item.HighlightMode connectedNewMode) { 955 if (item == null) 956 return; 551 public static void changeHighlightMode(Item item, Item.HighlightMode newMode, Item.HighlightMode connectedNewMode) 552 { 553 if (item == null) return; 957 554 958 555 if (item.hasVector()) { … … 960 557 if (i.getEditTarget() == item) { 961 558 i.setHighlightMode(newMode); 559 i.setHighlightColorToDefault(); 962 560 } 963 561 } 964 562 item.setHighlightMode(newMode); 563 item.setHighlightColorToDefault(); 965 564 } else { 966 565 // Mike: TODO comment on why the line below is used!! 967 // I forgot already!! Opps566 // I forgot already!! Oops 968 567 boolean freeItem = FreeItems.getInstance().contains(item); 969 568 for (Item i : item.getAllConnected()) { 970 569 if (/* freeItem || */!FreeItems.getInstance().contains(i)) { 971 570 i.setHighlightMode(connectedNewMode); 972 } 973 } 974 if (!freeItem && newMode != connectedNewMode) 571 i.setHighlightColorToDefault(); 572 } 573 } 574 if (!freeItem && newMode != connectedNewMode) { 975 575 item.setHighlightMode(newMode); 976 } 977 Repaint(); 978 } 979 980 /** 981 * Repaints the buffer of the given Frame. 982 * 983 * @param toUpdate 984 * The Frame whose buffer is to be repainted. 985 */ 986 987 public static void UpdateBuffer(Frame toUpdate, boolean paintOverlays, 988 boolean useVolitile) { 989 toUpdate.setBuffer(getBuffer(toUpdate, paintOverlays, useVolitile)); 990 } 991 992 public static Image getBuffer(Frame toUpdate, boolean paintOverlays, 993 boolean useVolitile) { 994 if (toUpdate == null) 995 return null; 996 997 return Paint(toUpdate, null, paintOverlays, useVolitile); 998 } 999 1000 public static int getMode() { 1001 return _Mode; 1002 } 1003 1004 public static Graphics createGraphics() { 1005 // Error messages on start up will call this message before 1006 // _DisplayGraphics has been initialised 1007 if (_DisplayGraphics == null) 1008 return null; 1009 return _DisplayGraphics.create(); 1010 } 1011 1012 // Damaged areas pending to render. Accessessed by multiple threads 1013 private static HashSet<Rectangle> damagedAreas = new HashSet<Rectangle>(); 1014 1015 /** The clip used while paiting */ 1016 private static Area currentClip; 1017 1018 /** 1019 * The current clip that is used for painting at this instant. 1020 * 1021 * Intention: for extra clipping within an items paint method - the clip is 1022 * lost in the graphics object for which can be regained via this method. 1023 * 1024 * @return The current clip. Null if no clip (e.g. full screen render). 1025 */ 1026 public static Area getCurrentClip() { 1027 return (currentClip != null) ? (Area) currentClip.clone() : null; 1028 } 1029 1030 /** 1031 * Checks that the item is visible (on current frame && overlays) - if 1032 * visible then damaged area will be re-rendered on the next refresh. 1033 * 1034 * @param damagedItem 1035 * @param toRepaint 1036 */ 1037 public static void invalidateItem(Item damagedItem, Rectangle toRepaint) { 1038 // Only add area to repaint if item is visible... 1039 if (ItemUtils.isVisible(damagedItem)) { 1040 synchronized (damagedAreas) { 1041 damagedAreas.add(toRepaint); 1042 } 1043 } else if (MessageBay.isMessageItem(damagedItem)) { 1044 MessageBay.addDirtyArea(toRepaint); 1045 } 1046 } 1047 1048 /** 1049 * The given area will be re-rendered in the next refresh. This is the 1050 * quicker version and is more useful for re-rendering animated areas. 1051 * 1052 * @param toRepaint 1053 */ 1054 public static void invalidateArea(Rectangle toRepaint) { 1055 synchronized (damagedAreas) { 1056 damagedAreas.add(toRepaint); 1057 } 1058 } 1059 1060 public static void clearInvalidAreas() { 1061 synchronized (damagedAreas) { 1062 damagedAreas.clear(); 1063 } 1064 } 1065 1066 /** 1067 * Invalidates the buffered image of the current Frame and forces it to be 1068 * repainted on to the screen. Repaints all items. This is more expensive 1069 * than refresh. 1070 */ 1071 public static void ForceRepaint() { // TODO: TEMP: Use refresh 1072 Frame current = DisplayIO.getCurrentFrame(); 1073 1074 if (current == null) 1075 return; 1076 refresh(false); 1077 } 1078 1079 public static void Repaint() { // TODO: TEMP: Use refresh 1080 refresh(true); 1081 } 1082 1083 /** 1084 * Called to refresh the display screen. Thread safe. 1085 */ 1086 public static void refresh(boolean useInvalidation) { 1087 1088 if (_DisplayGraphics == null || _MaxSize.width <= 0 1089 || _MaxSize.height <= 0) 1090 return; 1091 1092 currentClip = null; 1093 if (useInvalidation) { // build clip 1094 1095 synchronized (damagedAreas) { 1096 if (!damagedAreas.isEmpty()) { 1097 1098 for (Rectangle r : damagedAreas) { 1099 if (currentClip == null) 1100 currentClip = new Area(r); 1101 else 1102 currentClip.add(new Area(r)); 1103 } 1104 damagedAreas.clear(); 1105 1106 } else if (MessageBay.isDirty()) { 1107 // Paint dirty message bay 1108 Graphics dg = _DisplayGraphics.create(); 1109 MessageBay.refresh(true, dg, Item.DEFAULT_BACKGROUND); 1110 return; 1111 1112 } else 1113 return; // nothing to render 1114 } 1115 1116 } else { 1117 synchronized (damagedAreas) { 1118 damagedAreas.clear(); 1119 } 1120 // System.out.println("FULLSCREEN REFRESH"); // TODO: REMOVE 1121 } 1122 1123 Frame[] toPaint = DisplayIO.getFrames(); 1124 Image left = Paint(toPaint[0], currentClip); 1125 Image right = Paint(toPaint[1], currentClip); 1126 1127 Graphics dg = _DisplayGraphics.create(); 1128 1129 // Paint frame to window 1130 Paint(dg, left, right, Item.DEFAULT_BACKGROUND); 1131 1132 // Paint any animations 1133 PopupManager.getInstance().paintAnimations(); 1134 1135 // Paint message bay 1136 MessageBay.refresh(useInvalidation, dg, Item.DEFAULT_BACKGROUND); 1137 1138 dg.dispose(); 1139 } 1140 1141 /** 1142 * If wanting to refresh from another thread - other than the main thread 1143 * that handles the expeditee datamodel (modifying / accessing / rendering). 1144 * Use this method for thread safety. 1145 */ 1146 public static synchronized void requestRefresh(boolean useInvalidation) { 1147 1148 _requestMarsheller._useInvalidation = useInvalidation; 1149 1150 if (_requestMarsheller._isQueued) { 1151 return; 1152 } 1153 1154 _requestMarsheller._isQueued = true; 1155 EventQueue.invokeLater(_requestMarsheller); // Render on AWT thread 1156 } 1157 1158 private static RenderRequestMarsheller _requestMarsheller = new FrameGraphics().new RenderRequestMarsheller(); 1159 1160 /** 1161 * Used for marshelling render requests from foreign threads to the event 1162 * dispatcher thread... (AWT) 1163 * 1164 * @author Brook Novak 1165 */ 1166 private class RenderRequestMarsheller implements Runnable { 1167 1168 boolean _useInvalidation = true; 1169 1170 boolean _isQueued = false; 1171 1172 public void run() { 1173 refresh(_useInvalidation); 1174 _isQueued = false; 1175 _useInvalidation = true; 1176 } 1177 1178 } 1179 576 item.setHighlightColorToDefault(); 577 } 578 } 579 DisplayController.requestRefresh(true); 580 } 581 582 /* 583 * 584 * FrameRenderPass stuff. (TODO: Not sure if this is used for anything? In Apollo. cts16) 585 * 586 */ 587 1180 588 /** 1181 589 * Adds a FinalFrameRenderPass to the frame-render pipeline... … … 1221 629 * situations. 1222 630 * 1223 * Although if there are multiples FinalFrameRenderPasses atta tach to the1224 * frame painter then it is not g araunteed to be rendered very last.631 * Although if there are multiples FinalFrameRenderPasses attach to the 632 * frame painter then it is not guaranteed to be rendered very last. 1225 633 * 1226 634 * @see FrameGraphics#addFinalFrameRenderPass(org.expeditee.gui.FrameGraphics.FrameRenderPass) … … 1236 644 * 1237 645 * @return The clip that the pass should use instead. i.e. if there are 1238 * any effects that cannot inv ladate prior to paint call.646 * any effects that cannot invalidate prior to paint call. 1239 647 */ 1240 Area paintStarted(AreacurrentClip);1241 1242 void paintFinalPass( Graphics g);1243 1244 void paintPreLayeredPanePass( Graphics g);648 Clip paintStarted(Clip currentClip); 649 650 void paintFinalPass(); 651 652 void paintPreLayeredPanePass(); 1245 653 } 1246 654 -
trunk/src/org/expeditee/gui/FrameIO.java
r997 r1102 195 195 } 196 196 197 public static Frame LoadFrame(String frameName, String path, 198 boolean ignoreAnnotations) { 199 if (!isValidFrameName(frameName)) 200 return null; 197 public static Frame LoadFrame(String frameName, String path, boolean ignoreAnnotations) 198 { 199 if (!isValidFrameName(frameName)) return null; 201 200 202 201 String frameNameLower = frameName.toLowerCase(); 203 202 // first try reading from cache 204 203 if (isCacheOn() && _Cache.containsKey(frameNameLower)) { 205 Logger.Log(Logger.SYSTEM, Logger.LOAD, "Loading " + frameName 206 + " from cache."); 204 Logger.Log(Logger.SYSTEM, Logger.LOAD, "Loading " + frameName + " from cache."); 207 205 Frame frame = _Cache.get(frameNameLower); 208 206 return frame; … … 389 387 390 388 public static boolean canAccessFrame(String frameName) { 391 Frame current = Display IO.getCurrentFrame();389 Frame current = DisplayController.getCurrentFrame(); 392 390 // Just in case the current frame is not yet saved... 393 391 if (frameName.equals(current.getName())) { … … 490 488 491 489 _UseCache = false; 492 Frame fresh = FrameIO.LoadFrame(Display IO.getCurrentFrame().getName());490 Frame fresh = FrameIO.LoadFrame(DisplayController.getCurrentFrame().getName()); 493 491 _UseCache = cache; 494 492 if (_Cache.containsKey(fresh.getName().toLowerCase())) 495 493 addToCache(fresh); 496 Display IO.setCurrentFrame(fresh, false);494 DisplayController.setCurrentFrame(fresh, false); 497 495 } 498 496 … … 599 597 600 598 public static Frame LoadZero() { 601 Frame current = Display IO.getCurrentFrame();599 Frame current = DisplayController.getCurrentFrame(); 602 600 return LoadZero(current.getFramesetName(), current.getPath()); 603 601 } 604 602 605 603 public static Frame LoadLast() { 606 Frame current = Display IO.getCurrentFrame();604 Frame current = DisplayController.getCurrentFrame(); 607 605 return LoadLast(current.getFramesetName(), current.getPath()); 608 606 } 609 607 610 608 public static Frame LoadNext() { 611 return LoadNext(Display IO.getCurrentFrame());609 return LoadNext(DisplayController.getCurrentFrame()); 612 610 } 613 611 614 612 public static Frame LoadPrevious() { 615 return LoadPrevious(Display IO.getCurrentFrame());613 return LoadPrevious(DisplayController.getCurrentFrame()); 616 614 } 617 615 … … 747 745 } 748 746 749 // Remove the old frame from the ca she then add the new one747 // Remove the old frame from the cache then add the new one 750 748 // TODO figure out some way that we can put both in the cache 751 749 _Cache.remove(template.getName().toLowerCase()); … … 770 768 Item titleItem = template.getTitleItem(); 771 769 772 if (!Display IO.isTwinFramesOn() && !Justification.center.equals(((Text)titleItem).getJustification())) {770 if (!DisplayController.isTwinFramesOn() && !Justification.center.equals(((Text)titleItem).getJustification())) { 773 771 if ((titleItem.getX() + 1) < template.getNameItem().getX()) { 774 772 while (titleItem.getSize() > Text.MINIMUM_FONT_SIZE … … 811 809 } 812 810 813 public static void RefreshCasheImages() { 811 public static void RefreshCacheImages() 812 { 814 813 SuspendCache(); 815 for (Frame f : _Cache.values()) 816 f.setBuffer(null); 814 for (Frame frame : _Cache.values()) frame.setBuffer(null); 817 815 ResumeCache(); 818 816 } … … 1152 1150 * @return true if the frame is in the current user profile frameset 1153 1151 */ 1154 public static boolean isProfileFrame(Frame toCheck) { 1155 if (toCheck.getNumber() == 0) 1156 return false; 1152 public static boolean isProfileFrame(Frame toCheck) 1153 { 1154 if (toCheck.getNumber() == 0) return false; 1155 1157 1156 return toCheck.getPath().equals(PROFILE_PATH); 1158 1157 // return toCheck.getFramesetName() … … 1160 1159 } 1161 1160 1162 public static Frame LoadProfile(String userName) { 1161 public static Frame LoadProfile(String userName) 1162 { 1163 1163 return LoadFrame(userName + "1"); 1164 1164 } … … 1299 1299 String templateLink = linker.getAbsoluteLinkTemplate(); 1300 1300 String framesetLink = linker.getAbsoluteLinkFrameset(); 1301 String frameset = (framesetLink != null ? framesetLink : Display IO1301 String frameset = (framesetLink != null ? framesetLink : DisplayController 1302 1302 .getCurrentFrame().getFramesetName()); 1303 1303 … … 1322 1322 */ 1323 1323 public static Frame CreateNewFrameset(String name) throws Exception { 1324 String path = Display IO.getCurrentFrame().getPath();1324 String path = DisplayController.getCurrentFrame().getPath(); 1325 1325 1326 1326 // if current frameset is profile directory change it to framesets … … 1394 1394 } 1395 1395 1396 public static Frame CreateFrameset(String frameset, String path, 1397 boolean recreate) throws Exception{1396 public static Frame CreateFrameset(String frameset, String path, boolean recreate) throws Exception 1397 { 1398 1398 String conversion = frameset + " --> "; 1399 1399 1400 if (!isValidFramesetName(frameset)) { 1401 throw new Exception("Invalid frameset name"); 1402 } 1400 if (!isValidFramesetName(frameset)) throw new Exception("Invalid frameset name"); 1403 1401 1404 1402 if (!recreate && FrameIO.canAccessFrameset(frameset)) { … … 1474 1472 SaveFrame(base, true); 1475 1473 1476 Logger.Log(Logger.SYSTEM, Logger.NEW_FRAMESET, "Created new frameset: " 1477 + frameset); 1474 Logger.Log(Logger.SYSTEM, Logger.NEW_FRAMESET, "Created new frameset: " + frameset); 1478 1475 1479 1476 return base; -
trunk/src/org/expeditee/gui/FrameKeyboardActions.java
r1077 r1102 19 19 package org.expeditee.gui; 20 20 21 import java.awt.Color;22 import java.awt.Rectangle;23 21 import java.awt.Toolkit; 24 22 import java.awt.datatransfer.StringSelection; 25 23 import java.awt.event.KeyEvent; 26 24 import java.awt.event.KeyListener; 27 import java.awt.geom.Point2D;28 25 import java.text.NumberFormat; 29 26 import java.util.ArrayList; … … 37 34 import org.expeditee.actions.Navigation; 38 35 import org.expeditee.actions.Simple; 36 import org.expeditee.core.AxisAlignedBoxBounds; 37 import org.expeditee.core.Colour; 38 import org.expeditee.core.Point; 39 39 import org.expeditee.gui.indirect.keyboard.IndirectKeyboardActions; 40 40 import org.expeditee.gui.indirect.keyboard.KeyboardAction; … … 51 51 import org.expeditee.items.XRayable; 52 52 import org.expeditee.items.MagneticConstraint.MagneticConstraints; 53 import org.expeditee.items.widgets.InteractiveWidget; 53 /*import org.expeditee.items.widgets.InteractiveWidget; TODO: Reinstate. cts16 54 54 import org.expeditee.items.widgets.WidgetCorner; 55 import org.expeditee.items.widgets.WidgetEdge; 55 import org.expeditee.items.widgets.WidgetEdge;*/ 56 56 import org.expeditee.settings.experimental.ExperimentalFeatures; 57 57 import org.expeditee.settings.templates.TemplateSettings; … … 60 60 import org.expeditee.stats.SessionStats; 61 61 62 public class FrameKeyboardActions implements KeyListener{62 public class FrameKeyboardActions { 63 63 64 64 private static FrameKeyboardActions _instance = new FrameKeyboardActions(); 65 65 66 66 protected FrameKeyboardActions() { 67 IndirectKeyboardActions.getInstance().setDropDownAction(67 /*IndirectKeyboardActions.getInstance().setDropDownAction( 68 68 new KeyboardAction() { 69 69 @Override … … 82 82 } else { 83 83 // Move to the top of the box 84 Rectangle rect = info.firstConnected 85 .getEnclosedShape().getBounds(); 86 int newX = rect.x + Text.MARGIN_LEFT; 84 AxisAlignedBoxBounds rect = info.firstConnected.getBounds(); 85 int newX = rect.getMinX() + Text.MARGIN_LEFT; 87 86 int newY = Text.MARGIN_LEFT 88 + rect. y87 + rect.getMinY() 89 88 + DisplayIO.getCurrentFrame() 90 89 .getItemTemplate() … … 171 170 return null; 172 171 } 173 }); 172 });*/ 174 173 IndirectKeyboardActions.getInstance().setCreateNewTextAction( 175 174 new KeyboardAction() { … … 179 178 "" + c); 180 179 181 Point2D.Float newMouse = t.insertChar(c, 182 DisplayIO.getMouseX(), FrameMouseActions.getY()); 183 DisplayIO.setCursorPosition(newMouse.x, newMouse.y, 184 false); 180 Point newMouse = t.insertChar(c, DisplayIO.getMouseX(), FrameMouseActions.getY()); 181 DisplayIO.setCursorPosition(newMouse.x, newMouse.y, false); 185 182 186 183 return t; … … 192 189 public Text exec(final KeyboardInfo info, final char c) { 193 190 float oldY = FrameMouseActions.MouseY; 194 Point 2D.FloatnewMouse = null;191 Point newMouse = null; 195 192 if (c == '\t') { 196 193 if (info.isShiftDown) { … … 212 209 // float diff = newMouse.y - oldY; 213 210 // System.out.print("c"); 214 Rectangle rect = info.firstConnected.getPolygon().getBounds();211 AxisAlignedBoxBounds rect = info.firstConnected.getBounds(); 215 212 216 213 // Text lastEdited = FrameUtils.getLastEdited(); … … 218 215 219 216 Item justBelow = FrameUtils.onItem(DisplayIO.getCurrentFrame(), 220 info.firstConnected.getX() + 10, rect. y + rect.height+ 1, false);217 info.firstConnected.getX() + 10, rect.getMinY() + rect.getHeight() + 1, false); 221 218 222 219 // FrameUtils.setLastEdited(lastEdited); … … 242 239 } 243 240 244 private static Text _toRemove = null;245 246 private static Collection<Item> _enclosedItems = null;247 248 public static void resetEnclosedItems() {249 _enclosedItems = null;250 }251 252 241 public synchronized void keyTyped(KeyEvent e) { 253 242 if (Simple.isProgramRunning()) { 254 if (e.isControlDown() 255 && (e.getKeyChar() == KeyEvent.VK_ESCAPE || e.getKeyChar() == KeyEvent.VK_C)) { 243 if (e.isControlDown() && (e.getKeyChar() == KeyEvent.VK_ESCAPE || e.getKeyChar() == KeyEvent.VK_C)) { 256 244 Simple.stop(); 257 245 return; … … 262 250 Simple.KeyStroke(e.getKeyChar()); 263 251 } 264 if (Simple.consumeKeyboardInput())265 252 253 if (Simple.consumeKeyboardInput()) return; 266 254 } 267 255 … … 284 272 // System.out.println(ch); 285 273 286 if (e.isAltDown()) { 287 288 } else { 289 processChar(ch, e.isShiftDown()); 290 } 274 if (!e.isAltDown()) processChar(ch, e.isShiftDown()); 291 275 // FrameGraphics.Repaint(); 292 }293 294 public static void processChar(char ch, boolean isShiftDown) {295 Navigation.ResetLastAddToBack();296 Item on = FrameUtils.getCurrentItem();297 298 // permission check299 if (on != null && !on.hasPermission(UserAppliedPermission.full)) {300 MessageBay301 .displayMessage("Insufficient permission to edit this item");302 return;303 }304 305 if (isShiftDown && MagneticConstraints.getInstance().keyHit(-ch, on))306 return;307 else if (MagneticConstraints.getInstance().keyHit(ch, on))308 return;309 310 if (_toRemove != null && on != _toRemove) {311 assert (_toRemove.getLength() == 0);312 // This line is to protect mistaken removal of items if there is a313 // bug...314 if (_toRemove.getLength() == 0)315 DisplayIO.getCurrentFrame().removeItem(_toRemove);316 }317 _toRemove = null;318 319 // ignore delete and backspace if in free space320 if ((on == null || !(on instanceof Text))321 && (ch == KeyEvent.VK_BACK_SPACE || ch == KeyEvent.VK_TAB || ch == KeyEvent.VK_DELETE))322 return;323 324 SessionStats.TypedChar(ch);325 326 // check for dot's being replaced with text327 if (on != null && on instanceof Dot && !(on instanceof WidgetCorner)) {328 if (ch == KeyEvent.VK_BACK_SPACE || ch == KeyEvent.VK_DELETE) {329 return;330 }331 replaceDot((Item) on, ch);332 return;333 }334 335 // only text can interact with keyboard events336 if (on != null && !(on instanceof Text))337 on = null;338 339 // DisplayIO.UpdateTitle();340 341 Text text = (Text) on;342 // if this text is empty but has not been removed (such as from343 // ESC-pushdown)344 if (text != null && text.isEmpty()345 && (ch == KeyEvent.VK_BACK_SPACE || ch == KeyEvent.VK_DELETE)) {346 if (text.getLines().size() > 0)347 replaceText(text);348 else {349 DisplayIO.setCursor(Item.DEFAULT_CURSOR);350 }351 return;352 }353 354 // if the user is in free space, create a new text item355 /*356 * MikeSays: Why do we have to check is highlighted... doing so causes357 * problems if you type characters to fast, they turn into multiple text358 * items. ie. JK together on the Linux laptop.359 */360 if (on == null /* || !on.isHighlighted() */) {361 // DisplayIO.UpdateTitle();362 text = createText(ch);363 text.justify(false);364 365 FrameUtils.setLastEdited(text);366 DisplayIO.setTextCursor(text, Text.NONE);367 return;368 } else {369 FrameUtils.setLastEdited(text);370 }371 372 DisplayIO.setTextCursor(text, Text.NONE);373 IndirectKeyboardActions.getInstance().getInsertCharacterAction()374 .exec(new KeyboardInfo(null, ch, isShiftDown, isShiftDown,375 _enclosedItems, text, _enclosedItems, _enclosedItems), ch);376 377 // This repaint is needed for WINDOWS only?!?!? Mike is not sure why!378 if (ch == KeyEvent.VK_DELETE)379 FrameGraphics.requestRefresh(true);380 381 // a change has occured to the Frame382 text.getParent().setChanged(true);383 384 // check that the Text item still exists (hasn't been deleted\backspaced385 // away)386 if (text.isEmpty()) {387 _toRemove = text;388 389 if (text.hasAction())390 text.setActionMark(true);391 else if (text.getLink() != null)392 text.setLinkMark(true);393 else if (text.getLines().size() > 0)394 replaceText(text);395 else {396 // DisplayIO.getCurrentFrame().removeItem(text);397 DisplayIO.setCursor(Item.DEFAULT_CURSOR);398 }399 }400 }401 402 public static Text replaceDot(Item dot, char ch) {403 Text text = createText(ch);404 Item.DuplicateItem(dot, text);405 FrameUtils.setLastEdited(text);406 407 // Copy the lines list so it can be modified408 List<Line> lines = new LinkedList<Line>(dot.getLines());409 for (Line line : lines)410 line.replaceLineEnd(dot, text);411 Frame current = dot.getParentOrCurrentFrame();412 current.removeItem(dot);413 ItemUtils.EnclosedCheck(current.getItems());414 return text;415 }416 417 /**418 * Replaces the given text item with a dot419 */420 public static Item replaceText(Item text) {421 Item dot = new Dot(text.getX(), text.getY(), text.getID());422 Item.DuplicateItem(text, dot);423 424 List<Line> lines = new LinkedList<Line>();425 lines.addAll(text.getLines());426 if (lines.size() > 0)427 dot.setColor(lines.get(0).getColor());428 for (Line line : lines) {429 line.replaceLineEnd(text, dot);430 }431 text.delete();432 Frame current = text.getParentOrCurrentFrame();433 current.addItem(dot);434 DisplayIO.setCursor(Item.DEFAULT_CURSOR);435 ItemUtils.EnclosedCheck(current.getItems());436 return dot;437 }438 439 /**440 * Creates a new Text Item whose text contains the given character. This441 * method also moves the mouse cursor to be pointing at the newly created442 * Text Item ready to insert the next character.443 *444 * @param start445 * The character to use as the initial text of this Item.446 * @return The newly created Text Item447 */448 private static Text createText(char start) {449 return IndirectKeyboardActions.getInstance().getCreateNewTextAction()450 .exec(new KeyboardInfo(null, start, false, false, _enclosedItems, _toRemove, _enclosedItems, _enclosedItems), start);451 }452 453 /**454 * Creates a new Text Item with no text. The newly created Item is a copy of455 * any ItemTemplate if one is present, and inherits all the attributes of456 * the Template457 *458 * @return The newly created Text Item459 */460 private static Text createText() {461 return DisplayIO.getCurrentFrame().createNewText();462 }463 464 private void move(int direction, boolean isShiftDown, boolean isCtrlDown) {465 Item on = FrameUtils.getCurrentItem();466 467 if ((on == null) || (on instanceof Picture)){468 navigateFrame(direction);469 return;470 }471 472 if (on instanceof Text) {473 Text text = (Text) on;474 // When the user hits the left and right button with mouse475 // positions over the the frame name navigation occurs476 if (text.isFrameName()) {477 navigateFrame(direction);478 return;479 } else {480 FrameUtils.setLastEdited(text);481 DisplayIO.setTextCursor(text, direction, false, isShiftDown,482 isCtrlDown, true);483 }484 }485 }486 487 private void navigateFrame(int direction) {488 switch (direction) {489 case Text.RIGHT:490 case Text.PAGE_UP:491 Navigation.NextFrame(false);492 break;493 case Text.LEFT:494 case Text.PAGE_DOWN:495 Navigation.PreviousFrame(false);496 break;497 case Text.HOME:498 case Text.LINE_HOME:499 Navigation.ZeroFrame();500 break;501 case Text.END:502 case Text.LINE_END:503 Navigation.LastFrame();504 break;505 }506 276 } 507 277 … … 515 285 int keyCode = e.getKeyCode(); 516 286 517 if (keyCode != KeyEvent.VK_F1 && keyCode != KeyEvent.VK_F2) { 287 // Empty the list of enclosed items if not a size-up or size-down press 288 /* if (keyCode != KeyEvent.VK_F1 && keyCode != KeyEvent.VK_F2) { 518 289 resetEnclosedItems(); 519 290 } 520 291 292 // Notify the change in stats 293 // TODO: Will changing this to the Expeditee KBMInputEvent upset stats? cts16 521 294 SessionStats.AddFrameEvent("k" + KeyEvent.getKeyText(keyCode)); 522 295 296 // Used for calculating frame stats (response time) 523 297 FrameUtils.ResponseTimer.restart(); 524 298 // e.consume(); 525 299 300 // Things that should consume input before main Expeditee 526 301 if (Actions.isAgentRunning()) { 527 302 if (keyCode == KeyEvent.VK_ESCAPE) … … 534 309 } 535 310 311 // Function keys are handled here 536 312 if (keyCode >= KeyEvent.VK_F1 && keyCode <= KeyEvent.VK_F12) { 537 functionKey(FunctionKey.values()[keyCode - KeyEvent.VK_F1 + 1], 538 e.isShiftDown(), e.isControlDown()); 539 return; 540 } else if (e.isAltDown()) { 313 functionKey(FunctionKey.values()[keyCode - KeyEvent.VK_F1 + 1], e.isShiftDown(), e.isControlDown()); 314 return; 315 }*/ 316 317 // Keyboard for mouse emulation 318 // TODO: Do we need individual mouse button clicks? Are the corresponding gestures enough? cts16 319 if (e.isAltDown()) { 541 320 int distance = e.isShiftDown() ? 1 : 20; 542 321 switch (keyCode) { … … 553 332 FrameMouseActions.rightButton(); 554 333 break; 555 case KeyEvent.VK_LEFT:334 /* case KeyEvent.VK_LEFT: 556 335 DisplayIO.translateCursor(-distance, 0); 557 336 break; … … 564 343 case KeyEvent.VK_DOWN: 565 344 DisplayIO.translateCursor(0, distance); 566 break; 567 } 568 return; 569 } 345 break;*/ 346 } 347 return; 348 } 349 350 // Notify the mouse handler of the control/shift key state 570 351 switch (keyCode) { 571 352 case KeyEvent.VK_CONTROL: … … 577 358 } 578 359 360 // Handles all CTRL+KEY combinations 579 361 if (e.isControlDown()) { 580 362 controlChar(e.getKeyCode(), e.isShiftDown()); … … 582 364 } 583 365 584 switch (keyCode) { 366 // Handles all other keystrokes (with possible shift modifier) 367 // Note: At this point e.isControlDown() must be false 368 /* switch (keyCode) { 585 369 case KeyEvent.VK_ESCAPE: 586 // Do escape after control so Ctl+Escape does not perform DropDown 587 functionKey(FunctionKey.DropDown, e.isShiftDown(), 588 e.isControlDown()); 370 // Do escape after control so Ctrl+Escape does not perform DropDown 371 functionKey(FunctionKey.DropDown, e.isShiftDown(), false); 589 372 SessionStats.Escape(); 590 373 break; 591 374 case KeyEvent.VK_LEFT: 592 move(Text.LEFT, e.isShiftDown(), e.isControlDown());375 move(Text.LEFT, e.isShiftDown(), false); 593 376 break; 594 377 case KeyEvent.VK_RIGHT: 595 move(Text.RIGHT, e.isShiftDown(), e.isControlDown());378 move(Text.RIGHT, e.isShiftDown(), false); 596 379 break; 597 380 case KeyEvent.VK_PAGE_DOWN: … … 602 385 break; 603 386 case KeyEvent.VK_UP: 604 if (e.isControlDown()) { 605 NextTextItem(FrameUtils.getCurrentItem(), false); 606 } else { 607 move(Text.UP, e.isShiftDown(), e.isControlDown()); 608 } 387 move(Text.UP, e.isShiftDown(), false); 609 388 break; 610 389 case KeyEvent.VK_DOWN: 611 if (e.isControlDown()) { 612 NextTextItem(FrameUtils.getCurrentItem(), true); 613 } else { 614 move(Text.DOWN, e.isShiftDown(), e.isControlDown()); 615 } 390 move(Text.DOWN, e.isShiftDown(), false); 616 391 break; 617 392 case KeyEvent.VK_END: 618 if (e.isControlDown()) 619 move(Text.END, e.isShiftDown(), e.isControlDown()); 620 else 621 move(Text.LINE_END, e.isShiftDown(), e.isControlDown()); 393 move(Text.LINE_END, e.isShiftDown(), false); 622 394 break; 623 395 case KeyEvent.VK_HOME: 624 if (e.isControlDown()) 625 move(Text.HOME, e.isShiftDown(), e.isControlDown()); 626 else 627 move(Text.LINE_HOME, e.isShiftDown(), e.isControlDown()); 396 move(Text.LINE_HOME, e.isShiftDown(), false); 628 397 break; 629 398 // TODO remove this when upgrading Java … … 636 405 } 637 406 break; 638 } 639 } 640 641 /** 642 * Moves the cursor to the next text item on the frame 643 * 644 * @param currentItem 645 * @param direction 646 * move up if direction is negative, down if direction is 647 * positive 648 */ 649 public static void NextTextItem(Item currentItem, boolean down) { 650 // Move the cursor to the next text item 651 Frame current = DisplayIO.getCurrentFrame(); 652 Text title = current.getTitleItem(); 653 654 Collection<Text> currentItems = FrameUtils.getCurrentTextItems(); 655 List<Text> textItems = new ArrayList<Text>(); 656 // Move to the next text item in the box if 657 if (currentItems.contains(currentItem)) { 658 textItems.addAll(currentItems); 659 } else { 660 if (title != null) 661 textItems.add(title); 662 textItems.addAll(current.getBodyTextItems(true)); 663 } 664 665 Collections.sort(textItems); 666 667 if (textItems.size() == 0) { 668 // If there are no text items on the frame its a NoOp 669 if (title == null) 670 return; 671 if (title != null) 672 DisplayIO.MoveCursorToEndOfItem(title); 673 FrameGraphics.Repaint(); 674 return; 675 } 676 677 // If the user is mouse wheeling in free space... 678 if (currentItem == null) { 679 // find the nearest item in the correct direction 680 int currY = FrameMouseActions.getY(); 681 for (int i = 0; i < textItems.size(); i++) { 682 Item t = textItems.get(i); 683 if (currY < t.getY()) { 684 if (down) { 685 DisplayIO.MoveCursorToEndOfItem(t); 686 } else { 687 if (i == 0) { 688 DisplayIO.MoveCursorToEndOfItem(current 689 .getTitleItem()); 690 } else { 691 DisplayIO.MoveCursorToEndOfItem(textItems 692 .get(i - 1)); 693 } 694 } 695 FrameGraphics.Repaint(); 696 return; 697 } 698 } 699 // If we are at the botton of the screen and the user scrolls down 700 // then scroll backup to the title 701 if (textItems.size() > 0) { 702 DisplayIO 703 .MoveCursorToEndOfItem(textItems.get(textItems.size() - 1)); 704 } 705 return; 706 } 707 708 // Find the current item... then move to the next item 709 int i = textItems.indexOf(currentItem); 710 711 int nextIndex = i + (down ? 1 : -1); 712 if (nextIndex >= 0 && nextIndex < textItems.size()) { 713 DisplayIO.MoveCursorToEndOfItem(textItems.get(nextIndex)); 714 } else { 715 DisplayIO.MoveCursorToEndOfItem(currentItem); 716 } 717 return; 718 407 }*/ 719 408 } 720 409 … … 739 428 } 740 429 741 private static void copyItemToClipboard(Item on) {742 if (on == null || !(on instanceof Text))743 return;744 745 Text text = (Text) on;746 String string = text.copySelectedText();747 748 if (string == null || string.length() == 0)749 string = text.getText();750 751 // add the text of the item to the clipboard752 StringSelection selection = new StringSelection(string);753 Toolkit.getDefaultToolkit().getSystemClipboard()754 .setContents(selection, null);755 }756 757 430 /** 758 431 * Processes all control character keystrokes. Currently Ctrl+C and Ctrl+V … … 763 436 */ 764 437 private void controlChar(int key, boolean isShiftDown) { 765 Logger.Log(Logger.USER, Logger.CONTROL_CHAR, "User pressing: Ctrl+" 766 + KeyEvent.getKeyText(key)); 438 //Logger.Log(Logger.USER, Logger.CONTROL_CHAR, "User pressing: Ctrl+" + KeyEvent.getKeyText(key)); 767 439 // 768 440 // if (FrameUtils.getCurrentItem() == null … … 776 448 int distance = isShiftDown ? 1 : 20; 777 449 switch (key) { 778 case KeyEvent.VK_HOME:450 /* case KeyEvent.VK_HOME: 779 451 if (current != null && current instanceof Text) { 780 452 move(Text.HOME, isShiftDown, true); … … 802 474 break; 803 475 case KeyEvent.VK_ESCAPE: 804 // Do escape after control so Ct l+Escape does not perform DropDown476 // Do escape after control so Ctrl+Escape does not perform DropDown 805 477 functionKey(FunctionKey.DropDown, isShiftDown, true); 806 SessionStats.Escape(); 478 SessionStats.Escape();*/ 807 479 break; 808 480 case KeyEvent.VK_1: … … 819 491 break; 820 492 case KeyEvent.VK_LEFT: 821 if (current instanceof Text) { 822 DisplayIO.setTextCursor((Text) current, Text.LEFT, false, 823 isShiftDown, true, true); 824 } else { 493 /* if (current instanceof Text) { 494 DisplayIO.setTextCursor((Text) current, Text.LEFT, false, isShiftDown, true, true); 495 } else */{ 825 496 DisplayIO.translateCursor(-distance, 0); 826 497 } 827 498 break; 828 499 case KeyEvent.VK_RIGHT: 829 if (current instanceof Text) { 830 DisplayIO.setTextCursor((Text) current, Text.RIGHT, false, 831 isShiftDown, true, true); 832 } else { 500 /* if (current instanceof Text) { 501 DisplayIO.setTextCursor((Text) current, Text.RIGHT, false, isShiftDown, true, true); 502 } else */{ 833 503 DisplayIO.translateCursor(distance, 0); 834 504 } 835 505 break; 836 case KeyEvent.VK_UP:506 /* case KeyEvent.VK_UP: 837 507 // if (current instanceof Text) { 838 508 NextTextItem(FrameUtils.getCurrentItem(), false); … … 849 519 break; 850 520 case KeyEvent.VK_L: 851 // If its not linked then link it to its self521 // If its not linked then link it to itself 852 522 if (current instanceof Text && current.getLink() == null) { 853 523 String text = ((Text) current).getText(); … … 866 536 } 867 537 break; 868 case KeyEvent.VK_G: 869 // If its not linked then link it to its self538 case KeyEvent.VK_G: // Same as CTRL+L but follows it afterwards 539 // If its not linked then link it to itself 870 540 if (current instanceof Text) { 871 541 String text = ((Text) current).getText(); … … 922 592 return; 923 593 case KeyEvent.VK_C: 924 if (FreeItems. itemsAttachedToCursor()) {594 if (FreeItems.hasItemsAttachedToCursor()) { 925 595 ItemSelection.copyClone(); 926 596 return; … … 933 603 if (current instanceof Dot && current.getLines().size() == 1) { 934 604 item = replaceDot(current, '@'); 935 } else if (current instanceof Line 936 && current.getAllConnected().size() == 3) { 605 } else if (current instanceof Line && current.getAllConnected().size() == 3) { 937 606 Item end = ((Line) current).getEndItem(); 938 607 if (end instanceof Dot) { … … 955 624 if (current == null) 956 625 return; 957 if (current != null 958 && !current.hasPermission(UserAppliedPermission.full)) { 959 MessageBay 960 .displayMessage("Insufficient permission toggle the items mark"); 961 return; 962 } 963 boolean newValue = !(current.getLinkMark() || current 964 .getActionMark()); 626 if (current != null && !current.hasPermission(UserAppliedPermission.full)) { 627 MessageBay.displayMessage("Insufficient permission toggle the items mark"); 628 return; 629 } 630 boolean newValue = !(current.getLinkMark() || current.getActionMark()); 965 631 current.setLinkMark(newValue); 966 632 current.setActionMark(newValue); … … 980 646 // perform a delete operation 981 647 FrameMouseActions.delete(current); 982 break; 648 break;*/ 983 649 case KeyEvent.VK_SPACE: 984 650 if (isShiftDown) { … … 988 654 } 989 655 break; 990 case KeyEvent.VK_F:656 /* case KeyEvent.VK_F: 991 657 // perform a format operation 992 658 if (isShiftDown) { … … 1012 678 break; 1013 679 1014 case KeyEvent.VK_R: 680 case KeyEvent.VK_R: // TODO: What is this? Similar to above? cts16 1015 681 Text textCurrent = getCurrentTextItem(); 1016 682 if (textCurrent == null) { … … 1026 692 break; 1027 693 case KeyEvent.VK_S: 1028 /* 1029 * Only split when shift is down... it is too easy to accidentally 1030 * hit Ctrl+S after completing a paragraph because this is the 1031 * shortcut for saving a document in most word processors and text 1032 * editors! 1033 */ 694 // Only split when shift is down... it is too easy to accidentally 695 // hit Ctrl+S after completing a paragraph because this is the 696 // shortcut for saving a document in most word processors and text 697 // editors! 1034 698 if (!isShiftDown) { 1035 699 Save(); … … 1057 721 currentFrame.addItem(newText); 1058 722 } 1059 break; 723 break;*/ 1060 724 case KeyEvent.VK_ENTER: 1061 725 FrameMouseActions.leftButton(); 1062 726 break; 1063 case KeyEvent.VK_BACK_SPACE:727 /* case KeyEvent.VK_BACK_SPACE: 1064 728 DisplayIO.Back(); 1065 break; 729 break;*/ 1066 730 } 1067 731 FrameGraphics.Repaint(); … … 1078 742 1079 743 if (item != null && !item.hasPermission(UserAppliedPermission.full)) { 1080 MessageBay 1081 .displayMessage("Insufficient permission to copy that item"); 744 MessageBay.displayMessage("Insufficient permission to copy that item"); 1082 745 return null; 1083 746 } … … 1093 756 } 1094 757 1095 public static void functionKey(FunctionKey key, boolean isShiftDown, 1096 boolean isControlDown){758 /* public static void functionKey(FunctionKey key, boolean isShiftDown, boolean isControlDown) 759 { 1097 760 functionKey(key, 1, isShiftDown, isControlDown); 1098 761 } 1099 762 */ 1100 763 /** 1101 764 * Called when a Function key has been pressed, and performs the specific 1102 765 * action based on the key. 1103 766 */ 1104 public static void functionKey(FunctionKey key, int repeat, 1105 boolean isShiftDown, boolean isControlDown){767 /* public static void functionKey(FunctionKey key, int repeat, boolean isShiftDown, boolean isControlDown) 768 { 1106 769 // get whatever the user is pointing at 1107 770 Item on = FrameUtils.getCurrentItem(); … … 1195 858 } 1196 859 } 860 1197 861 // Show a description of the function key pressed if the user is in free 1198 862 // space and return for the F keys that dont do anything in free space. 1199 863 if (on == null) { 1200 864 1201 int mouse_x = FrameMouseActions.getX(), mouse_y = FrameMouseActions.getY();865 // int mouse_x = FrameMouseActions.getX(), mouse_y = FrameMouseActions.getY(); 1202 866 1203 867 switch (key) { 1204 868 // These function keys still work in free space 1205 case DropDown:1206 case InsertDate:869 // case DropDown: 870 // case InsertDate: 1207 871 case XRayMode: 1208 872 case AudienceMode: 1209 873 case Refresh: 1210 case Save:874 // case Save: 1211 875 break; 1212 876 … … 1244 908 } 1245 909 } 1246 Drop(on, false);910 // Drop(on, false); 1247 911 return; 1248 912 case SizeUp: 1249 913 SetSize(on, repeat, true, false, isControlDown); 1250 914 if (on instanceof Text) { 1251 DisplayIO.setTextCursor((Text) on, Text.NONE, true, false, 1252 false, true); 915 DisplayIO.setTextCursor((Text) on, Text.NONE, true, false, false, true); 1253 916 } 1254 917 break; … … 1256 919 SetSize(on, -repeat, true, false, isControlDown); 1257 920 if (on instanceof Text) { 1258 DisplayIO.setTextCursor((Text) on, Text.NONE, true, false, 1259 false, true); 921 DisplayIO.setTextCursor((Text) on, Text.NONE, true, false, false, true); 1260 922 } 1261 923 break; … … 1300 962 MessageBay.displayMessage(displayMessage); 1301 963 } 1302 1303 private static void calculateItem(Item toCalculate) { 1304 if (toCalculate == null) 1305 return; 1306 1307 if (!toCalculate.update()) { 1308 toCalculate.setFormula(null); 1309 MessageBay.errorMessage("Can not calculate formula [" 1310 + toCalculate.getText() + ']'); 1311 } 1312 } 1313 1314 public static void Save() { 1315 Frame current = DisplayIO.getCurrentFrame(); 1316 current.change(); 1317 FrameIO.SaveFrame(current, true, true); 1318 } 1319 1320 public static final String DEFAULT_NEW_ITEM_TEXT = ""; 1321 1322 /** 1323 * Performs the dropping action: If the cursor is in free space then: the 1324 * cursor is repositioned below the last non-annotation text item. If the 1325 * cursor is on an item, and has items attached then: the cusor is 1326 * positioned below the pointed to item, and the items below are 'pushed 1327 * down' to make room. 1328 * 1329 * @param toDropFrom 1330 * The Item being pointed at by the mouse, may be null to 1331 * indicate the cursor is in free space. 1332 */ 1333 public static boolean Drop(Item toDropFrom, boolean bPasting) { 1334 try { 1335 FrameUtils.setLastEdited(null); 1336 1337 String newItemText = DEFAULT_NEW_ITEM_TEXT; 1338 1339 // if a line is being rubber-banded, this is a no-op 1340 if (Frame.rubberbandingLine()) 1341 return false; // No-op 1342 1343 // if the cursor is in free space then the drop will happen from the 1344 // last non annotation text item on the frame 1345 if (toDropFrom == null) { 1346 toDropFrom = DisplayIO.getCurrentFrame() 1347 .getLastNonAnnotationTextItem(); 1348 } 1349 1350 // if no item was found, return 1351 if (toDropFrom == null) { 1352 MessageBay.errorMessage("No item could be found to drop from"); 1353 return false; 1354 } 1355 1356 if (!(toDropFrom instanceof Text)) { 1357 MessageBay 1358 .displayMessage("Only text items can be dropped from"); 1359 return false; 1360 } 1361 1362 // Get the list of items that must be dropped 1363 List<Text> column = DisplayIO.getCurrentFrame().getColumn( 1364 toDropFrom); 1365 1366 if (column == null) { 1367 MessageBay.errorMessage("No column found to align items to"); 1368 return false; 1369 } 1370 1371 Item title = DisplayIO.getCurrentFrame().getTitleItem(); 1372 1373 // We wont do auto bulleting when dropping from titles 1374 if (!bPasting && toDropFrom != title) { 1375 newItemText = getAutoBullet(((Text) toDropFrom).getFirstLine()); 1376 } 1377 1378 Text dummyItem = null; 1379 if (!bPasting && FreeItems.textOnlyAttachedToCursor()) { 1380 dummyItem = (Text) FreeItems.getItemAttachedToCursor(); 1381 String autoBullet = getAutoBullet(dummyItem.getText()); 1382 1383 if (autoBullet.length() > 0) 1384 newItemText = ""; 1385 dummyItem.setText(newItemText + dummyItem.getText()); 1386 } 1387 1388 dummyItem = createText(); 1389 if (FreeItems.textOnlyAttachedToCursor()) { 1390 Text t = (Text) FreeItems.getItemAttachedToCursor(); 1391 dummyItem.setSize(t.getSize()); 1392 int lines = t.getTextList().size(); 1393 for (int i = 0; i < lines; i++) { 1394 newItemText += '\n'; 1395 } 1396 } 1397 1398 dummyItem.setText(newItemText); 1399 1400 // If the only item on the frame is the title and the frame name 1401 // goto the zero frame and drop to the @start if there is one 1402 // or a fixed amount if there is not 1403 if (column.size() == 0) { 1404 Frame current = DisplayIO.getCurrentFrame(); 1405 // Item itemTemplate = current.getItemTemplate(); 1406 int xPos = title.getX() + FrameCreator.INDENT_FROM_TITLE; 1407 int yPos = FrameCreator.getYStart(title); 1408 // Check for @start on the zero frame 1409 Frame zero = FrameIO.LoadFrame(current.getFramesetName() + '0'); 1410 Text start = zero.getAnnotation("start"); 1411 if (start != null) { 1412 xPos = start.getX(); 1413 yPos = start.getY(); 1414 } 1415 1416 dummyItem.setPosition(xPos, yPos); 1417 // DisplayIO.setCursorPosition(xPos, yPos); 1418 1419 checkMovingCursor(dummyItem); 1420 } else { 1421 int yPos = column.get(0).getY() + 1; 1422 int xPos = column.get(0).getX(); 1423 // Either position the new item below the title or just above 1424 // the first item below the title 1425 if (toDropFrom == title && column.get(0) != title) { 1426 // If dropping from the title position just above top item 1427 yPos = column.get(0).getY() - 1; 1428 1429 Frame current = DisplayIO.getCurrentFrame(); 1430 // Check for @start on the zero frame 1431 Frame zero = FrameIO 1432 .LoadFrame(current.getFramesetName() + '0'); 1433 Text start = zero.getAnnotation("start"); 1434 if (start != null) { 1435 yPos = Math.min(yPos, start.getY()); 1436 } 1437 } 1438 dummyItem.setPosition(xPos, yPos); 1439 column.add(dummyItem); 1440 FrameUtils.Align(column, false, 0); 1441 // Check if it will be outside the frame area 1442 if (dummyItem.getY() < 0 1443 || dummyItem.getY() > FrameGraphics.getMaxFrameSize() 1444 .getHeight()) { 1445 // Check for the 'next' tag! 1446 Frame current = DisplayIO.getCurrentFrame(); 1447 Item next = current.getAnnotation("next"); 1448 Item prev = current.getAnnotation("previous"); 1449 // Check for an unlinked next tag 1450 if ((next != null && !next.hasLink()) 1451 || (prev != null && prev.hasLink())) { 1452 Frame firstFrame = current; 1453 if (next != null) 1454 next.delete(); 1455 FrameCreator frameCreator = new FrameCreator(null); 1456 // Add the next button 1457 next = frameCreator.addNextButton(current, null); 1458 1459 // Create the new frame linked to the next tag 1460 boolean mouseMoved = FrameMouseActions.tdfc(next); 1461 Frame moreFrame = DisplayIO.getCurrentFrame(); 1462 1463 // Add previous button to the new frame 1464 frameCreator.addPreviousButton(moreFrame, 1465 firstFrame.getName()); 1466 Item first = current.getAnnotation("first"); 1467 if (first != null) { 1468 frameCreator.addFirstButton(moreFrame, 1469 first.getLink()); 1470 } else { 1471 frameCreator.addFirstButton(moreFrame, 1472 firstFrame.getName()); 1473 } 1474 // Add the @next if we are pasting 1475 // if (bPasting) { 1476 // Item copy = next.copy(); 1477 // copy.setLink(null); 1478 // moreFrame.addItem(copy); 1479 // } 1480 1481 moreFrame.setTitle(firstFrame.getTitleItem().getText()); 1482 // need to move the mouse to the top of the frame if 1483 // there wasnt an @start on it 1484 if (!mouseMoved) { 1485 Item moreTitle = moreFrame.getTitleItem(); 1486 moreTitle 1487 .setOverlayPermission(UserAppliedPermission.full); 1488 Drop(moreTitle, bPasting); 1489 } 1490 // Add the bullet text to the item 1491 dummyItem.setPosition(DisplayIO.getMouseX(), 1492 FrameMouseActions.getY()); 1493 } else { 1494 MessageBay 1495 .warningMessage("Can not create items outside the frame area"); 1496 // ensures correct repainting when items don't move 1497 DisplayIO.setCursorPosition(DisplayIO.getMouseX(), 1498 FrameMouseActions.getY()); 1499 return false; 1500 } 1501 } 1502 if (!FreeItems.textOnlyAttachedToCursor() 1503 && !dummyItem.isEmpty()) { 1504 DisplayIO.getCurrentFrame().addItem(dummyItem); 1505 } 1506 1507 checkMovingCursor(dummyItem); 1508 } 1509 if (dummyItem.getText().length() == 0 1510 || FreeItems.itemsAttachedToCursor()) { 1511 dummyItem.getParentOrCurrentFrame().removeItem(dummyItem); 1512 dummyItem.setRightMargin(FrameGraphics.getMaxFrameSize().width, 1513 false); 1514 } else { 1515 dummyItem.setWidth(toDropFrom.getWidth()); 1516 } 1517 1518 DisplayIO.resetCursorOffset(); 1519 FrameGraphics.Repaint(); 1520 } catch (RuntimeException e) { 1521 // MessageBay.errorMessage(e.getMessage()); 1522 e.printStackTrace(); 1523 return false; 1524 } 1525 return true; 1526 } 1527 1528 /** 1529 * @param dummyItem 1530 */ 1531 private static void checkMovingCursor(Text dummyItem) { 1532 // Move the item to the cursor position 1533 if (FreeItems.itemsAttachedToCursor()) { 1534 moveCursorAndFreeItems(dummyItem.getX(), dummyItem.getY()); 1535 } else { 1536 DisplayIO.MoveCursorToEndOfItem(dummyItem); 1537 } 1538 } 1539 1540 /** 1541 * @param dummyItem 1542 */ 1543 public static void moveCursorAndFreeItems(int x, int y) { 1544 int oldX = FrameMouseActions.getX(); 1545 int oldY = FrameMouseActions.getY(); 1546 1547 if (oldX == x && oldY == y) 1548 return; 1549 1550 DisplayIO.setCursorPosition(x, y); 1551 Item firstItem = FreeItems.getItemAttachedToCursor(); 1552 1553 if (firstItem == null) { 1554 firstItem = null; 1555 return; 1556 } 1557 1558 int deltaX = firstItem.getX() - x; 1559 int deltaY = firstItem.getY() - y; 1560 1561 for (Item i : FreeItems.getInstance()) { 1562 i.setPosition(i.getX() - deltaX, i.getY() - deltaY); 1563 } 1564 } 1565 1566 /** 1567 * Gets the next letter sequence for a given string to be used in auto 1568 * lettering. 1569 * 1570 * @param s 1571 * a sequence of letters 1572 * @return the next sequence of letters 1573 */ 1574 static private String nextLetterSequence(String s) { 1575 if (s.length() > 1) 1576 return s; 1577 1578 if (s.equals("z")) 1579 return "a"; 1580 1581 return (char) ((int) s.charAt(0) + 1) + ""; 1582 } 1583 1584 public static String getBullet(String s) { 1585 return getBullet(s, false); 1586 } 1587 1588 public static String getAutoBullet(String s) { 1589 return getBullet(s, true); 1590 } 1591 1592 private static String getBullet(String s, boolean nextBullet) { 1593 String newItemText = DEFAULT_NEW_ITEM_TEXT; 1594 1595 if (s == null) 1596 return newItemText; 1597 /* 1598 * Item i = ItemUtils.FindTag(DisplayIO.getCurrentFrame().getItems(), 1599 * "@NoAutoBullets"); if (i != null) return newItemText; 1600 */ 1601 // Separate the space at the start of the text item 1602 String preceedingSpace = ""; 1603 for (int i = 0; i < s.length(); i++) { 1604 if (!Character.isSpaceChar(s.charAt(i))) { 1605 preceedingSpace = s.substring(0, i); 1606 s = s.substring(i); 1607 break; 1608 } 1609 } 1610 1611 // figure out the type of the text item 1612 // This allows us to do auto bulleting 1613 if (s != null && s.length() > 1) { 1614 // First check for text beginning with * @ # etc 1615 // These are simple auto bullets 1616 if (!Character.isLetterOrDigit(s.charAt(0)) 1617 && !Character.isSpaceChar(s.charAt(0))) { 1618 if (Text.isBulletChar(s.charAt(0))) { 1619 int nonSpaceIndex = 1; 1620 // Find the end of the bullet and space after the bullet 1621 while (nonSpaceIndex < s.length() 1622 && s.charAt(nonSpaceIndex) == ' ') { 1623 nonSpaceIndex++; 1624 } 1625 // we must have a special char followed by >= 1 space 1626 if (nonSpaceIndex > 1) 1627 newItemText = s.substring(0, nonSpaceIndex); 1628 } 1629 // Auto numbering and lettering 1630 } else { 1631 if (Character.isDigit(s.charAt(0))) { 1632 newItemText = getAutoNumber(s, nextBullet); 1633 // Auto lettering 1634 } else if (Character.isLetter(s.charAt(0))) { 1635 newItemText = getAutoLetter(s, nextBullet); 1636 } 1637 } 1638 } 1639 return preceedingSpace + newItemText; 1640 } 1641 1642 private static boolean isAutoNumberOrLetterChar(char c) { 1643 return c == ':' || c == '-' || c == '.' || c == ')' || c == '>'; 1644 } 1645 1646 /** 1647 * Gets the string to be used to start the next auto numbered text item. 1648 * 1649 * @param s 1650 * the previous text item 1651 * @return the beginning of the next auto numbered text item 1652 */ 1653 private static String getAutoNumber(String s, boolean nextBullet) { 1654 String newItemText = DEFAULT_NEW_ITEM_TEXT; 1655 1656 int nonDigitIndex = 1; 1657 while (Character.isDigit(s.charAt(nonDigitIndex))) { 1658 nonDigitIndex++; 1659 1660 if (nonDigitIndex + 1 >= s.length()) 1661 return DEFAULT_NEW_ITEM_TEXT; 1662 } 1663 1664 if (isAutoNumberOrLetterChar(s.charAt(nonDigitIndex))) { 1665 1666 // we must have a number followed one non letter 1667 // then one or more spaces 1668 int nonSpaceIndex = nonDigitIndex + 1; 1669 while (nonSpaceIndex < s.length() && s.charAt(nonSpaceIndex) == ' ') { 1670 nonSpaceIndex++; 1671 } 1672 1673 if (nonSpaceIndex > nonDigitIndex + 1) { 1674 if (nextBullet) 1675 newItemText = (Integer.parseInt(s.substring(0, 1676 nonDigitIndex)) + 1) 1677 + s.substring(nonDigitIndex, nonSpaceIndex); 1678 else 1679 newItemText = s.substring(0, nonSpaceIndex); 1680 } 1681 } 1682 return newItemText; 1683 } 1684 1685 /** 1686 * Gets the string to be used to start the next auto lettered text item. 1687 * 1688 * @param s 1689 * the previous text items 1690 * @return the initial text for the new text item 1691 */ 1692 private static String getAutoLetter(String s, boolean nextBullet) { 1693 String newItemText = DEFAULT_NEW_ITEM_TEXT; 1694 1695 int nonLetterIndex = 1; 1696 1697 if (isAutoNumberOrLetterChar(s.charAt(nonLetterIndex))) { 1698 1699 // Now search for the next non space character 1700 int nonSpaceIndex = nonLetterIndex + 1; 1701 while (nonSpaceIndex < s.length() && s.charAt(nonSpaceIndex) == ' ') { 1702 nonSpaceIndex++; 1703 } 1704 1705 // If there was a space then we have reached the end of our auto 1706 // text 1707 if (nonSpaceIndex > nonLetterIndex + 1) { 1708 if (nextBullet) 1709 newItemText = nextLetterSequence(s.substring(0, 1710 nonLetterIndex)) 1711 + s.substring(nonLetterIndex, nonSpaceIndex); 1712 else 1713 newItemText = s.substring(0, nonSpaceIndex); 1714 } 1715 } 1716 return newItemText; 1717 } 1718 1719 private static boolean refreshAnchors(Collection<Item> items) { 1720 boolean bReparse = false; 1721 1722 for (Item i : items) { 1723 Float anchorLeft = i.getAnchorLeft(); 1724 Float anchorRight = i.getAnchorRight(); 1725 Float anchorTop = i.getAnchorTop(); 1726 Float anchorBottom = i.getAnchorBottom(); 1727 1728 if (anchorLeft != null) { 1729 i.setAnchorLeft(anchorLeft); 1730 if (i.hasVector()) { 1731 bReparse = true; 1732 } 1733 } 1734 1735 if (anchorRight != null) { 1736 i.setAnchorRight(anchorRight); 1737 if (i.hasVector()) { 1738 bReparse = true; 1739 } 1740 } 1741 1742 if (anchorTop != null) { 1743 i.setAnchorTop(anchorTop); 1744 if (i.hasVector()) { 1745 bReparse = true; 1746 } 1747 } 1748 1749 if (anchorBottom != null) { 1750 i.setAnchorBottom(anchorBottom); 1751 if (i.hasVector()) { 1752 bReparse = true; 1753 } 1754 } 1755 } 1756 return bReparse; 1757 } 1758 1759 protected static void zoomFrame(Frame frame, double scaleFactor, int x, int y) { 1760 1761 if (frame == null) { 1762 return; 1763 } 1764 1765 Collection<Item> items = frame.getVisibleItems(); 1766 1767 for (Item item : items) { 1768 if (item instanceof Text 1769 && item.getSize() <= Text.MINIMUM_FONT_SIZE 1770 && scaleFactor < 1) { 1771 return; 1772 } 1773 } 1774 1775 for (Vector v : frame.getVectors()) { 1776 v.Source.scale((float) scaleFactor, x, y); 1777 } 1778 1779 for (Item item : items) { 1780 // This line is only needed for circles!! 1781 // Need to really fix up the way this works!! 1782 if (item.hasEnclosures()) 1783 continue; 1784 if (!item.hasPermission(UserAppliedPermission.full)) 1785 continue; 1786 item.invalidateAll(); 1787 if (!(item instanceof Line)) { 1788 item.scale((float) scaleFactor, x, y); 1789 } 1790 } 1791 1792 for (Item item : items) { 1793 if (!item.hasPermission(UserAppliedPermission.full)) 1794 continue; 1795 // if (!(item instanceof Line)) 1796 item.updatePolygon(); 1797 1798 if (item instanceof Line) { 1799 ((Line) item).refreshStroke(item.getThickness()); 1800 } 1801 1802 item.invalidateAll(); 1803 } 1804 } 1805 1806 public static boolean zoomFrameIfEnabled(Frame frame, double scaleFactor, int mouse_x, int mouse_y) 1807 { 1808 boolean zoom_active = ExperimentalFeatures.FrameZoom.get(); 1809 1810 if (zoom_active) { 1811 1812 int x, y; 1813 if (ExperimentalFeatures.FrameZoomAroundCursor.get()) { 1814 x = mouse_x; 1815 y = mouse_y; 1816 } 1817 else { 1818 x = 0; 1819 y = 0; 1820 } 1821 1822 zoomFrame(DisplayIO.getCurrentFrame(), scaleFactor, x, y); 1823 DisplayIO.getCurrentFrame().refreshSize(); 1824 FrameKeyboardActions.Refresh(); 1825 } 1826 else { 1827 String frameZoomingDisabledMessage = "Frame Zooming currently disabled. " 1828 + "Access Settings->Experimental->FrameZoom and set to 'true' to enable this"; 1829 MessageBay.displayMessageOnce(frameZoomingDisabledMessage); 1830 } 1831 1832 return zoom_active; 1833 } 1834 1835 public static boolean zoomFrameTopLeftIfEnabled(Frame frame, double scaleFactor) 1836 { 1837 return zoomFrameIfEnabled(frame, scaleFactor, 0, 0); 1838 } 1839 1840 /** 1841 * Adjusts the size of the given Item, by the given amount. Note: The amount 1842 * is relative and can be positive or negative. 1843 * 1844 * @param toSet 1845 * The Item whose size is to be adjusted 1846 * @param diff 1847 * The amount to adjust the Item's size by 1848 * @param moveCursor 1849 * true if the cursor position should be automatically adjusted 1850 * with resizing 1851 */ 1852 public static void SetSize(Item item, int diff, boolean moveCursor, 1853 boolean insideEnclosure, boolean isControlDown) { 1854 Collection<Item> toSize = new HashSet<Item>(); 1855 Collection<InteractiveWidget> widgets = new HashSet<InteractiveWidget>(); 1856 // the mouse is only moved when the Item is on the frame, not free 1857 // boolean moveMouse = false; 1858 Item toSet = null; 1859 1860 // if the user is not pointing to any item 1861 if (item == null) { 1862 if (FreeItems.itemsAttachedToCursor()) 1863 toSize.addAll(FreeItems.getInstance()); 1864 else { 1865 MessageBay 1866 .displayMessage("There are no Items selected on the Frame or on the Cursor"); 1867 return; 1868 } 1869 } else { 1870 if (item.isFrameName()) { 1871 // scale the entire frame 1872 if (diff != 0) { 1873 double scaleFactor = diff > 0 ? 1.1 : 0.909090909; 1874 zoomFrameTopLeftIfEnabled(DisplayIO.getCurrentFrame(), scaleFactor); 1875 } 1876 // MessageBay.displayMessage("Can not resize the frame name"); 1877 return; 1878 } 1879 // check permissions 1880 if (!item.hasPermission(UserAppliedPermission.full)) { 1881 Item editTarget = item.getEditTarget(); 1882 if (editTarget != item 1883 && editTarget.hasPermission(UserAppliedPermission.full)) { 1884 item = editTarget; 1885 } else { 1886 MessageBay 1887 .displayMessage("Insufficient permission to change the size of that item"); 1888 return; 1889 } 1890 } 1891 toSet = item; 1892 // For resizing enclosures pick up everything that is attached to 1893 // items partly in the enclosure 1894 // TODO make this only pick up stuff COMPLETELY enclosed... if we 1895 // change copying to copy only the stuff completely enclosed 1896 if (insideEnclosure) { 1897 if (_enclosedItems == null) { 1898 for (Item i : FrameUtils.getCurrentItems(toSet)) { 1899 if (i.hasPermission(UserAppliedPermission.full) 1900 && !toSize.contains(i)) 1901 toSize.addAll(i.getAllConnected()); 1902 } 1903 _enclosedItems = toSize; 1904 } else { 1905 toSize = _enclosedItems; 1906 } 1907 1908 }// Enclosed circle centers are resized with the center as origin 1909 // Just add the circle center to the list of items to size 1910 else if (!toSet.hasEnclosures() && !(toSet instanceof Text) 1911 && toSet.isLineEnd()) { 1912 toSize.addAll(toSet.getLines()); 1913 } else if (toSet instanceof Line) { 1914 1915 Line line = (Line) toSet; 1916 1917 if (!(toSet instanceof WidgetEdge) 1918 || ((WidgetEdge) toSet).getWidgetSource() 1919 .isWidgetEdgeThicknessAdjustable()) { 1920 1921 float current = Math.abs(line.getThickness()); 1922 current = Math.max(current + diff, Item.MINIMUM_THICKNESS); 1923 line.setThickness(current); 1924 FrameGraphics.Repaint(); 1925 return; 1926 1927 } 1928 1929 } else { 1930 toSize.add(toSet); 1931 } 1932 } 1933 1934 // add widgets to notify 1935 for (Item i : toSize) { 1936 if (i instanceof WidgetEdge) { 1937 widgets.add(((WidgetEdge) i).getWidgetSource()); 1938 } else if (i instanceof WidgetCorner) { 1939 widgets.add(((WidgetCorner) i).getWidgetSource()); 1940 } 1941 } 1942 1943 Point2D origin = new Point2D.Float(FrameMouseActions.MouseX, 1944 FrameMouseActions.MouseY); 1945 // Inside enclosures increase the size of the enclosure 1946 double ratio = (100.0 + diff * 2) / 100.0; 1947 if (insideEnclosure) { 1948 Collection<Item> done = new HashSet<Item>(); 1949 // adjust the size of all the items 1950 for (Item i : toSize) { 1951 if (done.contains(i)) 1952 continue; 1953 1954 if (i.isLineEnd()) { 1955 1956 if (!(i instanceof WidgetCorner) 1957 || !((WidgetCorner) i).getWidgetSource() 1958 .isFixedSize()) { // don't size fixed 1959 // widgets 1960 1961 Collection<Item> allConnected = i.getAllConnected(); 1962 done.addAll(allConnected); 1963 for (Item it : allConnected) { 1964 it.translate(origin, ratio); 1965 it.setArrowheadLength((float) (it 1966 .getArrowheadLength() * ratio)); 1967 } 1968 i.setThickness((float) (i.getThickness() * ratio)); 1969 } 1970 } else if (i instanceof XRayable) { 1971 XRayable xRay = (XRayable) i; 1972 Text source = xRay.getSource(); 1973 // Ensure that the source is done before the XRayable 1974 if (!done.contains(source)) { 1975 scaleText(insideEnclosure, origin, ratio, done, source); 1976 } 1977 1978 i.translate(origin, ratio); 1979 i.setThickness((float) (i.getThickness() * ratio)); 1980 done.add(i); 1981 } else if (i.hasVector()) { 1982 // TODO Improve the effiency of resizing vectors... ie... 1983 // dont want to have to reparse all the time 1984 assert (i instanceof Text); 1985 Text text = (Text) i; 1986 AttributeValuePair avp = new AttributeValuePair( 1987 text.getText()); 1988 double scale = 1F; 1989 try { 1990 scale = avp.getDoubleValue(); 1991 } catch (Exception e) { 1992 } 1993 scale *= ratio; 1994 NumberFormat nf = Vector.getNumberFormatter(); 1995 text.setAttributeValue(nf.format(scale)); 1996 text.translate(origin, ratio); 1997 item.getParent().parse(); 1998 } else if (i instanceof Text) { 1999 scaleText(insideEnclosure, origin, ratio, done, (Text) i); 2000 } 2001 } 2002 // refresh anchored items 2003 if (refreshAnchors(toSize)) { 2004 FrameUtils.Parse(DisplayIO.getCurrentFrame(), false); 2005 } 2006 // notify widgets they were resized 2007 for (InteractiveWidget iw : widgets) { 2008 iw.onResized(); 2009 } 2010 FrameGraphics.refresh(true); 2011 return; 2012 } 2013 2014 // adjust the size of all the items 2015 for (Item i : toSize) { 2016 // Lines and dots use thickness, not size 2017 if (i.hasEnclosures()) { 2018 Circle c = (Circle) i.getEnclosures().iterator().next(); 2019 c.setSize(c.getSize() * (float) ratio); 2020 } else if (i instanceof Line || i instanceof Circle 2021 && !insideEnclosure) { 2022 float current = Math.abs(i.getThickness()); 2023 current = Math.max(current + diff, Item.MINIMUM_THICKNESS); 2024 i.setThickness(current); 2025 } else if (i instanceof Dot) { 2026 Item dot = (Item) i; 2027 float current = Math.abs(dot.getThickness()); 2028 current = Math.max(current + diff, Item.MINIMUM_THICKNESS); 2029 dot.setThickness(current); 2030 } else if (i.hasVector()) { 2031 assert (item instanceof Text); 2032 Text text = (Text) item; 2033 AttributeValuePair avp = new AttributeValuePair(text.getText()); 2034 double scale = 1F; 2035 try { 2036 scale = avp.getDoubleValue(); 2037 } catch (Exception e) { 2038 } 2039 scale *= ratio; 2040 NumberFormat nf = Vector.getNumberFormatter(); 2041 text.setAttributeValue(nf.format(scale)); 2042 text.translate(origin, ratio); 2043 item.getParent().parse(); 2044 } else { 2045 float oldSize = Math.abs(i.getSize()); 2046 float newSize = Math 2047 .max(oldSize + diff, Item.MINIMUM_THICKNESS); 2048 float resizeRatio = newSize / oldSize; 2049 // Set size for Picture also translates 2050 i.setSize(newSize); 2051 if (i instanceof Text && i.getSize() != oldSize) { 2052 if (toSize.size() == 1 && !isControlDown) { 2053 moveCursorAndFreeItems(i.getX(), i.getY()); 2054 } else { 2055 i.translate(origin, resizeRatio); 2056 if (i.isLineEnd()) { 2057 i.setPosition(i.getPosition()); 2058 } 2059 } 2060 } 2061 } 2062 } 2063 2064 if (toSet != null) 2065 toSet.getParent().setChanged(true); 2066 2067 // refresh anchored items 2068 if (refreshAnchors(toSize)) { 2069 FrameUtils.Parse(DisplayIO.getCurrentFrame(), false); 2070 } 2071 2072 // notify widgets they were resized 2073 for (InteractiveWidget iw : widgets) { 2074 iw.onResized(); 2075 } 2076 FrameGraphics.refresh(true); 2077 } 2078 2079 /** 2080 * @param origin 2081 * @param ratio 2082 * @param done 2083 * @param source 2084 */ 2085 private static void scaleText(boolean insideEnclosure, Point2D origin, 2086 double ratio, Collection<Item> done, Text source) { 2087 if (insideEnclosure) 2088 source.setWidth(Math.round((float) (source.getWidth() * ratio))); 2089 source.translate(origin, ratio); 2090 source.setSize((float) (source.getSize() * ratio)); 2091 done.add(source); 2092 } 2093 2094 private static void SetFillColor(Item item, boolean setTransparent) { 2095 if (item == null) 2096 return; 2097 2098 if (!item.hasPermission(UserAppliedPermission.full)) { 2099 MessageBay 2100 .displayMessage("Insufficient permission to change fill color"); 2101 return; 2102 } 2103 2104 Item toSet = item; 2105 Color color = toSet.getFillColor(); 2106 if (setTransparent) 2107 color = null; 2108 else 2109 color = ColorUtils.getNextColor(color, 2110 TemplateSettings.FillColorWheel.get(), 2111 toSet.getGradientColor()); 2112 2113 // if (color == null) { 2114 // MessageBay.displayMessage("FillColor is now transparent"); 2115 // } 2116 2117 toSet.setFillColor(color); 2118 toSet.getParent().setChanged(true); 2119 2120 FrameGraphics.Repaint(); 2121 } 2122 2123 private static void SetGradientColor(Item item, boolean setTransparent) { 2124 if (item == null) 2125 return; 2126 2127 if (!item.hasPermission(UserAppliedPermission.full)) { 2128 MessageBay 2129 .displayMessage("Insufficient permission to change gradient color"); 2130 return; 2131 } 2132 2133 Item toSet = item; 2134 Color color = toSet.getGradientColor(); 2135 if (setTransparent) 2136 color = null; 2137 else 2138 color = ColorUtils.getNextColor(color, 2139 TemplateSettings.ColorWheel.get(), toSet.getFillColor()); 2140 2141 // if (color == null) { 2142 // MessageBay.displayMessage("FillColor is now transparent"); 2143 // } 2144 2145 toSet.setGradientColor(color); 2146 toSet.getParent().setChanged(true); 2147 2148 FrameGraphics.Repaint(); 2149 } 2150 2151 /** 2152 * Sets the colour of the current Item based on its current colour. The 2153 * colours proceed in the order stored in COLOR_WHEEL. 2154 * 2155 * @param toSet 2156 * The Item whose colour is to be changed 2157 */ 2158 private static void SetColor(Item item, boolean setTransparent, 2159 boolean setBackgroundColor) { 2160 // first determine the next color 2161 Color color = null; 2162 Frame currentFrame = DisplayIO.getCurrentFrame(); 2163 if (item == null) { 2164 if (FreeItems.itemsAttachedToCursor()) { 2165 color = FreeItems.getInstance().get(0).getColor(); 2166 } else { 2167 return; 2168 } 2169 // change the background color if the user is pointing on the 2170 // frame name 2171 } else if (item == currentFrame.getNameItem()) { 2172 // check permissions 2173 if (!item.hasPermission(UserAppliedPermission.full)) { 2174 MessageBay 2175 .displayMessage("Insufficient permission to the frame's background color"); 2176 return; 2177 } 2178 if (setTransparent) 2179 currentFrame.setBackgroundColor(null); 2180 else 2181 currentFrame.toggleBackgroundColor(); 2182 // Display a message if the color has changed to transparent 2183 // if (currentFrame.getBackgroundColor() == null) 2184 // FrameGraphics 2185 // .displayMessage("Background color is now transparent"); 2186 FrameGraphics.Repaint(); 2187 return; 2188 } else { 2189 // check permissions 2190 if (!item.hasPermission(UserAppliedPermission.full)) { 2191 Item editTarget = item.getEditTarget(); 2192 if (editTarget != item 2193 && editTarget.hasPermission(UserAppliedPermission.full)) { 2194 item = editTarget; 2195 } else { 2196 MessageBay 2197 .displayMessage("Insufficient permission to change color"); 2198 return; 2199 } 2200 } 2201 // Toggling color of circle center changes the circle fill color 2202 if (item.hasEnclosures()) { 2203 if (setBackgroundColor) { 2204 SetGradientColor(item.getEnclosures().iterator().next(), 2205 setTransparent); 2206 } else { 2207 SetFillColor(item.getEnclosures().iterator().next(), 2208 setTransparent); 2209 } 2210 } else if (setBackgroundColor) { 2211 color = item.getPaintBackgroundColor(); 2212 } else { 2213 color = item.getPaintColor(); 2214 } 2215 } 2216 if (setTransparent) 2217 color = null; 2218 else if (setBackgroundColor) { 2219 color = ColorUtils 2220 .getNextColor(color, TemplateSettings.FillColorWheel.get(), 2221 item.getPaintColor()); 2222 } else { 2223 color = ColorUtils.getNextColor(color, 2224 TemplateSettings.ColorWheel.get(), 2225 currentFrame.getPaintBackgroundColor()); 2226 } 2227 // if (currentFrame.getPaintForegroundColor().equals(color)) 2228 // color = null; 2229 2230 // if color is being set to default display a message to indicate that 2231 // if (color == null) { 2232 // MessageBay.displayMessage("Color is set to default"); 2233 // } 2234 2235 if (setBackgroundColor) { 2236 if (item == null && FreeItems.itemsAttachedToCursor()) { 2237 for (Item i : FreeItems.getInstance()) 2238 i.setBackgroundColor(color); 2239 } else { 2240 item.setBackgroundColor(color); 2241 item.getParent().setChanged(true); 2242 } 2243 } else { 2244 if (item == null && FreeItems.itemsAttachedToCursor()) { 2245 for (Item i : FreeItems.getInstance()) 2246 i.setColor(color); 2247 } else { 2248 item.setColor(color); 2249 item.getParent().setChanged(true); 2250 } 2251 } 2252 FrameGraphics.Repaint(); 2253 } 2254 2255 /** 2256 * Toggles the given Item's annotation status on\off. 2257 * 2258 * @param toToggle 2259 * The Item to toggle 2260 */ 2261 private static void ToggleAnnotation(Item toToggle) { 2262 if (toToggle == null) { 2263 MessageBay.displayMessage("There is no Item selected to toggle"); 2264 return; 2265 } 2266 2267 // check permissions 2268 if (!toToggle.hasPermission(UserAppliedPermission.full)) { 2269 MessageBay 2270 .displayMessage("Insufficient permission to toggle that item's annotation"); 2271 return; 2272 } 2273 toToggle.setAnnotation(!toToggle.isAnnotation()); 2274 2275 toToggle.getParent().setChanged(true); 2276 FrameGraphics.Repaint(); 2277 } 2278 2279 /** 2280 * Toggles the face style of a text item 2281 * 2282 * @param toToggle 2283 * The Item to toggle 2284 */ 2285 private static void ToggleFontStyle(Item toToggle) { 2286 if (toToggle == null) { 2287 MessageBay.displayMessage("There is no Item selected to toggle"); 2288 return; 2289 } 2290 2291 // check permissions 2292 if (!toToggle.hasPermission(UserAppliedPermission.full)) { 2293 MessageBay 2294 .displayMessage("Insufficient permission to toggle that item's annotation"); 2295 return; 2296 } 2297 2298 if (toToggle instanceof Text) { 2299 Text text = (Text) toToggle; 2300 text.toggleFontStyle(); 2301 2302 text.getParent().setChanged(true); 2303 FrameGraphics.Repaint(); 2304 } 2305 } 2306 2307 /** 2308 * Toggles the face style of a text item 2309 * 2310 * @param toToggle 2311 * The Item to toggle 2312 */ 2313 private static void ToggleFontFamily(Item toToggle) { 2314 if (toToggle == null) { 2315 MessageBay.displayMessage("There is no Item selected to toggle"); 2316 return; 2317 } 2318 2319 // check permissions 2320 if (!toToggle.hasPermission(UserAppliedPermission.full)) { 2321 MessageBay 2322 .displayMessage("Insufficient permission to toggle that item's annotation"); 2323 return; 2324 } 2325 2326 if (toToggle instanceof Text) { 2327 Text text = (Text) toToggle; 2328 text.toggleFontFamily(); 2329 2330 text.getParent().setChanged(true); 2331 FrameGraphics.Repaint(); 2332 } 2333 } 2334 2335 /** 2336 * If the given Item is null, then a new Text item is created with the 2337 * current date If the given Item is not null, then the current date is 2338 * prepended to the Item's text 2339 * 2340 * @param toAdd 2341 * The Item to prepend the date to, or null 2342 */ 2343 public static void AddDate(Item toAdd) { 2344 String date1 = Formatter.getDateTime(); 2345 String date2 = Formatter.getDate(); 2346 final String leftSeparator = " :"; 2347 final String rightSeparator = ": "; 2348 String dateToAdd = date1 + rightSeparator; 2349 boolean prepend = false; 2350 boolean append = false; 2351 2352 // if the user is pointing at an item, add the date where ever the 2353 // cursor is pointing 2354 if (toAdd != null && toAdd instanceof Text) { 2355 // permission check 2356 if (!toAdd.hasPermission(UserAppliedPermission.full)) { 2357 MessageBay 2358 .displayMessage("Insufficicent permission to add the date to that item"); 2359 return; 2360 } 2361 2362 Text textItem = (Text) toAdd; 2363 2364 String text = textItem.getText(); 2365 2366 // check if the default date has already been put on this item 2367 if (text.startsWith(date1 + rightSeparator)) { 2368 textItem.removeText(date1 + rightSeparator); 2369 dateToAdd = date2 + rightSeparator; 2370 prepend = true; 2371 } else if (text.startsWith(date2 + rightSeparator)) { 2372 textItem.removeText(date2 + rightSeparator); 2373 dateToAdd = leftSeparator + date2; 2374 append = true; 2375 } else if (text.endsWith(leftSeparator + date2)) { 2376 textItem.removeEndText(leftSeparator + date2); 2377 append = true; 2378 dateToAdd = leftSeparator + date1; 2379 } else if (text.endsWith(leftSeparator + date1)) { 2380 textItem.removeEndText(leftSeparator + date1); 2381 if (textItem.getLength() > 0) { 2382 dateToAdd = ""; 2383 prepend = true; 2384 } else { 2385 // use the default date format 2386 prepend = true; 2387 } 2388 } 2389 2390 if (prepend) { 2391 // add the date to the text item 2392 textItem.prependText(dateToAdd); 2393 if (dateToAdd.length() == textItem.getLength()) 2394 DisplayIO.setCursorPosition(textItem 2395 .getParagraphEndPosition()); 2396 } else if (append) { 2397 textItem.appendText(dateToAdd); 2398 if (dateToAdd.length() == textItem.getLength()) 2399 DisplayIO.setCursorPosition(textItem.getPosition()); 2400 } else { 2401 for (int i = 0; i < date1.length(); i++) { 2402 processChar(date1.charAt(i), false); 2403 } 2404 } 2405 2406 textItem.getParent().setChanged(true); 2407 FrameGraphics.Repaint(); 2408 // } else { 2409 // MessageBay 2410 // .displayMessage("Only text items can have the date prepended to 2411 // them"); 2412 // } 2413 // otherwise, create a new text item 2414 } else { 2415 Text newText = createText(); 2416 newText.setText(dateToAdd); 2417 DisplayIO.getCurrentFrame().addItem(newText); 2418 DisplayIO.getCurrentFrame().setChanged(true); 2419 FrameGraphics.Repaint(); 2420 2421 DisplayIO.setCursorPosition(newText.getParagraphEndPosition()); 2422 } 2423 2424 } 2425 2426 /** 2427 * Creates a new Frameset with the name given by the Item 2428 * 2429 * @param name 2430 */ 2431 private static void CreateFrameset(Item item) { 2432 if (item == null) { 2433 MessageBay 2434 .displayMessage("There is no selected item to use for the frameset name"); 2435 return; 2436 } 2437 2438 if (!(item instanceof Text)) { 2439 MessageBay 2440 .displayMessage("Framesets can only be created from text items"); 2441 return; 2442 } 2443 2444 // dont create frameset if the item is linked 2445 if (item.getLink() != null) { 2446 MessageBay 2447 .displayMessage("A frameset can not be created from a linked item"); 2448 return; 2449 } 2450 2451 // check permissions 2452 if (!item.hasPermission(UserAppliedPermission.full)) { 2453 MessageBay 2454 .displayMessage("Insufficient permission to create a frameset from this item"); 2455 return; 2456 } 2457 2458 Text text = (Text) item; 2459 try { 2460 // create the new frameset 2461 Frame linkTo = FrameIO.CreateNewFrameset(text.getFirstLine()); 2462 DisplayIO.setCursor(Item.DEFAULT_CURSOR); 2463 text.setLink(linkTo.getName()); 2464 text.getParent().setChanged(true); 2465 FrameUtils.DisplayFrame(linkTo, true, true); 2466 linkTo.moveMouseToDefaultLocation(); 2467 // this needs to be done if the user doesnt move the mouse before 2468 // doing Tdfc while the cursor is set to the text cursor 2469 DisplayIO.setCursor(Item.DEFAULT_CURSOR); 2470 } catch (Exception e) { 2471 MessageBay.errorMessage(e.getMessage()); 2472 } 2473 } 2474 2475 /** 2476 * Forces a re-parse and repaint of the current Frame. 2477 */ 2478 public static void Refresh() { 2479 Frame currentFrame = DisplayIO.getCurrentFrame(); 2480 2481 if (FrameMouseActions.isShiftDown()) { 2482 currentFrame.refreshSize(); 2483 } 2484 2485 // Refresh widgets that use its self as a data source 2486 currentFrame.notifyObservers(true); 2487 2488 if (FrameIO.isProfileFrame(currentFrame)) { 2489 // TODO ensure that users can not delete the first frame in a 2490 // frameset... 2491 // TODO handle the case when users manually delete the first frame 2492 // in a frameset from the filesystem 2493 Frame profile = FrameIO.LoadFrame(currentFrame.getFramesetName() 2494 + "1"); 2495 assert (profile != null); 2496 FrameUtils.Parse(currentFrame); 2497 FrameUtils.ParseProfile(profile); 2498 } else { 2499 FrameUtils.Parse(currentFrame); 2500 } 2501 // Need to update the cursor for when text items change to @b pictures 2502 // etc and the text cursor is showing 2503 FrameMouseActions.updateCursor(); 2504 FrameMouseActions.getInstance().refreshHighlights(); 2505 FrameGraphics.ForceRepaint(); 2506 } 2507 } 964 }*/ -
trunk/src/org/expeditee/gui/FrameMouseActions.java
r1064 r1102 19 19 package org.expeditee.gui; 20 20 21 import java.awt.Color;22 import java.awt.Image;23 import java.awt.Point;24 import java.awt.Rectangle;25 import java.awt.Toolkit;26 import java.awt.datatransfer.Clipboard;27 import java.awt.datatransfer.DataFlavor;28 import java.awt.datatransfer.Transferable;29 import java.awt.event.ActionEvent;30 import java.awt.event.ActionListener;31 import java.awt.event.KeyEvent;32 21 import java.awt.event.MouseEvent; 33 import java.awt.event.MouseListener;34 import java.awt.event.MouseMotionListener;35 import java.awt.event.MouseWheelEvent;36 import java.awt.event.MouseWheelListener;37 22 import java.text.NumberFormat; 38 23 import java.util.ArrayList; … … 45 30 import java.util.List; 46 31 import java.util.Set; 47 import java.util.TimerTask;48 49 import javax.swing.Timer;50 32 51 33 import org.expeditee.actions.Actions; 52 34 import org.expeditee.actions.Misc; 53 35 import org.expeditee.actions.Navigation; 36 import org.expeditee.core.AxisAlignedBoxBounds; 37 import org.expeditee.core.Colour; 38 import org.expeditee.core.OSManager; 39 import org.expeditee.core.Point; 40 import org.expeditee.core.swing.SwingConversions; 41 import org.expeditee.gio.gesture.Gesture; 42 import org.expeditee.gio.gesture.GestureListener; 54 43 import org.expeditee.gui.indirect.mouse.IndirectMouseActions; 55 44 import org.expeditee.gui.indirect.mouse.MouseAction; … … 71 60 import org.expeditee.items.UserAppliedPermission; 72 61 import org.expeditee.items.XRayable; 73 import org.expeditee.items.widgets.ButtonWidget; 62 /*import org.expeditee.items.widgets.ButtonWidget; TODO: Reinstate. cts16 74 63 import org.expeditee.items.widgets.InteractiveWidget; 75 64 import org.expeditee.items.widgets.WidgetCorner; 76 import org.expeditee.items.widgets.WidgetEdge; 65 import org.expeditee.items.widgets.WidgetEdge;*/ 77 66 import org.expeditee.settings.UserSettings; 78 67 import org.expeditee.settings.experimental.ExperimentalFeatures; 79 68 import org.expeditee.stats.SessionStats; 80 69 81 public class FrameMouseActions implements MouseListener, MouseMotionListener,82 MouseWheelListener{70 public class FrameMouseActions 71 { 83 72 84 73 private static int _lastMouseClickModifiers = 0; … … 92 81 @Override 93 82 public List<Item> exec(MouseInfo info) { 94 //if user is not pointing at something, this is a back83 //if user is not pointing at something, this is a back 95 84 if (info.isControlDown || info.isShiftDown) 96 85 forward(); … … 105 94 // check for TDFC permission 106 95 if (!info.clicked.hasPermission(UserAppliedPermission.createFrames)) { 107 MessageBay 108 .displayMessage("Insufficient permission to TDFC (Top Down Frame Creation) from that item"); 96 MessageBay.displayMessage("Insufficient permission to TDFC (Top Down Frame Creation) from that item"); 109 97 return null; 110 98 } … … 178 166 copies.add(new Line(d[3], d[0], current.getNextItemID())); 179 167 180 new Constraint(d[0], d[1], current.getNextItemID(), 181 Constraint.HORIZONTAL); 182 new Constraint(d[2], d[3], current.getNextItemID(), 183 Constraint.HORIZONTAL); 184 new Constraint(d[1], d[2], current.getNextItemID(), 185 Constraint.VERTICAL); 186 new Constraint(d[3], d[0], current.getNextItemID(), 187 Constraint.VERTICAL); 168 new Constraint(d[0], d[1], current.getNextItemID(), Constraint.HORIZONTAL); 169 new Constraint(d[2], d[3], current.getNextItemID(), Constraint.HORIZONTAL); 170 new Constraint(d[1], d[2], current.getNextItemID(), Constraint.VERTICAL); 171 new Constraint(d[3], d[0], current.getNextItemID(), Constraint.VERTICAL); 188 172 189 173 anchor(new ArrayList<Item>(copies)); … … 233 217 Collection<Item> enclosed = getFullyEnclosedItems(info.clickedIn); 234 218 if (enclosed.size() == 0) { 235 MessageBay 236 .displayMessage("Insufficient permission to copy items"); 219 MessageBay.displayMessage("Insufficient permission to copy items"); 237 220 } else { 238 221 copies = copy(enclosed); … … 308 291 List<Item> copies = new ArrayList<Item>(); 309 292 if (info.clicked != null) { 310 Collection<Item> leftOver = merge(FreeItems 311 .getInstance(), info.clicked); 293 Collection<Item> leftOver = merge(FreeItems.getInstance(), info.clicked); 312 294 anchor(leftOver); 313 295 } 314 296 // This is executed when the user is putting down a line 315 297 // endpoint and unreeling. ie. Normal unreeling 316 copies = ItemUtils.UnreelLine(FreeItems.getInstance(), 317 _controlDown); 318 319 if (copies == null) 320 copies = copy(FreeItems.getInstance()); 298 copies = ItemUtils.UnreelLine(FreeItems.getInstance(), _controlDown); 299 300 if (copies == null) copies = copy(FreeItems.getInstance()); 301 321 302 anchor(FreeItems.getInstance()); 322 for (Item i : copies) 323 i.setOffset(0, 0); 303 for (Item i : copies) i.setOffset(0, 0); 324 304 // need to move to prevent cursor dislocation 325 305 move(copies); … … 354 334 if (next instanceof Line) 355 335 continue; 356 double distance = Point.distance(currentX, 357 currentY, next.getX(), next.getY()); 336 double distance = Point.distance((int) currentX, (int) currentY, next.getX(), next.getY()); 358 337 if (distance < shortestDistance) { 359 338 shortestDistance = distance; … … 469 448 public List<Item> exec(MouseInfo info) { 470 449 List<Item> copies = new ArrayList<Item>(); 471 Item on = FrameUtils.onItem(DisplayIO.getCurrentFrame(), Math 472 .round(MouseX), Math.round(MouseY), true); 450 Item on = FrameUtils.onItem(DisplayIO.getCurrentFrame(), Math.round(MouseX), Math.round(MouseY), true); 473 451 // If we have permission to copy this item then pick it up 474 452 if (on != null && on.isLineEnd() … … 479 457 } 480 458 481 if (on instanceof WidgetEdge) { 459 /* if (on instanceof WidgetEdge) { TODO: Reinstate. cts16 482 460 // Don't allow the user to break widget edges. 483 461 // Note: had to return here because random dots would … … 485 463 // with create line. 486 464 return copies; 487 } 465 }*/ 488 466 489 467 // if its on a line then split the line and put a point on it and … … 519 497 List<Item> copies = new ArrayList<Item>(); 520 498 ArrayList<Item> toPickup = new ArrayList<Item>(info.clickedIn.size()); 521 for (Item ip : info.clickedIn) 522 if (ip.hasPermission(UserAppliedPermission.full)) 523 toPickup.add(ip);499 for (Item ip : info.clickedIn) { 500 if (ip.hasPermission(UserAppliedPermission.full)) toPickup.add(ip); 501 } 524 502 pickup(toPickup); 525 503 // otherwise the user is creating a line … … 532 510 List<Item> items = new ArrayList<Item>(); 533 511 // BROOK: WIDGET RECTANGLES DONT ALLOW DISCONNECTION 534 if (info.clicked instanceof Line && !(info.clicked instanceof WidgetEdge)) {512 if (info.clicked instanceof Line/* && !(info.clicked instanceof WidgetEdge) TODO: Reinstate. cts16*/) { 535 513 // Check if within 20% of the end of the line 536 514 Line l = (Line) info.clicked; 537 Item toDisconnect = l.getEndPointToDisconnect(_lastMouseClick 538 .getX(), _lastMouseClick.getY()); 515 Item toDisconnect = l.getEndPointToDisconnect(_lastMouseClick.getX(), _lastMouseClick.getY()); 539 516 540 517 if (toDisconnect == null) { … … 696 673 697 674 public static FrameMouseActions getInstance() { 698 if (_instance == null) 699 _instance = new FrameMouseActions();675 if (_instance == null) _instance = new FrameMouseActions(); 676 700 677 return _instance; 701 678 } … … 708 685 private static final int MINIMUM_RANGE_DEPRESS_TIME = 250; 709 686 710 private static final int RECTANGLE_TO_POINT_THRESHOLD = 20;711 712 687 private static Date _lastMouseClickDate = new Date(); 713 688 … … 717 692 718 693 public static final int BIG_MOUSE_PAUSE = 750; 719 720 public static final int CONTEXT_FREESPACE = 0;721 722 public static final int CONTEXT_AT_TEXT = 1;723 724 public static final int CONTEXT_AT_LINE = 2;725 726 public static final int CONTEXT_AT_DOT = 3;727 728 public static final int CONTEXT_AT_ENCLOSURE = 4;729 694 730 695 public static int _alpha = -1; … … 765 730 private static boolean _extrude = false; 766 731 767 // keeps track of the last highlighted Item768 private static Item _lastHighlightedItem = null;769 770 732 // keeps track of the item being 'ranged out' if there is one. 771 733 private static Text _lastRanged = null; … … 773 735 // keeps track of the picture being cropped if there is one 774 736 private static Picture _lastCropped = null; 775 776 // true if lastItem only has highlighting removed when a new item is777 // highlighted778 private static boolean _lastHoldsHighlight = false;779 780 private static boolean _forceArrowCursor = true;781 782 // the current context of the cursor783 private static int _context = 0;784 785 public static void setForceArrow(boolean val) {786 _forceArrowCursor = val;787 }788 737 789 738 public static int getContext() { … … 807 756 public void actionPerformed(ActionEvent ae) { 808 757 // check if we are in free space 809 if (_lastClickedOn == null 810 && FreeItems.getInstance().size() == 0) { 758 if (_lastClickedOn == null && FreeItems.getInstance().size() == 0) { 811 759 // System.out.println("SuperBack!"); 812 760 _MouseTimer.setDelay(ZERO_MOUSE_PAUSE); … … 829 777 }); 830 778 831 private static void setPulse(boolean pulseOn) {832 if (_pulseOn == pulseOn){833 834 } 779 private static void setPulse(boolean pulseOn) 780 { 781 if (_pulseOn == pulseOn) return; 782 835 783 int amount = PULSE_AMOUNT; 836 if (!pulseOn) { 837 amount *= -1; 838 } 784 if (!pulseOn) amount *= -1; 839 785 _pulseOn = pulseOn; 840 786 … … 859 805 } 860 806 }); 861 862 public void mouseClicked(MouseEvent e) {863 }864 807 865 808 /** … … 874 817 875 818 private void ProccessMousePressedEvent(MouseEvent e, int modifiersEx) { 876 // System.out.println("MousePressed " + e.getX() + "," + e.getY() + " " 877 // + e.getWhen()); 819 // System.out.println("MousePressed " + e.getX() + "," + e.getY() + " " + e.getWhen()); 878 820 879 821 // TODO WHY DID I NOT COMMENT THIS LINE!! MIKE SAYS 880 if (LastRobotX != null) {822 /* if (LastRobotX != null) { 881 823 _RobotTimer.stop(); 882 824 LastRobotX = null; … … 894 836 MouseX = panStartX; 895 837 MouseY = panStartY; 896 } 838 }*/ 897 839 898 840 // System.out.println(modifiersEx); 899 if (_mouseDown == 0) 900 _lastMouseClickDate = new Date(); 841 if (_mouseDown == 0) _lastMouseClickDate = new Date(); 901 842 902 843 int buttonPressed = e.getButton(); … … 916 857 * backup stack. 917 858 */ 918 if (on == null || buttonPressed != MouseEvent.BUTTON1 919 || !on.isFrameName()) { 859 if (on == null || buttonPressed != MouseEvent.BUTTON1 || !on.isFrameName()) { 920 860 Navigation.ResetLastAddToBack(); 921 861 } 922 862 923 SessionStats.MouseClicked(e.getButton());863 //SessionStats.MouseClicked(e.getButton()); 924 864 if (buttonPressed == MouseEvent.BUTTON1) { 925 SessionStats.AddFrameEvent("Ld");865 //SessionStats.AddFrameEvent("Ld"); 926 866 _extrude = false; 927 867 } else if (buttonPressed == MouseEvent.BUTTON2) { 928 SessionStats.AddFrameEvent("Md");868 //SessionStats.AddFrameEvent("Md"); 929 869 _extrude = false; 930 870 } else if (buttonPressed == MouseEvent.BUTTON3) { 931 SessionStats.AddFrameEvent("Rd");871 //SessionStats.AddFrameEvent("Rd"); 932 872 933 873 // Check if the user picked up a paint brush 934 if (FreeItems.getInstance().size() == 1 935 && FreeItems.getItemAttachedToCursor().isAutoStamp()) { 936 int delay = (int) (FreeItems.getItemAttachedToCursor() 937 .getAutoStamp() * 1000); 874 if (FreeItems.getInstance().size() == 1 && FreeItems.getItemAttachedToCursor().isAutoStamp()) { 875 int delay = (int) (FreeItems.getItemAttachedToCursor().getAutoStamp() * 1000); 938 876 if (delay < 10) { 939 877 _autoStamp = true; … … 958 896 */ 959 897 if (_lastClickedOn == null && FreeItems.getInstance().size() == 0) { 960 // System.out.println(e.getClickCount());961 898 if (e.getClickCount() >= 2) { 962 899 _MouseTimer.start(); 963 900 } 964 } else if (_lastClickedOn != null 965 && FreeItems.getInstance().size() == 0 966 && e.getButton() == MouseEvent.BUTTON3) { 901 } else if ( _lastClickedOn != null && 902 FreeItems.getInstance().size() == 0 && 903 e.getButton() == MouseEvent.BUTTON3) 904 { 967 905 _ExtrudeMouseTimer.start(); 968 969 906 } else { 970 907 _MouseTimer.start(); … … 994 931 _isDelete = false; 995 932 _isNoOp = true; 996 } else 933 } else { 997 934 _isDelete = false; 935 } 998 936 999 937 // This must happen before the previous code 1000 938 // This is when the user is anchoring something 1001 if ( buttonPressed != MouseEvent.BUTTON11002 && (_context == CONTEXT_FREESPACE || _context == CONTEXT_AT_ENCLOSURE)1003 && FreeItems.itemsAttachedToCursor()) {1004 FrameGraphics.changeHighlightMode(_lastHighlightedItem,1005 939 if ( buttonPressed != MouseEvent.BUTTON1 && 940 (_context == CONTEXT_FREESPACE || _context == CONTEXT_AT_ENCLOSURE) && 941 FreeItems.hasItemsAttachedToCursor()) 942 { 943 FrameGraphics.changeHighlightMode(_lastHighlightedItem, Item.HighlightMode.None); 1006 944 1007 945 _lastHighlightedItem = FreeItems.getItemAttachedToCursor(); … … 1010 948 } 1011 949 FrameGraphics.Repaint(); 1012 950 // this is when the user is picking something up 1013 951 } else if (_lastHighlightedItem != null) { 1014 952 if (!(_lastHighlightedItem instanceof Line)) { 1015 _lastHighlightedItem 1016 .setHighlightColor(Item.DEPRESSED_HIGHLIGHT); 953 _lastHighlightedItem.setHighlightColor(Item.DEPRESSED_HIGHLIGHT); 1017 954 } else { 1018 955 for (Item i : _lastHighlightedItem.getAllConnected()) { … … 1027 964 _lastRanged = (Text) on; 1028 965 // set start-drag point 1029 _lastRanged.setSelectionStart(DisplayIO.getMouseX(), 1030 FrameMouseActions.getY()); 966 _lastRanged.setSelectionStart(DisplayIO.getMouseX(), DisplayIO.getMouseY()); 1031 967 } 1032 968 … … 1040 976 } 1041 977 1042 if (on != null && on instanceof Picture 1043 && e.getButton() == MouseEvent.BUTTON3 && !_isDelete) { 978 if (on != null && on instanceof Picture && e.getButton() == MouseEvent.BUTTON3 && !_isDelete) { 1044 979 _lastCropped = (Picture) on; 1045 980 // set start crop point 1046 _lastCropped.setStartCrop(DisplayIO.getMouseX(), FrameMouseActions 1047 .getY()); 981 _lastCropped.setStartCrop(DisplayIO.getMouseX(), DisplayIO.getMouseY()); 1048 982 _lastCropped.setShowCrop(true); 1049 983 } … … 1055 989 // System.out.println("Released " + e.getX() + "," + e.getY() + " " + 1056 990 // e.getWhen()); 1057 FrameUtils.ResponseTimer.restart();991 // FrameUtils.ResponseTimer.restart(); 1058 992 _autoStampTimer.stop(); 1059 993 _autoStamp = false; … … 1063 997 // the user probably wants to click away the popup - therefore ignore 1064 998 // the event 1065 boolean shouldConsume = PopupManager.getInstance() 1066 .shouldConsumeBackClick(); 999 /* boolean shouldConsume = PopupManager.getInstance().shouldConsumeBackClick(); TODO: Reinstate. cts16 1067 1000 PopupManager.getInstance().hideAutohidePopups(); 1068 1001 if (shouldConsume && e.getButton() == MouseEvent.BUTTON1) { 1069 1002 return; // consume back click event 1070 } 1003 }*/ 1071 1004 1072 1005 // _lastMovedDistance = new Point(e.getX() - _lastMouseClick.getX(), e … … 1084 1017 // They are probably trying to pick something up in this case 1085 1018 if (lastRanged != null) { 1086 long depressTime = (new Date()).getTime() 1087 - _lastMouseClickDate.getTime(); 1019 long depressTime = (new Date()).getTime() - _lastMouseClickDate.getTime(); 1088 1020 // double changeInDistance = 1089 1021 // e.getPoint().distance(_currentMouseClick.getPoint()); … … 1092 1024 // System.out.println(depressTime); 1093 1025 1094 if (depressTime < MINIMUM_RANGE_DEPRESS_TIME 1095 || lastRanged.getSelectionSize() <= 0) {// Text.MINIMUM_RANGED_CHARS) 1026 if (depressTime < MINIMUM_RANGE_DEPRESS_TIME || lastRanged.getSelectionSize() <= 0) {// Text.MINIMUM_RANGED_CHARS) 1096 1027 // { 1097 1028 lastRanged.clearSelection(); … … 1145 1076 1146 1077 if (_lastHighlightedItem != null) 1147 FrameGraphics.changeHighlightMode(_lastHighlightedItem, 1148 Item.HighlightMode.None); 1149 1150 if (FreeItems.itemsAttachedToCursor()) { 1078 FrameGraphics.changeHighlightMode(_lastHighlightedItem, Item.HighlightMode.None); 1079 1080 if (FreeItems.hasItemsAttachedToCursor()) { 1151 1081 move(FreeItems.getInstance()); 1152 1082 } … … 1174 1104 lastRanged.replaceSelectedText(((Text) i).getText()); 1175 1105 FreeItems.getInstance().clear(); 1176 } else 1106 } else { 1177 1107 lastRanged.cutSelectedText(); 1108 } 1178 1109 lastRanged.clearSelection(); 1179 1110 FrameGraphics.Repaint(); … … 1231 1162 // Check if the user is trying to range an item for which they 1232 1163 // do not have permission to do so... or it is the frame name 1233 if (!lastRanged.hasPermission(UserAppliedPermission.full) 1234 || lastRanged.isFrameName()) { 1235 MessageBay 1236 .displayMessage("Insufficient permission to cut text"); 1164 if (!lastRanged.hasPermission(UserAppliedPermission.full) || lastRanged.isFrameName()) { 1165 MessageBay.displayMessage("Insufficient permission to cut text"); 1237 1166 lastRanged.clearSelection(); 1238 1167 FrameGraphics.Repaint(); … … 1241 1170 // if the entire text is selected and its not a line end then 1242 1171 // pickup the item 1243 boolean entireText = lastRanged.getSelectionSize() == lastRanged 1244 .getLength(); 1172 boolean entireText = lastRanged.getSelectionSize() == lastRanged.getLength(); 1245 1173 if (entireText && !lastRanged.isLineEnd()) { 1246 1174 lastRanged.clearSelection(); … … 1262 1190 // do not have permission to do so... or it is the frame name 1263 1191 if (!lastRanged.hasPermission(UserAppliedPermission.copy)) { 1264 MessageBay 1265 .displayMessage("Insufficient permission to copy text"); 1192 MessageBay.displayMessage("Insufficient permission to copy text"); 1266 1193 lastRanged.clearSelection(); 1267 1194 FrameGraphics.Repaint(); … … 1272 1199 1273 1200 ranged.setParent(null); 1274 ranged.setPosition(DisplayIO.getMouseX(), FrameMouseActions.getY());1201 ranged.setPosition(DisplayIO.getMouseX(), DisplayIO.getMouseY()); 1275 1202 pickup(ranged); 1276 1203 lastRanged.clearSelection(); … … 1303 1230 // MIKE put the code below up here 1304 1231 _lastCropped.clearCropping(); 1305 FrameGraphics.changeHighlightMode(_lastCropped, 1306 HighlightMode.None); 1232 FrameGraphics.changeHighlightMode(_lastCropped, HighlightMode.None); 1307 1233 _lastCropped = null; 1308 1234 FrameGraphics.Repaint(); … … 1341 1267 1342 1268 // error, we should have returned by now 1343 System.out.println("Error: mouseReleased should have returned by now. " 1344 + e); 1269 System.out.println("Error: mouseReleased should have returned by now. " + e); 1345 1270 } 1346 1271 … … 1348 1273 * This method handles all left-click actions 1349 1274 */ 1350 private void leftButton(Item clicked, Collection<Item> clickedIn, 1351 boolean isShiftDown, boolean isControlDown){1275 private void leftButton(Item clicked, Collection<Item> clickedIn, boolean isShiftDown, boolean isControlDown) 1276 { 1352 1277 1353 1278 //Gets the current frame … … 1355 1280 1356 1281 //Checks if the current frame is an overlay 1357 if (f.getOverlays() != null && FrameUtils.getCurrentItem() != null){1282 if (f.getOverlays() != null && FrameUtils.getCurrentItem() != null) { 1358 1283 Item i = FrameUtils.getCurrentItem(); 1359 1284 1360 1285 //Checks if the item clicked in the overlay is a Rubbish Bin. If it is, delete the item attached to the cursor and return. 1361 if(i instanceof WidgetCorner){ 1286 /* if(i instanceof WidgetCorner){ TODO: Reinstate. cts16 1362 1287 1363 1288 try{ … … 1375 1300 e.printStackTrace(); 1376 1301 } 1377 } 1302 }*/ 1378 1303 1379 1304 Item on = _lastClickedOn; … … 1387 1312 // Check if the user is nearby another item... 1388 1313 int mouseX = DisplayIO.getMouseX(); 1389 int mouseY = FrameMouseActions.getY();1314 int mouseY = DisplayIO.getMouseY(); 1390 1315 // System.out.println(mouseX + "," + mouseY); 1391 1316 for (Item i : DisplayIO.getCurrentFrame().getItems()) { … … 1411 1336 1412 1337 // If the user clicked into a widgets free space... 1413 if (clicked == null && _lastClickedIn != null 1414 && _lastClickedIn.size() >= 4) { 1338 if (clicked == null && _lastClickedIn != null && _lastClickedIn.size() >= 4) { 1415 1339 1416 1340 // Check to see if the user clicked into a widgets empty space 1417 InteractiveWidget iw = null; 1341 /* InteractiveWidget iw = null; TODO: Reinstate. cts16 1418 1342 1419 1343 for (Item i : _lastClickedIn) { … … 1441 1365 assert (widgetLink != null); 1442 1366 clicked = widgetLink; 1443 } else {1367 } else*/ { 1444 1368 for (Item i : _lastClickedIn) { 1445 1369 /* … … 1464 1388 Picture clickedOnPicture = (Picture)clicked; 1465 1389 Frame current_frame = DisplayIO.getCurrentFrame(); 1466 Colo r bg_col = current_frame.getBackgroundColor();1390 Colour bg_col = current_frame.getBackgroundColor(); 1467 1391 if (clickedOnPicture.MouseOverBackgroundPixel(mouseX,mouseY,bg_col)) { 1468 1392 // Make 'clicked' null, effectively causing a back() operation … … 1475 1399 boolean hasLinkOrAction = clicked.hasLink() || clicked.hasAction(); 1476 1400 1477 if ((hasLinkOrAction && !clicked 1478 .hasPermission(UserAppliedPermission.followLinks)) 1479 || (!hasLinkOrAction && !clicked 1480 .hasPermission(UserAppliedPermission.createFrames))) { 1401 if ((hasLinkOrAction && !clicked.hasPermission(UserAppliedPermission.followLinks)) 1402 || (!hasLinkOrAction && !clicked.hasPermission(UserAppliedPermission.createFrames))) 1403 { 1481 1404 Item editTarget = clicked.getEditTarget(); 1482 1405 if (editTarget != clicked) { … … 1484 1407 clicked = editTarget; 1485 1408 } else { 1486 MessageBay 1487 .displayMessage("Insufficient permission to perform action on item"); 1409 MessageBay.displayMessage("Insufficient permission to perform action on item"); 1488 1410 return; 1489 1411 } … … 1494 1416 1495 1417 // actions take priority 1496 if (_lastMouseClick != null && !_lastMouseClick.isControlDown() 1497 && clickedOn.hasAction()) { 1418 if (_lastMouseClick != null && !_lastMouseClick.isControlDown() && clickedOn.hasAction()) { 1498 1419 IndirectMouseActions.getInstance().getExecuteActionAction().exec(new MouseInfo(clicked, clickedIn, isShiftDown, isControlDown)); 1499 1420 } else if (clickedOn.getLink() != null) { 1500 1421 IndirectMouseActions.getInstance().getFollowLinkAction().exec(new MouseInfo(clicked, clickedIn, isShiftDown, isControlDown)); 1501 1422 // no link is found, perform TDFC 1502 1423 } else { 1503 1424 /* … … 1519 1440 } 1520 1441 1521 private static boolean doMerging(Item clicked) {1522 if (clicked == null)1523 return false;1524 1525 // // Brook: widgets do not merge1526 // if (clicked instanceof WidgetCorner)1527 // return false;1528 //1529 // // Brook: widgets do not merge1530 // if (clicked instanceof WidgetEdge)1531 // return false;1532 1533 // System.out.println(FreeItems.getInstance().size());1534 if (isRubberBandingCorner()) {1535 if (clicked.isLineEnd()1536 || clicked.getAllConnected().contains(1537 FreeItems.getItemAttachedToCursor())) {1538 return true;1539 }1540 }1541 1542 if (FreeItems.getInstance().size() > 2)1543 return false;1544 1545 Item attachedToCursor = FreeItems.getItemAttachedToCursor();1546 1547 if (clicked instanceof Text1548 && !(attachedToCursor instanceof Text || attachedToCursor1549 .isLineEnd())) {1550 return false;1551 }1552 1553 if (clicked instanceof Picture) {1554 int mouseX = DisplayIO.getMouseX();1555 int mouseY = FrameMouseActions.getY();1556 Picture clickedOnPicture = (Picture)clicked;1557 Frame current_frame = DisplayIO.getCurrentFrame();1558 Color bg_col = current_frame.getBackgroundColor();1559 if (clickedOnPicture.MouseOverBackgroundPixel(mouseX,mouseY,bg_col)) {1560 // Make 'clicked' null, effectively causing a back() operation1561 return false;1562 }1563 }1564 1565 return true;1566 }1567 1568 1442 public static void middleButton() { 1569 1443 Item currentItem = FrameUtils.getCurrentItem(); … … 1582 1456 public static void leftButton() { 1583 1457 Item currentItem = FrameUtils.getCurrentItem(); 1584 getInstance().leftButton(currentItem, 1585 FrameUtils.getCurrentItems(currentItem), false, false); 1458 getInstance().leftButton(currentItem, FrameUtils.getCurrentItems(currentItem), false, false); 1586 1459 updateCursor(); 1587 1460 } … … 1590 1463 * This method handles all middle-click actions 1591 1464 */ 1592 private void middleButton(Item clicked, Collection<Item> clickedIn, 1593 boolean isShiftDown){1465 private void middleButton(Item clicked, Collection<Item> clickedIn, boolean isShiftDown) 1466 { 1594 1467 1595 1468 // If the user clicked into a widgets free space... … … 1598 1471 1599 1472 // Check to see if the use clicked into a widgets empty space 1600 InteractiveWidget iw = null; 1473 /* InteractiveWidget iw = null; TODO: Reinstate. cts16 1601 1474 1602 1475 for (Item i : _lastClickedIn) { … … 1617 1490 return; 1618 1491 } 1619 } 1492 }*/ 1620 1493 } 1621 1494 // if the cursor has Items attached 1622 if (FreeItems.itemsAttachedToCursor()) { 1623 // if the user is pointing at something, merge the items (if 1624 // possible) 1495 if (FreeItems.hasItemsAttachedToCursor()) { 1496 // if the user is pointing at something, merge the items (if possible) 1625 1497 if (doMerging(clicked)) { 1626 1498 IndirectMouseActions.getInstance().getDeleteItemsAction().exec(new MouseInfo(clicked, clickedIn, false, false)); … … 1635 1507 Picture clickedOnPicture = (Picture)clicked; 1636 1508 Frame current_frame = DisplayIO.getCurrentFrame(); 1637 Colo r bg_col = current_frame.getBackgroundColor();1509 Colour bg_col = current_frame.getBackgroundColor(); 1638 1510 if (clickedOnPicture.MouseOverBackgroundPixel(mouseX,mouseY,bg_col)) { 1639 1511 clicked = null; // Effectively make it as if they haven't clicked on anything … … 1645 1517 if (!clicked.hasPermission(UserAppliedPermission.full)) { 1646 1518 Item editTarget = clicked.getEditTarget(); 1647 if (editTarget != clicked 1648 && editTarget.hasPermission(UserAppliedPermission.full)) { 1519 if (editTarget != clicked && editTarget.hasPermission(UserAppliedPermission.full)) { 1649 1520 clicked = editTarget; 1650 1521 } else { 1651 MessageBay 1652 .displayMessage("Insufficient permission to pick up item"); 1522 MessageBay.displayMessage("Insufficient permission to pick up item"); 1653 1523 return; 1654 1524 } … … 1663 1533 } 1664 1534 SessionStats.MovedItems(FreeItems.getInstance()); 1665 }1666 1667 private static Item getFirstFreeLineEnd() {1668 for (Item i : FreeItems.getInstance())1669 if (i.isLineEnd())1670 return i;1671 return null;1672 }1673 1674 private static boolean isRubberBandingCorner() {1675 return getShapeCorner(FreeItems.getInstance()) != null;1676 }1677 1678 /**1679 * Gets the rectangle corner from the list of items that are part of a1680 * rectangle.1681 *1682 * @param partialRectangle1683 * a corner and its two connecting lines.1684 * @return the rectangle corner or null if the list of items is not part of1685 * a rectangle.1686 */1687 private static Item getShapeCorner(List<Item> partialRectangle) {1688 if (partialRectangle.size() < 3)1689 return null;1690 Item lineEnd = null;1691 // only one lineEnd will be present for rectangles1692 // All other items must be lines1693 for (Item i : partialRectangle) {1694 if (i.isLineEnd()) {1695 if (lineEnd == null) {1696 lineEnd = i;1697 } else {1698 return null;1699 }1700 } else if (!(i instanceof Line)) {1701 return null;1702 }1703 }1704 // if this is at least the corner of two connected lines1705 if (lineEnd != null && lineEnd.getAllConnected().size() >= 5)1706 return lineEnd;1707 1708 return null;1709 1535 } 1710 1536 … … 1719 1545 1720 1546 // Check to see if the use clicked into a widgets empty space 1721 InteractiveWidget iw = null; 1547 /* InteractiveWidget iw = null; TODO: Reinstate. cts16 1722 1548 1723 1549 for (Item i : _lastClickedIn) { … … 1738 1564 return; 1739 1565 } 1740 } 1566 }*/ 1741 1567 } 1742 1568 … … 1744 1570 1745 1571 List<Item> copies = null; 1746 if (FreeItems.itemsAttachedToCursor()) { 1747 if (FreeItems.getInstance().size() == 1 1748 && FreeItems.getItemAttachedToCursor().isAutoStamp()) { 1572 if (FreeItems.hasItemsAttachedToCursor()) { 1573 if (FreeItems.getInstance().size() == 1 && FreeItems.getItemAttachedToCursor().isAutoStamp()) { 1749 1574 // Dont stamp if the user is painting... because we dont want to 1750 1575 // save any of the items created! 1751 1576 return; 1752 // if the user is clicking on something, merge the items 1753 // unless it is a point onto something other than a lineEnd or a 1754 // dot 1577 // if the user is clicking on something, merge the items unless 1578 // it is a point onto something other than a lineEnd or a dot 1755 1579 } else if (clicked != null 1756 1580 // TODO Change the items merge methods so the logic is simplified … … 1758 1582 || clicked instanceof Dot || clicked.isLineEnd())) { 1759 1583 // check permissions 1760 if (!clicked.hasPermission(UserAppliedPermission.full) 1761 && clicked.getParent().getNameItem() != clicked) { 1762 MessageBay 1763 .displayMessage("Insufficient permission to merge items"); 1584 if (!clicked.hasPermission(UserAppliedPermission.full) && clicked.getParent().getNameItem() != clicked) { 1585 MessageBay.displayMessage("Insufficient permission to merge items"); 1764 1586 return; 1765 1587 } 1766 if (clicked instanceof Text || clicked instanceof Dot 1767 || clicked instanceof XRayable) { 1588 if (clicked instanceof Text || clicked instanceof Dot || clicked instanceof XRayable) { 1768 1589 if (isRubberBandingCorner()) { 1769 1590 copies = IndirectMouseActions.getInstance().getMergeGroupAction().exec(new MouseInfo(clicked, clickedIn, false, false)); 1770 1591 // line onto something 1771 } else if (FreeItems.getInstance().size() == 2 1772 /* && clicked instanceof XRayable */) { 1592 } else if (FreeItems.getInstance().size() == 2 /* && clicked instanceof XRayable */) { 1773 1593 copies = IndirectMouseActions.getInstance().getMergeTwoItemsAction().exec(new MouseInfo(clicked, clickedIn, false, false)); 1774 1594 } else if (FreeItems.getInstance().size() == 1) { … … 1778 1598 } 1779 1599 } else { 1780 copies = ItemUtils.UnreelLine(FreeItems.getInstance(), 1781 _controlDown); 1782 if (copies == null) 1783 copies = copy(FreeItems.getInstance()); 1600 copies = ItemUtils.UnreelLine(FreeItems.getInstance(), _controlDown); 1601 if (copies == null) copies = copy(FreeItems.getInstance()); 1784 1602 for (Item i : copies) { 1785 1603 i.setOffset(0, 0); … … 1789 1607 pickup(copies); 1790 1608 } 1791 1609 // otherwise, anchor the items 1792 1610 } else { 1793 1611 // check if this is anchoring a rectangle … … 1812 1630 Picture clickedOnPicture = (Picture)clicked; 1813 1631 Frame current_frame = DisplayIO.getCurrentFrame(); 1814 Colo r bg_col = current_frame.getBackgroundColor();1632 Colour bg_col = current_frame.getBackgroundColor(); 1815 1633 if (clickedOnPicture.MouseOverBackgroundPixel(mouseX,mouseY,bg_col)) { 1816 1634 clicked = null; // Effectively make it as if they haven't clicked on anything … … 1823 1641 if (clicked.isLineEnd()) { 1824 1642 if (!clicked.hasPermission(UserAppliedPermission.full)) { 1825 MessageBay 1826 .displayMessage("Insufficient permission to unreel"); 1643 MessageBay.displayMessage("Insufficient permission to unreel"); 1827 1644 return; 1828 1645 } … … 1833 1650 clicked = editTarget; 1834 1651 } else { 1835 MessageBay 1836 .displayMessage("Insufficient permission to copy"); 1652 MessageBay.displayMessage("Insufficient permission to copy"); 1837 1653 return; 1838 1654 } … … 1846 1662 // otherwise, create a rectangle 1847 1663 } else { 1848 Item on = FrameUtils.onItem(DisplayIO.getCurrentFrame(), 1849 MouseX, MouseY, true); 1664 Item on = FrameUtils.onItem(DisplayIO.getCurrentFrame(), MouseX, MouseY, true); 1850 1665 // if its on a line then create a line from that line 1851 1666 if (on instanceof Line && on.hasPermission(UserAppliedPermission.full)) { … … 1860 1675 updateCursor(); 1861 1676 FrameGraphics.Repaint(); 1862 }1863 1864 /**1865 *1866 */1867 private static void stampItemsOnCursor(boolean save) {1868 List<Item> copies = copy(FreeItems.getInstance());1869 // MIKE: what does the below 2 lines do?1870 for (Item i : copies) {1871 i.setOffset(0, 0);1872 i.setSave(save);1873 }1874 // The below code has a little problem withflicker when stamp1875 // and dragging1876 move(FreeItems.getInstance());1877 for (Item i : copies) {1878 i.setHighlightMode(HighlightMode.None);1879 }1880 anchor(copies);1881 1677 } 1882 1678 … … 1907 1703 } 1908 1704 1909 /** 1910 * Marks the items as not belonging to any specific frame. When picking up 1911 * items the parent will be automatically cleared for items on the current 1912 * frame but not for overlay items. This method ensures that overlay items 1913 * will also be cleared. This is useful when picking up copies of items from 1914 * an overlay (with the right mouse button) to ensure that the copy will be 1915 * anchored on the current frame rather than the overlay. When items are 1916 * picked up with the middle button clearParent should NOT be called. 1917 * 1918 * @param items 1919 * to have their parent cleared 1920 */ 1921 private static void clearParent(List<Item> items) { 1922 for (Item i : items) { 1923 // The next line is only necessary for circles... 1924 // Need to clean up/refactory some of this stuff 1925 i.getParentOrCurrentFrame().removeItem(i); 1926 i.setParent(null); 1927 } 1928 } 1929 1930 private static boolean inWindow = false; 1931 /** 1932 * event called when mouse exits window 1933 * (can't use MouseListener callback since that callback doesn't 1934 * correctly receive all mouse exit events) 1935 */ 1936 public static void mouseExitedWindow(MouseEvent e) { 1937 inWindow = false; 1938 // System.out.println("Left window"); 1939 if(FreeItems.itemsAttachedToCursor()) { 1940 boolean cut = true; 1941 for(Item i : FreeItems.getInstance()) { 1942 for(Item j : i.getAllConnected()) { 1943 if(!FreeItems.getInstance().contains(j)) { 1944 cut = false; 1945 break; 1946 } 1947 } 1948 } 1949 if(cut) { 1950 ItemSelection.cut(); 1951 } 1952 } 1953 } 1954 1955 public void mouseEntered(MouseEvent e) { 1956 // check if we are entering the window from outside of the window, or if we were just over a widget 1957 if(!inWindow) { 1958 inWindow = true; 1959 // if there is expeditee data on the clipboard that has not yet been autoPasted, autoPaste it 1960 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); 1961 Transferable content = c.getContents(null); 1962 try { 1963 if(content.isDataFlavorSupported(ItemSelection.expDataFlavor)) { // Expeditee data 1964 ExpDataHandler expData = (ExpDataHandler)content.getTransferData(ItemSelection.expDataFlavor); 1965 if(expData.autoPaste) { 1966 List<Item> items = new ExpClipReader(FrameMouseActions.getX(), FrameMouseActions.getY()).read(expData.items); 1967 // generate new IDs and pickup 1968 FrameMouseActions.pickup(ItemUtils.CopyItems(items)); 1969 // update the clipboard contents so they won't be autoPasted again 1970 expData.autoPaste = false; 1971 String stringData = ""; 1972 Image imageData = null; 1973 if(content.isDataFlavorSupported(DataFlavor.stringFlavor)) { 1974 stringData = (String) content.getTransferData(DataFlavor.stringFlavor); 1975 } 1976 if(content.isDataFlavorSupported(DataFlavor.imageFlavor)) { 1977 imageData = (Image) content.getTransferData(DataFlavor.imageFlavor); 1978 } 1979 c.setContents(new ItemSelection(stringData, imageData, expData), null); 1980 } 1981 } 1982 } catch(Exception ex) { 1983 ex.printStackTrace(); 1984 } 1985 } 1986 } 1987 1988 public void mouseExited(MouseEvent e) { 1989 } 1705 // public void mouseExited(MouseEvent e) { 1706 // } 1990 1707 1991 1708 private boolean _overFrame; 1992 1709 private int panStartX, panStartY; 1993 1710 private boolean _isPanOp; 1711 1994 1712 public void mouseDragged(MouseEvent e) { 1995 1713 _lastMouseDragged = e; … … 1998 1716 // Stop the longDepress mouse timer if the user drags above a threshold 1999 1717 if (_MouseTimer.isRunning()) { 2000 if (Math.abs(e.getX() - _lastMouseClick.getX()) 2001 + Math.abs(e.getY() - _lastMouseClick.getY()) > 10) 1718 if (Math.abs(e.getX() - _lastMouseClick.getX()) + Math.abs(e.getY() - _lastMouseClick.getY()) > 10) { 2002 1719 _MouseTimer.stop(); 1720 } 2003 1721 } 2004 1722 … … 2007 1725 } 2008 1726 2009 /* 2010 * Have the free items follow the cursor if the user clicks in freespace 2011 * then moves. 2012 */ 1727 // Have the free items follow the cursor if the user clicks in freespace then moves. 2013 1728 if (FreeItems.getInstance().size() > 0 && _lastClickedOn == null) { 2014 1729 mouseMoved(e); … … 2017 1732 2018 1733 // panning the frame when dragging the mouse while shift-leftclicking 2019 if(ExperimentalFeatures.MousePan.get() && _overFrame && e.isShiftDown() &&1734 /* if(ExperimentalFeatures.MousePan.get() && _overFrame && e.isShiftDown() && 2020 1735 (e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) != 0 && 2021 (_isPanOp || (Math.max(Math.abs(panStartX - e.getX()), Math.abs(panStartY - e.getY())) > 5))) { 1736 (_isPanOp || (Math.max(Math.abs(panStartX - e.getX()), Math.abs(panStartY - e.getY())) > 5))) 1737 { 2022 1738 int dX = (int) (e.getX() - MouseX); 2023 1739 int dY = (int) (e.getY() - MouseY); … … 2026 1742 MouseY = e.getY(); 2027 1743 _isPanOp = true; 2028 } 1744 }*/ 2029 1745 2030 1746 // check if user is dragging across a text item … … 2036 1752 2037 1753 int distance = _lastRanged.getY() - FrameMouseActions.getY(); 2038 if (distance <= 0) 2039 distance = FrameMouseActions.getY() - _lastRanged.getY() 2040 - _lastRanged.getBoundsHeight(); 1754 if (distance <= 0) distance = FrameMouseActions.getY() - _lastRanged.getY() - _lastRanged.getBoundsHeight(); 2041 1755 2042 1756 if (distance > UserSettings.NoOpThreshold.get()) { … … 2045 1759 } else { 2046 1760 // update the ranged section 2047 _lastRanged.setSelectionEnd(DisplayIO.getMouseX(), 2048 FrameMouseActions.getY()); 1761 _lastRanged.setSelectionEnd(DisplayIO.getMouseX(), DisplayIO.getMouseY()); 2049 1762 _isNoOp = false; 2050 1763 } 2051 1764 2052 DisplayIO.setTextCursor(_lastRanged, Text.NONE, false, e 2053 .isShiftDown(), e.isControlDown(), false); 1765 DisplayIO.setTextCursor(_lastRanged, Text.NONE, false, e.isShiftDown(), e.isControlDown(), false); 2054 1766 FrameGraphics.Repaint(); 2055 1767 return; … … 2058 1770 // if the user is dragging across a picture 2059 1771 if (_lastCropped != null) { 2060 // If shift is down then the distance moved is the same in the x and 2061 // y 1772 // If shift is down then the distance moved is the same in the x and y 2062 1773 MouseX = e.getX(); 2063 1774 MouseY = e.getY(); … … 2067 1778 int deltaY = Math.abs(e.getY() - _lastMouseClick.getY()); 2068 1779 if (deltaX > deltaY) { 2069 MouseY = _lastMouseClick.getY() + deltaX 2070 * (e.getY() > _lastMouseClick.getY() ? 1 : -1); 1780 MouseY = _lastMouseClick.getY() + deltaX * (e.getY() > _lastMouseClick.getY() ? 1 : -1); 2071 1781 } else { 2072 MouseX = _lastMouseClick.getX() + deltaY 2073 * (e.getX() > _lastMouseClick.getX() ? 1 : -1); 1782 MouseX = _lastMouseClick.getX() + deltaY * (e.getX() > _lastMouseClick.getX() ? 1 : -1); 2074 1783 } 2075 1784 } 2076 1785 // update the ranged section 2077 _lastCropped.setEndCrop(DisplayIO.getMouseX(), FrameMouseActions 2078 .getY()); 1786 _lastCropped.setEndCrop(DisplayIO.getMouseX(), DisplayIO.getMouseY()); 2079 1787 2080 1788 FrameGraphics.Repaint(); … … 2082 1790 } 2083 1791 2084 /* 2085 * This is the context of a user clicking in freespace an dragging onto 2086 * the edge of a line 2087 */ 2088 if ((_mouseDown == MouseEvent.BUTTON2 || _mouseDown == MouseEvent.BUTTON3) 2089 && _lastClickedOn == null && _lastClickedIn == null) { 2090 Item on = FrameUtils.onItem(DisplayIO.getCurrentFrame(), e.getX(), 2091 e.getY(), true); 1792 // This is the context of a user clicking in freespace an dragging onto 1793 // the edge of a line 1794 if ( (_mouseDown == MouseEvent.BUTTON2 || _mouseDown == MouseEvent.BUTTON3) && 1795 _lastClickedOn == null && 1796 _lastClickedIn == null) 1797 { 1798 Item on = FrameUtils.onItem(DisplayIO.getCurrentFrame(), e.getX(), e.getY(), true); 2092 1799 2093 1800 if (FreeItems.getInstance().size() == 0) { … … 2101 1808 on.setHighlightMode(Item.HighlightMode.Normal); 2102 1809 } else if (_lastHighlightedItem != null) { 2103 _lastHighlightedItem 2104 .setHighlightMode(Item.HighlightMode.None); 1810 _lastHighlightedItem.setHighlightMode(Item.HighlightMode.None); 2105 1811 _lastHighlightedItem = null; 2106 1812 } … … 2110 1816 // Use the below calculation for better speed. If it causes problems 2111 1817 // switch back to the Euclidean distance calculation 2112 if (Math.abs(MouseX - e.getX()) > UserSettings.NoOpThreshold.get() 2113 || Math.abs(MouseY - e.getY()) > UserSettings.NoOpThreshold.get()) 1818 if ( Math.abs(MouseX - e.getX()) > UserSettings.NoOpThreshold.get() || 1819 Math.abs(MouseY - e.getY()) > UserSettings.NoOpThreshold.get()) 1820 { 2114 1821 _isNoOp = true; 2115 1822 } 1823 2116 1824 FrameGraphics.Repaint(); 2117 1825 } 2118 1826 2119 1827 private static MouseEvent _lastMouseMoved = null; 2120 2121 private static Integer LastRobotX = null;2122 2123 private static Integer LastRobotY = null;2124 2125 // For some reason... sometimes the mouse move gets lost when moving the2126 // mouse really quickly after clicking...2127 // Use this timer to make sure it gets reset eventually if the Robot2128 // generated event never arrives.2129 private static Timer _RobotTimer = new Timer(200, new ActionListener() {2130 public void actionPerformed(ActionEvent ae) {2131 _RobotTimer.stop();2132 LastRobotX = null;2133 LastRobotY = null;2134 // System.out.println("RobotTimer");2135 }2136 });2137 1828 2138 1829 private static Timer _autoStampTimer = new Timer(200, new ActionListener() { … … 2152 1843 } 2153 1844 2154 public static boolean isControlDown() {2155 return _controlDown;2156 }2157 2158 public static boolean isShiftDown() {2159 return _shiftDown;2160 }2161 2162 public static void setLastRobotMove(float x, float y) {2163 // Make sure the system is in the right state while waiting for the2164 // Robots event to arrive.2165 MouseX = x;2166 MouseY = y;2167 // System.out.println("MouseMoved: " + MouseX + "," + MouseY + " " +2168 // System.currentTimeMillis());2169 LastRobotX = Math.round(x);2170 LastRobotY = Math.round(y);2171 _RobotTimer.start();2172 }2173 2174 public static boolean isWaitingForRobot() {2175 return LastRobotX != null;2176 }2177 2178 1845 /** 2179 1846 * Updates the stored mouse position and highlights any items as necessary. … … 2183 1850 } 2184 1851 2185 private void mouseMoved(MouseEvent e, boolean shiftStateChanged) {2186 // System.out.println("mouseMoved");2187 // System.out.println(_context);2188 if (_context == CONTEXT_FREESPACE)2189 FrameKeyboardActions.resetEnclosedItems();2190 // System.out.println(e.getX() + "," + e.getY() + " " + e.getWhen());2191 if (LastRobotX != null) {2192 // Wait until the last Robot mouse move event arrives before2193 // processing other events2194 if (/* FreeItems.getInstance().size() == 0 || */2195 (LastRobotX == e.getX() && LastRobotY == e.getY())) {2196 LastRobotX = null;2197 LastRobotY = null;2198 _RobotTimer.stop();2199 } else {2200 // System.out.println("Ignored: " +2201 // FreeItems.getInstance().size());2202 return;2203 }2204 }2205 2206 MouseX = e.getX();2207 MouseY = e.getY();2208 2209 // System.out.println(MouseX + "," + MouseY);2210 2211 // Moving the mouse a certain distance removes the last edited text if2212 // it is empty2213 Text lastEdited = FrameUtils.getLastEdited();2214 if (lastEdited != null && lastEdited.getText().length() == 02215 && lastEdited.getPosition().distance(e.getPoint()) > 20) {2216 FrameUtils.setLastEdited(null);2217 }2218 2219 // If shift is down then the movement is constrained2220 if (_controlDown && FreeItems.getInstance().size() > 0) {2221 // Check if we are rubber banding a line2222 if (shiftStateChanged && rubberBanding()) {2223 // Get the line end that is being rubber banded2224 Item thisEnd = FreeItems.getInstance().get(0).isLineEnd() ? FreeItems2225 .getInstance().get(0)2226 : FreeItems.getInstance().get(1);2227 Line line = (Line) (FreeItems.getInstance().get(0).isLineEnd() ? FreeItems2228 .getInstance().get(1)2229 : FreeItems.getInstance().get(0));2230 Item otherEnd = line.getOppositeEnd(thisEnd);2231 int deltaX = Math.abs(e.getX() - otherEnd.getX());2232 int deltaY = Math.abs(e.getY() - otherEnd.getY());2233 // Check if its a vertical line2234 if (deltaX < deltaY / 2) {2235 // otherEnd.setX(thisEnd.getX());2236 // MouseX = otherEnd.getX();2237 if (shiftStateChanged) {2238 new Constraint(thisEnd, otherEnd, thisEnd2239 .getParentOrCurrentFrame().getNextItemID(),2240 Constraint.VERTICAL);2241 }2242 }2243 // Check if its horizontal2244 else if (deltaY <= deltaX / 2) {2245 // MouseY = otherEnd.getY();2246 // otherEnd.setY(thisEnd.getY());2247 if (shiftStateChanged) {2248 new Constraint(thisEnd, otherEnd, thisEnd2249 .getParentOrCurrentFrame().getNextItemID(),2250 Constraint.HORIZONTAL);2251 }2252 } else {2253 // Add DIAGONAL constraints2254 // if (deltaX > deltaY) {2255 // otherEnd.setY(thisEnd.getY() + deltaX2256 // * (e.getY() < otherEnd.getY() ? 1 : -1));2257 // } else {2258 // otherEnd.setX(thisEnd.getX() + deltaY2259 // * (e.getX() < otherEnd.getX() ? 1 : -1));2260 // }2261 if (shiftStateChanged) {2262 int constraint = Constraint.DIAGONAL_NEG;2263 // Check if the slope is positive2264 if ((thisEnd.getY() - otherEnd.getY())2265 / (double) (thisEnd.getX() - otherEnd.getX()) > 0.0) {2266 constraint = Constraint.DIAGONAL_POS;2267 }2268 2269 new Constraint(thisEnd, otherEnd, thisEnd2270 .getParentOrCurrentFrame().getNextItemID(),2271 constraint);2272 }2273 }2274 }// If its a lineend attached to two lines lengthen the shorter2275 // so it is the same length as the longer line2276 else if (FreeItems.getInstance().size() == 3) {2277 // check if we are rubber banding the corner of a shape2278 Item thisEnd = getShapeCorner(FreeItems.getInstance());2279 if (thisEnd != null) {2280 Line line1 = thisEnd.getLines().get(0);2281 Line line2 = thisEnd.getLines().get(1);2282 // Check if the two lines are constrained and hence it is a2283 // rectangle2284 Integer c1 = line1.getPossibleConstraint();2285 Integer c2 = line2.getPossibleConstraint();2286 2287 if (c1 != null && c2 != null) {2288 // This is the case of a constrained rectangle2289 if ((c2 == Constraint.VERTICAL || c2 == Constraint.HORIZONTAL)2290 && (c1 == Constraint.VERTICAL || c1 == Constraint.HORIZONTAL)2291 && (c1 != c2)) {2292 Line vLine = line2;2293 Line hLine = line1;2294 if (c1 == Constraint.VERTICAL) {2295 vLine = line1;2296 hLine = line2;2297 }2298 Item hOtherEnd = hLine.getOppositeEnd(thisEnd);2299 Item vOtherEnd = vLine.getOppositeEnd(thisEnd);2300 2301 double vLength = Math2302 .abs(vOtherEnd.getY() - MouseY);2303 double hLength = Math2304 .abs(hOtherEnd.getX() - MouseX);2305 2306 if (vLength > hLength) {2307 MouseX = Math.round(hOtherEnd.getX() + vLength2308 * (MouseX > hOtherEnd.getX() ? 1 : -1));2309 } else /* if (hLength > vLength) */{2310 MouseY = Math.round(vOtherEnd.getY() + hLength2311 * (MouseY > vOtherEnd.getY() ? 1 : -1));2312 }2313 }2314 // } else if (c2 != null) {2315 //2316 // } // Other wise it is a not constrained shape so2317 // constrain2318 // the two lines lengths to be equal2319 } else {2320 Item lineEnd1 = line1.getOppositeEnd(thisEnd);2321 Item lineEnd2 = line2.getOppositeEnd(thisEnd);2322 double l1 = Line.getLength(lineEnd1.getPosition(), e2323 .getPoint());2324 double l2 = Line.getLength(lineEnd2.getPosition(), e2325 .getPoint());2326 double l3 = Line.getLength(lineEnd1.getPosition(),2327 lineEnd2.getPosition());2328 // l1 needs to be the shorter end2329 if (l1 > l2) {2330 Item temp = lineEnd1;2331 lineEnd1 = lineEnd2;2332 lineEnd2 = temp;2333 double tempL = l1;2334 l1 = l2;2335 l2 = tempL;2336 }2337 // Now use the cosine rule to calculate the angle2338 // between l1 and l32339 double cosTheta = (l1 * l1 + l3 * l3 - l2 * l2)2340 / (2 * l1 * l3);2341 // now calculate the new length for the lines using cos2342 // rule2343 double l_new = l3 / (2 * cosTheta);2344 double ratio = l_new / l1;2345 MouseX = Math.round((e.getX() - lineEnd1.getX())2346 * ratio)2347 + lineEnd1.getX();2348 MouseY = Math.round((e.getY() - lineEnd1.getY())2349 * ratio)2350 + lineEnd1.getY();2351 2352 }2353 }2354 }2355 } else if (shiftStateChanged && !_controlDown && rubberBanding()) {2356 // Get the line end that is being rubber banded2357 Item thisEnd = FreeItems.getInstance().get(0).isLineEnd() ? FreeItems2358 .getInstance().get(0)2359 : FreeItems.getInstance().get(1);2360 thisEnd.removeAllConstraints();2361 }2362 2363 if (_lastMouseMoved == null)2364 _lastMouseMoved = e;2365 2366 _lastMouseMoved = e;2367 2368 refreshHighlights();2369 2370 if (FreeItems.hasCursor()) {2371 move(FreeItems.getCursor(), true);2372 }2373 2374 if (FreeItems.itemsAttachedToCursor()) {2375 move(FreeItems.getInstance());2376 // System.out.println(FreeItems.getInstance().size());2377 }2378 2379 if (_forceArrowCursor)2380 updateCursor();2381 2382 _forceArrowCursor = true;2383 }2384 2385 1852 2386 public void refreshHighlights() { 2387 // ByMike: Get the item the mouse is hovering over 2388 Item click = FrameUtils.getCurrentItem(); 2389 Item on = null; 2390 // System.out.println(click); 2391 if (click != null) { 2392 on = click; 2393 // set the context 2394 if (on instanceof Line) 2395 _context = CONTEXT_AT_LINE; 2396 else if (on instanceof Dot) 2397 _context = CONTEXT_AT_DOT; 2398 else if (on instanceof Text) { 2399 _context = CONTEXT_AT_TEXT; 2400 } 2401 if (FreeItems.getInstance().size() > 0) 2402 _alpha = 60; 2403 else 2404 _alpha = -1; 2405 } else { 2406 _context = CONTEXT_FREESPACE; 2407 _alpha = -1; 2408 } 2409 2410 // if the user is pointing at an item, highlight it 2411 if (on != null && !FreeItems.getInstance().contains(on)) { 2412 // if the user can spot-weld, show the virtual spot 2413 if (FreeItems.getInstance().size() == 2 && on instanceof Line) { 2414 Line line = (Line) on; 2415 Item freeItem0 = FreeItems.getInstance().get(0); 2416 Item freeItem1 = FreeItems.getInstance().get(1); 2417 Item lineEnd = freeItem0.isLineEnd() ? freeItem0 : (freeItem1 2418 .isLineEnd() ? freeItem1 : null); 2419 if (lineEnd != null) { 2420 if (_mouseDown == 0) 2421 line.showVirtualSpot(lineEnd, DisplayIO.getMouseX(), 2422 FrameMouseActions.getY()); 2423 } else 2424 // The user is pointing at another point or text item 2425 // etc 2426 FrameGraphics.changeHighlightMode(on, 2427 Item.HighlightMode.Normal); 2428 } else { 2429 // FrameGraphics.ChangeSelectionMode(on, 2430 // Item.SelectedMode.Connected); 2431 // TODO: The method below is for the most part redundant 2432 2433 on = FrameGraphics.Highlight(on.getEditTarget()); 2434 } 2435 // if the last item highlighted is still highlighted, clear it 2436 if (_lastHoldsHighlight) { 2437 _lastHoldsHighlight = false; 2438 for (Item i : DisplayIO.getCurrentFrame().getItems()) 2439 if (i.isHighlighted() && i != on) 2440 FrameGraphics.changeHighlightMode(i, 2441 Item.HighlightMode.None); 2442 } 2443 2444 // if the user is not pointing at an item, check for enclosure 2445 // highlighting 2446 } else if (on == null) { 2447 Collection<Item> enclosure = FrameUtils.getEnclosingLineEnds(); 2448 if (enclosure != null && enclosure.size() > 0) { 2449 Item firstLineEnd = enclosure.iterator().next(); 2450 HighlightMode hm; 2451 if(isShiftDown()) { 2452 hm = HighlightMode.Connected; 2453 } else { 2454 hm = HighlightMode.Enclosed; 2455 } 2456 if (firstLineEnd.getLines().size() > 1 && 2457 // check that the enclosure is not part of a point being 2458 // dragged in space 2459 !ContainsOneOf(enclosure, FreeItems.getInstance())) { 2460 on = firstLineEnd.getLines().get(0); 2461 // System.out.println(on == null ? "Null" : 2462 // on.toString()); 2463 FrameGraphics.changeHighlightMode(on, hm); 2464 } else if (firstLineEnd instanceof XRayable) { 2465 on = firstLineEnd; 2466 FrameGraphics.changeHighlightMode(firstLineEnd, hm); 2467 } 2468 _context = CONTEXT_AT_ENCLOSURE; 2469 } else if (_lastHighlightedItem != null) { 2470 // System.out.println("LastHighlightedItem"); 2471 _lastHoldsHighlight = false; 2472 } 2473 } 2474 2475 // disable cursor changes when the cursor has items attached 2476 if (FreeItems.itemsAttachedToCursor() 2477 && DisplayIO.getCursor() != Item.TEXT_CURSOR) 2478 _forceArrowCursor = false; 2479 2480 // setLastHighlightedItem(on); 2481 2482 if (_lastHighlightedItem != null && _lastHighlightedItem != on 2483 && !_lastHoldsHighlight) { 2484 // Turn off the highlighting only if 2485 // the last highlighted item is not connected to the currentItem 2486 // Otherwise we get flickering in transition from connected to 2487 // normal mode while moving the cursor along a line. 2488 if (on == null 2489 || (!on.getAllConnected().contains(_lastHighlightedItem))) { 2490 FrameGraphics.changeHighlightMode(_lastHighlightedItem, 2491 Item.HighlightMode.None); 2492 } 2493 } 2494 2495 _lastHighlightedItem = on; 2496 2497 } 2498 2499 private boolean ContainsOneOf(Collection<Item> enclosure, 2500 Collection<Item> freeItems) { 2501 if (freeItems == null) 2502 return false; 2503 for (Item i : freeItems) { 2504 if (enclosure.contains(i)) 2505 return true; 2506 } 2507 return false; 2508 } 2509 2510 /** 2511 * Checks if lines are being rubber banded. 2512 * 2513 * @return true if the user is rubberBanding one or more lines 2514 */ 2515 private static boolean rubberBanding() { 2516 if (FreeItems.getInstance().size() != 2) { 2517 return false; 2518 } 2519 2520 // if rubber-banding, there will be 1 lineend and the rest will be lines 2521 boolean foundLineEnd = false; 2522 for (Item i : FreeItems.getInstance()) { 2523 if (i.isLineEnd()) { 2524 if (foundLineEnd) { 2525 return false; 2526 } 2527 foundLineEnd = true; 2528 } else if (!(i instanceof Line) || !i.isVisible()) { 2529 return false; 2530 } 2531 } 2532 return true; 2533 } 2534 2535 /** 2536 * Updates the current mouse cursor to whatever it should be. i.e. Hidden 2537 * when rubber-banding lines, otherwise default (arrow) 2538 */ 2539 public static void updateCursor() { 2540 if (rubberBanding()) { 2541 DisplayIO.setCursor(Item.HIDDEN_CURSOR); 2542 return; 2543 } 2544 // This is to make sure the TEXT_CURSOR doesnt get inadvertantly turned 2545 // off! 2546 Item on = FrameUtils.getCurrentItem(); 2547 if (on != null && on instanceof Text) { 2548 return; 2549 } 2550 DisplayIO.setCursor(Item.DEFAULT_CURSOR); 2551 } 2552 2553 public static void setHighlightHold(boolean hold) { 2554 _lastHoldsHighlight = hold; 2555 } 2556 2557 public static void resetOffset() { 2558 if (FreeItems.itemsAttachedToCursor()) { 2559 _offX = DisplayIO.getMouseX() 2560 - FreeItems.getInstance().get(0).getX() 2561 + FreeItems.getInstance().get(0).getOffset().x; 2562 _offY = getY() - FreeItems.getInstance().get(0).getY() 2563 + FreeItems.getInstance().get(0).getOffset().y; 2564 } 2565 } 2566 2567 /** 2568 * Moves the items to the current mouse position (plus the current offset) 2569 * 2570 * @param toMove 2571 */ 2572 static void move(Collection<Item> toMove) { 2573 move(toMove, false); 2574 } 2575 2576 static void move(Collection<Item> toMove, boolean cursor) { 2577 2578 // Gets the origin of the first item to move 2579 int xPos = (DisplayIO.getMouseX() - (cursor ? 0 : _offX)); 2580 2581 Item firstDot = toMove.iterator().next(); 2582 2583 int deltax = firstDot.getX() - xPos; 2584 int deltay = firstDot.getY() - (getY() - (cursor ? 0 : _offY)); 2585 2586 for (Item move : toMove) { 2587 move.setPosition(move.getX() - deltax, move.getY() - deltay); 2588 2589 if (!cursor && move instanceof Text) { 2590 ((Text) move).setAlpha(_alpha); 2591 } 2592 } 2593 2594 FrameGraphics.requestRefresh(true); 2595 // FrameGraphics.refresh(true); 2596 } 2597 2598 private static void load(String toLoad, boolean addToHistory) { 2599 if (FrameIO.isValidFrameName(toLoad)) { 2600 DisplayIO.clearBackedUpFrames(); 2601 FrameUtils.DisplayFrame(toLoad, addToHistory, true); 2602 } else { 2603 MessageBay.errorMessage(toLoad + " is not a valid frame name."); 2604 } 2605 } 2606 2607 private static void back() { 2608 DisplayIO.Back(); 2609 2610 // repaint things if necessary 2611 if (FreeItems.itemsAttachedToCursor()) 2612 move(FreeItems.getInstance()); 2613 2614 if (FreeItems.hasCursor()) 2615 move(FreeItems.getCursor(), true); 2616 } 2617 2618 private static void forward() { 2619 DisplayIO.Forward(); 2620 2621 // repaint things if necessary 2622 if (FreeItems.itemsAttachedToCursor()) 2623 move(FreeItems.getInstance()); 2624 2625 if (FreeItems.hasCursor()) 2626 move(FreeItems.getCursor(), true); 2627 } 2628 2629 /** 2630 * Returns true if the mouse moved during TDFC. This will happen if there is 2631 * a start annotation item on the frame. 2632 * 2633 * @param linker 2634 * @return 2635 */ 2636 public static boolean tdfc(Item linker) throws RuntimeException { 2637 // if this is a non-usable item 2638 if (linker.getID() < 0) 2639 return false; 2640 2641 // Check if its an image that can be resized to fit a box 2642 // around it 2643 String text = linker.getText(); 2644 boolean isVector = text.equals("@v") || text.equals("@av"); 2645 boolean isFrameImage = text.equals("@f"); 2646 boolean isBitmap = false; // text.equals("@b"); 2647 2648 if (isVector || isFrameImage || isBitmap) { 2649 Collection<Item> enclosure = FrameUtils.getEnclosingLineEnds(linker 2650 .getPosition()); 2651 if (enclosure != null) { 2652 for (Item i : enclosure) { 2653 if (i.isLineEnd() && i.isEnclosed()) { 2654 if (!isVector) 2655 DisplayIO.getCurrentFrame().removeAllItems( 2656 enclosure); 2657 Rectangle rect = i.getEnclosedRectangle(); 2658 long width = Math.round(rect.getWidth()); 2659 if (isVector) { 2660 NumberFormat nf = Vector.getNumberFormatter(); 2661 linker.setText(linker.getText() 2662 + ": " 2663 + nf.format((width / FrameGraphics 2664 .getMaxFrameSize().getWidth()))); 2665 } else { 2666 linker.setText(linker.getText() + ": " + width); 2667 } 2668 2669 linker.setPosition(new Point(rect.x, rect.y)); 2670 linker.setThickness(i.getThickness()); 2671 linker.setBorderColor(i.getColor()); 2672 break; 2673 } 2674 } 2675 if (!isVector) 2676 FrameMouseActions.deleteItems(enclosure, false); 2677 } 2678 } 2679 2680 boolean mouseMoved; 2681 2682 linker.getParent().setChanged(true); 2683 2684 Frame next = FrameIO.CreateNewFrame(linker, _onFrameAction); 2685 2686 linker.setLink("" + next.getNumber()); 2687 2688 for (Item i : next.getTextItems()) { 2689 // Set the link for @Parent annotation item if one 2690 if (ItemUtils.startsWithTag(i, ItemUtils.TAG_PARENT) 2691 && i.getLink() == null) { 2692 Frame parent = linker.getParentOrCurrentFrame(); 2693 i.setLink(parent.getName()); 2694 } else if (ItemUtils.startsWithTag(i, ItemUtils.TAG_BACKUP, false)) { 2695 // Delink backup tag if it is on the frame 2696 i.setLink(null); 2697 } 2698 } 2699 2700 FrameUtils.DisplayFrame(next, true, true); 2701 FrameUtils.setTdfcItem(linker); 2702 2703 mouseMoved = next.moveMouseToDefaultLocation(); 2704 // this needs to be done if the user doesnt move the mouse before doing 2705 // tdfc while the cursor is set to the text cursor 2706 DisplayIO.setCursor(Item.DEFAULT_CURSOR); 2707 // This needs to be done in case there was a @start on the frame which 2708 // triggers changed to be set to true when it should stay as false 2709 next.setChanged(false); 2710 return mouseMoved; 2711 } 2712 2713 /** 2714 * Creates a new Text item and fills it with particular attributes extracted 2715 * from the given Item. Note: Users always have permission to extract 2716 * attributes, so it is not checked. 2717 * 2718 * @param toExtract 2719 * Item containing the Item to extract the attributes from. 2720 */ 2721 private static void extractAttributes(Item toExtract) { 2722 if (toExtract == null || toExtract == null) 2723 return; 2724 2725 if (FreeItems.itemsAttachedToCursor()) 2726 return; 2727 2728 Item attribs; 2729 Item item = toExtract; 2730 // Extract the frames attributes when the user clicks on the frame name 2731 FrameGraphics.changeHighlightMode(item, HighlightMode.None); 2732 if (item.isFrameName()) 2733 attribs = AttributeUtils.extractAttributes(item.getParent()); 2734 else { 2735 attribs = AttributeUtils.extractAttributes(item); 2736 } 2737 2738 if (attribs == null) 2739 MessageBay 2740 .displayMessage("All attributes of that item are default values."); 2741 else { 2742 // Give the attribute text item the color of the item for which 2743 // attributes are being extracted. 2744 // attribs.setColor(item.getColor()); 2745 pickup(attribs); 2746 } 2747 } 2748 2749 public static void delete(Item toDelete) { 2750 boolean bRecalculate = false; 2751 2752 FrameUtils.setLastEdited(null); 2753 _offX = _offY = 0; 2754 2755 Frame currentFrame = DisplayIO.getCurrentFrame(); 2756 // check if the user is pointing at the frame's framename 2757 if (toDelete != null && toDelete == currentFrame.getNameItem()) { 2758 currentFrame.clear(false); 2759 FrameGraphics.Repaint(); 2760 return; 2761 } 2762 2763 // if the user is deleting items attached to the cursor 2764 if (FreeItems.itemsAttachedToCursor()) { 2765 // if this is an item-swap 2766 if (FreeItems.getInstance().size() == 1 2767 && FreeItems.getInstance().get(0) instanceof Text 2768 && toDelete != null && toDelete instanceof Text) { 2769 2770 // check permissions 2771 if (!toDelete.hasPermission(UserAppliedPermission.full)) { 2772 MessageBay 2773 .displayMessage("Insufficient permission to swap Item text"); 2774 return; 2775 } 2776 Text anchored = (Text) toDelete; 2777 Text free = (Text) FreeItems.getInstance().get(0); 2778 SessionStats.DeletedItem(free); 2779 // List<String> temp = anchored.getText(); 2780 anchored.setText(free.getText()); 2781 anchored.setFormula(free.getFormula()); 2782 2783 // free.setTextList(temp); 2784 FreeItems.getInstance().clear(); 2785 2786 anchored.getParent().setChanged(true); 2787 2788 bRecalculate |= free.recalculateWhenChanged(); 2789 bRecalculate |= anchored.recalculateWhenChanged(); 2790 2791 // update the offset since the text has changed 2792 _offX = DisplayIO.getMouseX() - anchored.getX() 2793 + anchored.getOffset().x; 2794 _offY = getY() - anchored.getY() + anchored.getOffset().y; 2795 } else { 2796 // if shift is pressed delete the entire shape attached to the dot 2797 if(isShiftDown()) { 2798 List<Item> tmp = new ArrayList<Item>(FreeItems.getInstance()); 2799 for(Item i : tmp) { 2800 // remove entire rectangles instead of just the corner 2801 if(i instanceof Dot) { 2802 FreeItems.getInstance().addAll(i.getAllConnected()); 2803 for(Item j : i.getAllConnected()) { 2804 if(j instanceof Dot) { 2805 FreeItems.getInstance().addAll(j.getLines()); 2806 } 2807 } 2808 } 2809 } 2810 } 2811 deleteItems(FreeItems.getInstance()); 2812 } 2813 // reset the mouse cursor 2814 updateCursor(); 2815 // the user is not pointing at an item 2816 } else if (toDelete == null) { 2817 2818 // if the user is pointing inside a closed shape, delete it 2819 2820 Collection<Item> items = null; 2821 // if shift is down, only delete the enclosing shape (ignore the items inside) 2822 if(isShiftDown()) { 2823 Collection<Item> tmp = FrameUtils.getEnclosingLineEnds(); 2824 if(tmp != null) { 2825 items = new ArrayList<Item>(); 2826 items.addAll(tmp); 2827 for(Item i : tmp) { 2828 if(i instanceof Dot) { 2829 items.addAll(((Dot)i).getLines()); 2830 } 2831 } 2832 } 2833 } else { 2834 items = FrameUtils.getCurrentItems(null); 2835 } 2836 2837 if (items != null) { 2838 Collection<Item> toRemove = new LinkedHashSet<Item>(items 2839 .size()); 2840 for (Item ip : items) { 2841 if (ip.hasPermission(UserAppliedPermission.full)) { 2842 // Only include lines if one of their enpoints are also 2843 // being removed 2844 if (ip instanceof Line) { 2845 Line l = (Line) ip; 2846 Item end = l.getEndItem(); 2847 Item start = l.getStartItem(); 2848 2849 // If one end of a line is being deleted, remove the 2850 // other end if all its connecting lines are being 2851 // deleted 2852 if (items.contains(end)) { 2853 if (!items.contains(start) 2854 && items.containsAll(start.getLines())) { 2855 toRemove.add(start); 2856 } 2857 } else if (items.contains(start)) { 2858 if (items.containsAll(end.getLines())) { 2859 toRemove.add(end); 2860 } 2861 } else { 2862 continue; 2863 } 2864 } 2865 toRemove.add(ip); 2866 } 2867 } 2868 2869 deleteItems(toRemove); 2870 2871 // reset the mouse cursor 2872 updateCursor(); 2873 FrameGraphics.Repaint(); 2874 2875 // otherwise this is an undo command 2876 } else { 2877 if(isControlDown()) { 2878 DisplayIO.getCurrentFrame().redo(); 2879 } else { 2880 DisplayIO.getCurrentFrame().undo(); 2881 } 2882 } 2883 return; 2884 // this is a delete command 2885 } else { 2886 2887 // Special case if toDelete item is an image: only want to delete if over non-background pixel color 2888 if (toDelete instanceof Picture) { 2889 int mouseX = DisplayIO.getMouseX(); 2890 int mouseY = FrameMouseActions.getY(); 2891 Picture clickedOnPicture = (Picture)toDelete; 2892 Frame current_frame = DisplayIO.getCurrentFrame(); 2893 Color bg_col = current_frame.getBackgroundColor(); 2894 if (clickedOnPicture.MouseOverBackgroundPixel(mouseX,mouseY,bg_col)) { 2895 // behave as if Redo/Undo request, then return 2896 if(isControlDown()) { 2897 DisplayIO.getCurrentFrame().redo(); 2898 } else { 2899 DisplayIO.getCurrentFrame().undo(); 2900 } 2901 return; 2902 } 2903 // If get to here, then user clicked on an image (non-trival pixel color), 2904 // so go ahead and let it be deleted in the usual way 2905 } 2906 2907 2908 // check permissions 2909 if (!toDelete.hasPermission(UserAppliedPermission.full)) { 2910 Item editTarget = toDelete.getEditTarget(); 2911 if (editTarget != toDelete 2912 && editTarget.hasPermission(UserAppliedPermission.full)) { 2913 toDelete = editTarget; 2914 } else { 2915 MessageBay 2916 .displayMessage("Insufficient permission to delete item"); 2917 return; 2918 } 2919 } 2920 2921 Frame parent = toDelete.getParent(); 2922 if (parent != null) { 2923 parent.setChanged(true); 2924 } 2925 Collection<Item> toUndo = null; 2926 if (toDelete.isLineEnd()) { 2927 // delete the entire connected shape if shift is down 2928 if(isShiftDown()) { 2929 List<Item> tmp = new ArrayList<Item>(); 2930 tmp.add(toDelete); 2931 // remove entire shape instead of just the corner 2932 tmp.addAll(toDelete.getAllConnected()); 2933 for(Item j : toDelete.getAllConnected()) { 2934 if(j instanceof Dot) { 2935 tmp.addAll(j.getLines()); 2936 } 2937 } 2938 deleteItems(tmp); 2939 return; 2940 } else { 2941 toUndo = deleteLineEnd(toDelete); 2942 } 2943 // delete the entire connected shape if shift is down, unless we're hovering the end of the line 2944 } else if (toDelete instanceof WidgetEdge) { // must notify 2945 // widgets that they 2946 // are being deleted 2947 ((WidgetEdge) toDelete).getWidgetSource().onDelete(); 2948 toUndo = toDelete.getConnected(); 2949 } else if (toDelete instanceof Line && isShiftDown() || 2950 toDelete.getHighlightMode() == Item.HighlightMode.Disconnect) { 2951 Line line = (Line) toDelete; 2952 Item start = line.getStartItem(); 2953 Item end = line.getEndItem(); 2954 Collection<Item> delete = new LinkedList<Item>(); 2955 delete.add(toDelete); 2956 if (end.getLines().size() == 1) { 2957 delete.add(end); 2958 } else { 2959 end.removeLine(line); 2960 } 2961 if (start.getLines().size() == 1) { 2962 delete.add(start); 2963 } else { 2964 start.removeLine(line); 2965 } 2966 toUndo = delete; 2967 } else { 2968 bRecalculate |= toDelete.recalculateWhenChanged(); 2969 toUndo = toDelete.getConnected(); // copy(toDelete.getConnected()); 2970 } 2971 SessionStats.DeletedItems(toUndo); 2972 if (parent != null) { 2973 parent.addToUndoDelete(toUndo); 2974 parent.removeAllItems(toUndo); // toDelete.getConnected() 2975 } 2976 // reset the mouse cursor 2977 updateCursor(); 2978 if (parent != null) 2979 // ItemUtils.EnclosedCheck(parent.getItems()); 2980 ItemUtils.Justify(parent); 2981 if (toDelete.hasOverlay()) { 2982 FrameUtils.Parse(parent, false, false); 2983 FrameGraphics.requestRefresh(false); 2984 } 2985 2986 DisplayIO.setCursor(Item.DEFAULT_CURSOR); 2987 2988 } 2989 2990 currentFrame.notifyObservers(bRecalculate); 2991 2992 FrameGraphics.Repaint(); 2993 } 2994 2995 public static void deleteItems(Collection<Item> itemList) { 2996 deleteItems(itemList, true); 2997 } 2998 2999 public static void deleteItems(Collection<Item> itemList, boolean addToUndo) { 3000 boolean bReparse = false; 3001 boolean bRecalculate = false; 3002 3003 SessionStats.DeletedItems(itemList); 3004 List<Frame> modifiedFrames = new LinkedList<Frame>(); 3005 // Get a list of all the modified frames 3006 for (Item i : itemList) { 3007 Frame parent = i.getParent(); 3008 if (parent != null) 3009 modifiedFrames.add(parent); 3010 i.setHighlightMode(HighlightMode.None); 3011 bReparse |= i.hasOverlay(); 3012 bRecalculate |= i.recalculateWhenChanged(); 3013 } 3014 // If they are all free items then add the current frame 3015 if (modifiedFrames.size() == 0) { 3016 modifiedFrames.add(DisplayIO.getCurrentFrame()); 3017 } 3018 3019 Collection<Item> toUndo = new LinkedHashSet<Item>(); 3020 // disconnect any connected items 3021 for (Item i : itemList) { 3022 3023 // Only delete the current item if have not already deleted. 3024 // This is especially important for heavy duty widgets - so they 3025 // do not have to expire several times per delete. 3026 if (toUndo.contains(i)) 3027 continue; 3028 3029 // Make sure text items attached to cursor are reset back to the 3030 // transparency they should have. 3031 if (i instanceof Text) { 3032 ((Text) i).setAlpha(-1); 3033 } 3034 3035 if (i.getLines().size() > 0) { 3036 3037 Collection<Item> toDelete = deleteLineEnd(i); 3038 if (addToUndo) { 3039 // add the copied items to the undo stack 3040 for (Item itemToUndo : toDelete) { 3041 3042 if (!toUndo.contains(itemToUndo)) 3043 toUndo.add(itemToUndo); 3044 3045 } 3046 } 3047 } else if (!toUndo.contains(i)) { 3048 if (addToUndo) 3049 toUndo.add(i); // Why was is this a copy 3050 } 3051 } 3052 3053 for (Frame f : modifiedFrames) { 3054 f.removeAllItems(itemList); 3055 // ItemUtils.EnclosedCheck(f.getItems()); 3056 ItemUtils.Justify(f); 3057 } 3058 // TODO: How should undelete deal with undo when items are removed from 3059 // the current frame as well as the overlay frame 3060 Frame currentFrame = DisplayIO.getCurrentFrame(); 3061 currentFrame.addToUndoDelete(itemList); 3062 itemList.clear(); 3063 if (bReparse) { 3064 FrameUtils.Parse(currentFrame, false, false); 3065 /* 3066 * TODO check if I need to recalculate even if reparse occurs, here 3067 * and in anchor, pickup etc 3068 */ 3069 } else { 3070 currentFrame.notifyObservers(bRecalculate); 3071 } 3072 3073 } 3074 3075 private static Collection<Item> deleteLineEnd(Item lineEnd) { 3076 3077 if (lineEnd instanceof WidgetCorner) { // Brook 3078 3079 WidgetCorner wc = (WidgetCorner) lineEnd; 3080 Frame parent = wc.getWidgetSource().getParentFrame(); 3081 3082 // Remove from the parent frame 3083 if (parent != null) { 3084 parent.removeAllItems(wc.getWidgetSource().getItems()); 3085 } 3086 3087 wc.getWidgetSource().onDelete(); // Changes the widgets 3088 // corner/edges ID's... 3089 3090 return wc.getWidgetSource().getItems(); 3091 3092 } else { 3093 3094 // // create a backup copy of the dot and its lines 3095 // List<Item> copy = copy(lineEnd.getConnected()); 3096 // 3097 // // Remove lines from their anchored dots 3098 // // note: the line is kept so that it can be properly restored 3099 // for (Item ic : copy) { 3100 // if (ic instanceof Line) { 3101 // Line line = (Line) ic; 3102 // // Remove the line from the item that is not the copy of the 3103 // // line end being deletedF 3104 // if (!copy.contains(line.getStartItem())) 3105 // line.getStartItem().removeLine(line); 3106 // if (!copy.contains(line.getEndItem())) 3107 // line.getEndItem().removeLine(line); 3108 // } 3109 // } 3110 3111 Collection<Item> copy = lineEnd.getConnected(); 3112 3113 // remove all lines being deleted 3114 for (Item ic : lineEnd.getConnected()) { 3115 if (ic instanceof Line 3116 && ((Line) ic).getOppositeEnd(lineEnd) != null) { 3117 Line line = (Line) ic; 3118 3119 // Invalidate the line to make sure we dont get any ghost 3120 // arrowheads. 3121 ic.invalidateAll(); 3122 3123 Item d = line.getOppositeEnd(lineEnd); 3124 d.removeLine(line); 3125 3126 // if the dot was only part of one line, it can be 3127 // removed 3128 if (d.getLines().size() == 0) { 3129 if (d.getParent() != null) 3130 d.getParent().removeItem(d); 3131 if (!copy.contains(d)) 3132 copy.add(d); 3133 } 3134 3135 if (lineEnd.getParent() != null) 3136 lineEnd.getParent().removeItem(ic); 3137 } 3138 } 3139 return copy; 3140 } 3141 } 3142 3143 private static void removeAllLinesExcept(Item from, Item but) { 3144 List<Line> lines = new LinkedList<Line>(); 3145 lines.addAll(from.getLines()); 3146 for (Line line : lines) 3147 if (line.getOppositeEnd(from) != but) 3148 from.removeLine(line); 3149 3150 List<Constraint> consts = new LinkedList<Constraint>(); 3151 consts.addAll(from.getConstraints()); 3152 for (Constraint c : consts) 3153 if (c.getOppositeEnd(from) != but) 3154 from.removeConstraint(c); 3155 } 3156 3157 public static Collection<Item> merge(List<Item> merger, Item mergee) { 3158 assert (mergee != null); 3159 if (mergee.isFrameName()) { 3160 return mergee.getParent().merge(merger); 3161 } 3162 3163 // if(mergee instanceof XRayable) 3164 // return merger; 3165 3166 // check for rectangle merging 3167 if (merger.size() == 3 && mergee.getLines().size() == 2) { 3168 Item corner = getShapeCorner(merger); 3169 // if this is a corner of a shape 3170 if (corner != null) { 3171 Collection<Item> allConnected = corner.getAllConnected(); 3172 // Check if we are collapsing a rectangle 3173 if (allConnected.size() == 8 && allConnected.contains(mergee)) { 3174 DisplayIO.setCursorPosition(mergee.getPosition()); 3175 DisplayIO.getCurrentFrame().removeAllItems(allConnected); 3176 3177 // find the point opposite corner... 3178 Item opposite = null; 3179 List<Line> lines = corner.getLines(); 3180 for (Line l : lines) { 3181 allConnected.remove(l.getOppositeEnd(corner)); 3182 } 3183 allConnected.remove(corner); 3184 for (Item i : allConnected) { 3185 if (i.isLineEnd()) { 3186 opposite = i; 3187 break; 3188 } 3189 } 3190 assert (opposite != null); 3191 3192 // check if the rectangle is small enough that it should be 3193 // collapsed to a single point 3194 int x1 = Math.abs(opposite.getX() - mergee.getX()); 3195 int x2 = Math.abs(opposite.getY() - mergee.getY()); 3196 int distance = (int) Math.sqrt(Math.pow(x1, 2) 3197 + Math.pow(x2, 2)); 3198 3199 if (distance < RECTANGLE_TO_POINT_THRESHOLD) { 3200 mergee.removeAllConstraints(); 3201 mergee.removeAllLines(); 3202 mergee.setThickness(4 * mergee.getThickness()); 3203 return mergee.getAllConnected(); 3204 } else { 3205 removeAllLinesExcept(mergee, opposite); 3206 removeAllLinesExcept(opposite, mergee); 3207 3208 return mergee.getAllConnected(); 3209 } 3210 } 3211 } 3212 } 3213 3214 List<Item> remain = new ArrayList<Item>(); 3215 Item res = null; 3216 3217 for (Item i : merger) { 3218 if (!i.isVisible()) 3219 continue; 3220 // check for link merging 3221 if (i instanceof Text 3222 && FrameIO.isValidFrameName((((Text) i).getFirstLine())) 3223 && FrameIO.canAccessFrame((((Text) i).getFirstLine()))) { 3224 // check that we can actually access the frame this link 3225 // corresponds to 3226 mergee.setLink(((Text) i).getFirstLine()); 3227 } else { 3228 // check for attribute merging 3229 if (i instanceof Text && !i.isLineEnd()) { 3230 Text txt = (Text) i; 3231 3232 // if this is not an attribute merge 3233 if (!AttributeUtils.setAttribute(mergee, txt)) { 3234 // set mouse position for text merges 3235 if (mergee instanceof Text) { 3236 ((Text) mergee).insertText(txt.getText(), DisplayIO 3237 .getMouseX(), FrameMouseActions.getY()); 3238 //Delete the item which had its text merged 3239 txt.delete(); 3240 return remain; 3241 } else if (mergee instanceof WidgetCorner) { 3242 if (merger.size() == 1 && txt.getLink() != null) { 3243 // If the text item is linked then use that 3244 ((WidgetCorner) mergee).setLink(txt 3245 .getAbsoluteLink(), txt); 3246 } else { 3247 remain.addAll(merger); 3248 } 3249 return remain; 3250 } else if (mergee instanceof WidgetEdge) { 3251 if (merger.size() == 1 && txt.getLink() != null) { 3252 // If the text item is linked then use that 3253 ((WidgetEdge) mergee).setLink(txt 3254 .getAbsoluteLink(), txt); 3255 } else { 3256 remain.addAll(merger); 3257 } 3258 return remain; 3259 } else if (mergee instanceof Dot) { 3260 DisplayIO.setCursorPosition(mergee.getPosition()); 3261 txt.setPosition(mergee.getPosition()); 3262 txt.setThickness(mergee.getThickness()); 3263 Frame parent = mergee.getParent(); 3264 parent.removeItem(mergee); 3265 anchor(txt); 3266 // change the end points of the lines to the text 3267 // item 3268 while (mergee.getLines().size() > 0) { 3269 Line l = mergee.getLines().get(0); 3270 l.replaceLineEnd(mergee, txt); 3271 } 3272 break; 3273 } 3274 3275 // TODO tidy this up... 3276 // Dot override doesnt use the x and y coords 3277 // Text does... but could be removed 3278 res = mergee.merge(i, DisplayIO.getMouseX(), getY()); 3279 if (res != null) { 3280 remain.add(res); 3281 } 3282 } 3283 } else { 3284 if (mergee.isLineEnd()) { 3285 DisplayIO.setCursorPosition(mergee.getPosition()); 3286 } 3287 // Moving the cursor ensures shapes are anchored correctly 3288 res = mergee.merge(i, DisplayIO.getMouseX(), getY()); 3289 if (res != null) 3290 remain.addAll(res.getConnected()); 3291 3292 } 3293 } 3294 } 3295 updateCursor(); 3296 3297 mergee.getParent().setChanged(true); 3298 3299 ItemUtils.EnclosedCheck(mergee.getParent().getItems()); 3300 // Mike: Why does parse frame have to be called?!? 3301 FrameUtils.Parse(mergee.getParent()); 3302 3303 return remain; 3304 } 3305 3306 /** 3307 * Picks up an item on a frame. 3308 * 3309 * @param toGrab 3310 * item to be picked up 3311 * @param removeItem 3312 * true if the item should be removed from the frame 3313 */ 3314 public static void pickup(Item toGrab) { 3315 if (toGrab.isFrameName()) 3316 return; 3317 3318 if (!toGrab.hasPermission(UserAppliedPermission.full)) { 3319 if (toGrab.getEditTarget() != toGrab) { 3320 pickup(toGrab.getEditTarget()); 3321 } else { 3322 MessageBay 3323 .displayMessage("Insufficient permission pickup the item"); 3324 } 3325 return; 3326 } 3327 3328 if (toGrab instanceof Circle) 3329 toGrab.setHighlightMode(HighlightMode.Connected); 3330 // Dont set the highlight mode if a vector is being picked up 3331 else if (toGrab.isVisible()) { 3332 toGrab.setHighlightMode(HighlightMode.Normal); 3333 } 3334 3335 // Brook: If the widget corner is being picked up. Instead refer to 3336 // picking up the edge for fixed-sized widgets so it is not so confusing 3337 if (toGrab instanceof WidgetCorner) { 3338 WidgetCorner wc = (WidgetCorner) toGrab; 3339 if (wc.getWidgetSource().isFixedSize()) { 3340 for (Item i : toGrab.getConnected()) { 3341 if (i instanceof WidgetEdge) { 3342 toGrab = i; 3343 break; 3344 } 3345 } 3346 } 3347 } 3348 pickup(toGrab.getConnected()); 3349 } 3350 3351 public static void pickup(Collection<Item> toGrab) { 3352 if (toGrab == null || toGrab.size() == 0) 3353 return; 3354 3355 boolean bReparse = false; 3356 boolean bRecalculate = false; 3357 3358 Frame currentFrame = DisplayIO.getCurrentFrame(); 3359 String currentFrameName = currentFrame.getName(); 3360 Iterator<Item> iter = toGrab.iterator(); 3361 while (iter.hasNext()) { 3362 Item i = iter.next(); 3363 if (!i.hasPermission(UserAppliedPermission.full)) { 3364 iter.remove(); 3365 continue; 3366 } 3367 if (i.equals(_lastHighlightedItem)) 3368 _lastHighlightedItem = null; 3369 3370 bRecalculate |= i.recalculateWhenChanged(); 3371 // i.setSelectedMode(SelectedMode.None); 3372 // Check if it has a relative link if so make it absolute 3373 i.setAbsoluteLink(); 3374 // parent may be null 3375 if (i.getParent() != null) { 3376 i.getParent().removeItem(i); 3377 if (currentFrameName.equals(i.getParent().getName())) 3378 i.setParent(null); 3379 } 3380 FreeItems.getInstance().add(i); 3381 i.setFloating(true); 3382 // If its a vector pick up a copy of the stuff on the vector frame 3383 if (i.hasVector()) { 3384 bReparse = true; 3385 3386 Frame overlayFrame = FrameIO.LoadFrame(i.getAbsoluteLink()); 3387 Collection<Item> copies = ItemUtils.CopyItems(overlayFrame 3388 .getNonAnnotationItems(false), i.getVector()); 3389 for (Item copy : copies) { 3390 FreeItems.getInstance().add(copy); 3391 copy.setEditTarget(i); 3392 copy.setFloating(true); 3393 copy.setParent(null); 3394 // copy.setHighlightMode(HighlightMode.Connected); 3395 } 3396 } 3397 } 3398 currentFrame.change(); 3399 3400 _lastHighlightedItem = null; 3401 updateCursor(); 3402 3403 // if there are multiple items in the list, determine which to use for 3404 // offset calculations 3405 if (toGrab.size() > 1) { 3406 for (Item i : toGrab) { 3407 // MIKE: Movement goes haywire if these are removed because Line 3408 // class returns 0 for getX 3409 if (!(i instanceof Line) && !(i instanceof XRayable)) { 3410 _offX = DisplayIO.getMouseX() - i.getX() + i.getOffset().x; 3411 _offY = getY() - i.getY() + i.getOffset().y; 3412 3413 // make the offset item the first item in the list (so 3414 // move method knows which item to use) 3415 FreeItems.getInstance().set( 3416 FreeItems.getInstance().indexOf(i), 3417 FreeItems.getInstance().get(0)); 3418 FreeItems.getInstance().set(0, i); 3419 break; 3420 } 3421 } 3422 3423 move(FreeItems.getInstance()); 3424 ItemUtils.EnclosedCheck(toGrab); 3425 // otherwise, just use the first item 3426 } else if (toGrab.size() == 1) { 3427 Item soleItem = toGrab.iterator().next(); 3428 _offX = DisplayIO.getMouseX() - soleItem.getX() 3429 + soleItem.getOffset().x; 3430 _offY = getY() - soleItem.getY() + soleItem.getOffset().y; 3431 // Now call move so that if we are on a message in the message box 3432 // It doesnt appear up the top of the scree!! 3433 move(toGrab); 3434 } else { 3435 MessageBay 3436 .displayMessage("Insufficient permission to pickup the items"); 3437 } 3438 if (bReparse) 3439 FrameUtils.Parse(currentFrame, false, false); 3440 else 3441 currentFrame.notifyObservers(bRecalculate); 3442 3443 FrameGraphics.Repaint(); 3444 } 3445 3446 private static Line createLine() { 3447 Frame current = DisplayIO.getCurrentFrame(); 3448 // create the two endpoints 3449 Item end = DisplayIO.getCurrentFrame().createDot(); 3450 Item start = DisplayIO.getCurrentFrame().createDot(); 3451 3452 // create the Line 3453 Line line = new Line(start, end, current.getNextItemID()); 3454 line.autoArrowheadLength(); 3455 3456 // anchor the start 3457 anchor(start); 3458 3459 // attach the line to the cursor 3460 pickup(end); 3461 _lastHighlightedItem = null; 3462 3463 // TODO figure out how to get the end to highlight 3464 // end.setSelectedMode(SelectedMode.Normal); 3465 // end.setSelectedMode(SelectedMode.None); 3466 3467 return line; 3468 } 3469 3470 /** 3471 * Returns a list of copies of the list passed in 3472 * 3473 * @param toCopy 3474 * The list of items to copy 3475 * @return A List of copied Items 3476 */ 3477 private static List<Item> copy(Collection<Item> toCopy) { 3478 return ItemUtils.CopyItems(toCopy); 3479 } 3480 3481 public static void anchor(Item toAnchor, boolean checkEnclosure) { 3482 // Only anchor items we have full permission over... i.e. don't anchor vector items 3483 if (!toAnchor.hasPermission(UserAppliedPermission.full)) 3484 return; 3485 3486 toAnchor.anchor(); 3487 3488 if (checkEnclosure) { 3489 ItemUtils.EnclosedCheck(toAnchor.getParentOrCurrentFrame() 3490 .getItems()); 3491 FrameGraphics.Repaint(); 3492 } 3493 } 3494 3495 public static void anchor(Item toAnchor) { 3496 anchor(toAnchor, true); 3497 } 3498 3499 public static void anchor(Collection<Item> toAnchor) { 3500 boolean bReparse = false; 3501 boolean bRecalculate = false; 3502 // Need to make sure we check enclosure for overlays etc 3503 Set<Frame> checkEnclosure = new HashSet<Frame>(); 3504 3505 // Create a clone of toAnchor since in the proccess of anchoring items 3506 // they can change the state of the toAnchor collection and thus create 3507 // concurrent modification exceptions. 3508 // This is especially needed for widgets being removed when anchored: 3509 // since they 3510 // currently are composed of 8 items this is vital. In the new revision 3511 // of 3512 // widgets being implemented as a single item this this can be 3513 // depreciated 3514 // however it may be useful for other applications. 3515 Collection<Item> toAnchorCopy = new ArrayList<Item>(toAnchor); 3516 3517 for (Item i : toAnchorCopy) { 3518 if (toAnchor.contains(i)) { // since to anchor could change while 3519 // anchoring 3520 // if (!i.hasVector()) 3521 anchor(i, false); 3522 checkEnclosure.add(i.getParentOrCurrentFrame()); 3523 bReparse |= i.hasOverlay(); 3524 bRecalculate |= i.recalculateWhenChanged(); 3525 } 3526 } 3527 3528 toAnchor.clear(); 3529 // Check enclosure for all the frames of the items that were anchored 3530 for (Frame f : checkEnclosure) { 3531 // ItemUtils.EnclosedCheck(f.getItems()); 3532 ItemUtils.Justify(f); 3533 } 3534 3535 Frame currentFrame = DisplayIO.getCurrentFrame(); 3536 if (bReparse) 3537 FrameUtils.Parse(currentFrame, false, false); 3538 else { 3539 currentFrame.notifyObservers(bRecalculate); 3540 } 3541 FrameGraphics.Repaint(); 3542 } 1853 1854 1855 1856 1857 1858 1859 1860 1861 3543 1862 3544 1863 /* … … 3554 1873 3555 1874 if (FreeItems.getInstance().size() == 2) { 3556 if ((FreeItems.getInstance().get(0).isLineEnd() && FreeItems 3557 .getInstance().get(1) instanceof Line) 3558 || (FreeItems.getInstance().get(1).isLineEnd() && FreeItems 3559 .getInstance().get(0) instanceof Line)) { 3560 1875 if ((FreeItems.getInstance().get(0).isLineEnd() && FreeItems.getInstance().get(1) instanceof Line) || 1876 (FreeItems.getInstance().get(1).isLineEnd() && FreeItems.getInstance().get(0) instanceof Line)) 1877 { 3561 1878 Line line; 3562 1879 if (FreeItems.getInstance().get(0) instanceof Line) … … 3582 1899 } 3583 1900 3584 FrameKeyboardActions.functionKey(rotationType, 1, arg0 3585 .isShiftDown(), arg0.isControlDown()); 1901 FrameKeyboardActions.functionKey(rotationType, 1, arg0.isShiftDown(), arg0.isControlDown()); 3586 1902 3587 1903 } else if (clicks >= MOUSE_WHEEL_THRESHOLD) { … … 3618 1934 */ 3619 1935 public static int getLastMouseButton() { 3620 if (_lastMouseClick == null) 3621 return MouseEvent.NOBUTTON; 1936 if (_lastMouseClick == null) return MouseEvent.NOBUTTON; 3622 1937 3623 1938 return _lastMouseClick.getButton(); … … 3625 1940 3626 1941 public static boolean isDelete(int modifiersEx) { 3627 3628 int onMask = MouseEvent.BUTTON3_DOWN_MASK 3629 | MouseEvent.BUTTON2_DOWN_MASK; 1942 int onMask = MouseEvent.BUTTON3_DOWN_MASK | MouseEvent.BUTTON2_DOWN_MASK; 3630 1943 return (modifiersEx & onMask) == onMask; 3631 1944 } 3632 1945 3633 1946 public static boolean isGetAttributes(int modifiersEx) { 3634 int onMask = MouseEvent.BUTTON3_DOWN_MASK 3635 | MouseEvent.BUTTON1_DOWN_MASK; 1947 int onMask = MouseEvent.BUTTON3_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK; 3636 1948 return (modifiersEx & onMask) == onMask; 3637 1949 } 3638 1950 3639 1951 public static boolean isTwoClickNoOp(int modifiersEx) { 3640 int onMask = MouseEvent.BUTTON2_DOWN_MASK 3641 | MouseEvent.BUTTON1_DOWN_MASK; 1952 int onMask = MouseEvent.BUTTON2_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK; 3642 1953 return (modifiersEx & onMask) == onMask; 3643 1954 } … … 3705 2016 } 3706 2017 3707 public static Item getlastHighlightedItem() {3708 return _lastHighlightedItem;3709 }3710 3711 2018 public static Point getPosition() { 3712 2019 return new Point(getX(), getY()); … … 3722 2029 getInstance().refreshHighlights(); 3723 2030 } 2031 2032 @Override 2033 public void onGesture(Gesture gesture) { 2034 // TODO Auto-generated method stub 2035 2036 } 3724 2037 } -
trunk/src/org/expeditee/gui/FrameUtils.java
r1064 r1102 19 19 package org.expeditee.gui; 20 20 21 import java.awt.Color;22 import java.awt.Point;23 import java.awt.Polygon;24 import java.awt.Rectangle;25 21 import java.io.File; 26 22 import java.io.FileInputStream; … … 44 40 import java.util.zip.ZipEntry; 45 41 42 import org.expeditee.core.Colour; 43 import org.expeditee.core.Point; 44 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 45 import org.expeditee.core.bounds.PolygonBounds; 46 import org.expeditee.gio.EcosystemManager; 47 import org.expeditee.gio.gesture.StandardGestureActions; 46 48 import org.expeditee.items.Circle; 47 49 import org.expeditee.items.Dot; … … 60 62 import org.expeditee.items.XRayable; 61 63 import org.expeditee.items.widgets.ButtonWidget; 62 import org.expeditee.items.widgets. InteractiveWidget;64 import org.expeditee.items.widgets.Widget; 63 65 import org.expeditee.items.widgets.InteractiveWidgetInitialisationFailedException; 64 66 import org.expeditee.items.widgets.InteractiveWidgetNotAvailableException; … … 73 75 public class FrameUtils { 74 76 75 private static final int COLUMN_WIDTH = 50; 76 77 /** 78 * Provides a way to monitor the time elapsed between button-down and the 79 * finished painting. 80 */ 81 public static TimeKeeper ResponseTimer = new TimeKeeper(); 82 83 private static float _ResponseTimeSum = 0; 84 85 private static float _LastResponse = 0; 86 87 private static Text LastEdited = null; 88 89 public static int MINIMUM_INTERITEM_SPACING = -6; 90 91 public static float getResponseTimeTotal() { 92 return _ResponseTimeSum; 93 } 94 95 public static float getLastResponseTime() { 96 return _LastResponse; 97 } 98 99 /** 100 * The list of known start pages framesets which will have prepopulated 101 * links in the home frame. 102 */ 103 public static final String[] startPages = { "exploratorysearch", 104 "webbrowser" }; 105 106 /** 107 * Checks if the given top Item is above the given bottom Item, allowing for 108 * the X coordinates to be off by a certain width... 109 * 110 * @param item1 111 * The Item to check is above the other Item 112 * @param item2 113 * The Item to check is below the top Item 114 * @return True if top is above bottom, False otherwise. 115 */ 116 public static boolean inSameColumn(Item item1, Item item2) { 117 if (!(item1 instanceof Text) || !(item2 instanceof Text)) 118 return false; 119 120 if (item1.getID() < 0 || item2.getID() < 0) 121 return false; 122 123 int minX = item2.getX(); 124 int maxX = item2.getX() + item2.getBoundsWidth(); 125 126 int startX = item1.getX(); 127 int endX = item1.getX() + item1.getBoundsWidth(); 128 129 // Check that the two items left values are close 130 if (Math.abs(item1.getX() - item2.getX()) > COLUMN_WIDTH) 131 return false; 132 133 // Ensure the two items 134 if ((minX >= startX && minX <= endX) 135 || (maxX >= startX && maxX <= endX) 136 || (startX >= minX && startX <= maxX) 137 || (endX >= minX && endX <= maxX)) 138 return true; 139 140 return false; 141 } 142 143 public static boolean sameBulletType(String bullet1, String bullet2) { 144 if (bullet1 == null || bullet2 == null) 145 return false; 146 147 if (bullet1.equals("") || bullet2.equals("")) 148 return false; 149 150 if (Character.isLetter(bullet1.charAt(0)) 151 && Character.isLetter(bullet2.charAt(0))) 152 return true; 153 154 if (Character.isDigit(bullet1.charAt(0)) 155 && Character.isDigit(bullet2.charAt(0))) 156 return true; 157 158 // TODO make this more sofisticated 159 160 return false; 161 } 162 163 private static boolean needsRenumbering(String s) { 164 if (s == null || s.equals("")) 165 return false; 166 if (!Character.isLetterOrDigit(s.charAt(0))) 167 return false; 168 169 s = s.trim(); 170 // if its all letters then we dont want to auto adjust 171 if (s.length() > 2) { 172 for (int i = 0; i < s.length() - 1; i++) { 173 if (!Character.isLetter(s.charAt(i))) 174 return true; 175 } 176 } else 177 return true; 178 179 return false; 180 } 181 182 /** 183 * 184 * @param toAlign 185 * @param moveAll 186 * @param adjust 187 * @return 188 */ 189 public static int Align(List<Text> toAlign, boolean moveAll, int adjust, 190 List<Item> changedItems) { 191 Collections.sort(toAlign); 192 193 /* 194 * Single items dont need alignment But if there are two items we may 195 * still want to format them... ie if they are too close together. 196 */ 197 if (toAlign.size() < 1) 198 return 0; 199 200 // get the first item 201 Text from = toAlign.get(0); 202 if (from.getParent() == null) 203 from = toAlign.get(1); 204 int x = from.getX(); 205 206 Frame curr = from.getParent(); 207 Text above = curr.getTextAbove(from); 208 209 String lastBullet = ""; 210 211 if (above != null && curr.isNormalTextItem(above)) 212 lastBullet = FrameKeyboardActions.getAutoBullet(above.getText()); 213 else { 214 lastBullet = FrameKeyboardActions.getBullet(toAlign.get(0) 215 .getText()); 216 } 217 if (needsRenumbering(lastBullet)) { 218 // renumber... 219 for (int i = 0; i < toAlign.size(); i++) { 220 221 Text currentText = toAlign.get(i); 222 String currentBullet = FrameKeyboardActions 223 .getAutoBullet(currentText.getText()); 224 225 if (sameBulletType(lastBullet, currentBullet)) { 226 String oldText = currentText.getText(); 227 228 currentText.stripFirstWord(); 229 230 currentText.setText(lastBullet + currentText.getText()); 231 lastBullet = FrameKeyboardActions.getAutoBullet(currentText 232 .getText()); 233 234 // if we changed the item, add to changedItems list 235 if (changedItems != null 236 && oldText != currentText.getText() 237 && !changedItems.contains(currentText)) { 238 Item copy = currentText.copy(); 239 copy.setID(currentText.getID()); 240 copy.setText(oldText); 241 changedItems.add(copy); 242 } 243 } 244 } 245 } 246 247 // work out the spacing between the first item and the one above it 248 249 int space = 10 + adjust; 250 251 // if we are dropping from the title make the space a little bigger 252 // than normal 253 254 // If there are only two items get the gap from the start item on the 255 // zero frame if there is one 256 if (above == curr.getTitleItem()) { 257 Frame zero = FrameIO.LoadFrame(curr.getFramesetName() + '0'); 258 String strGap = zero.getAnnotationValue("start"); 259 if (strGap != null) { 77 /** 78 * The list of known start pages framesets which will have prepopulated 79 * links in the home frame. 80 */ 81 public static final String[] startPages = { "exploratorysearch", "webbrowser" }; 82 83 private static final int COLUMN_WIDTH = 50; 84 85 /** 86 * Provides a way to monitor the time elapsed between button-down and the 87 * finished painting. 88 */ 89 public static TimeKeeper ResponseTimer = new TimeKeeper(); 90 91 private static float _ResponseTimeSum = 0; 92 93 private static float _LastResponse = 0; 94 95 private static Text LastEdited = null; 96 97 public static int MINIMUM_INTERITEM_SPACING = -6; 98 99 private static Item _tdfcItem = null; 100 101 public static float getResponseTimeTotal() 102 { 103 return _ResponseTimeSum; 104 } 105 106 public static float getLastResponseTime() 107 { 108 return _LastResponse; 109 } 110 111 /** 112 * Checks if the given top Item is above the given bottom Item, allowing for 113 * the X coordinates to be off by a certain width... 114 * 115 * @param item1 116 * The Item to check is above the other Item 117 * @param item2 118 * The Item to check is below the top Item 119 * @return True if top is above bottom, False otherwise. 120 */ 121 public static boolean inSameColumn(Item item1, Item item2) { 122 if (!(item1 instanceof Text) || !(item2 instanceof Text)) 123 return false; 124 125 if (item1.getID() < 0 || item2.getID() < 0) 126 return false; 127 128 int minX = item2.getX(); 129 int maxX = item2.getX() + item2.getBoundsWidth(); 130 131 int startX = item1.getX(); 132 int endX = item1.getX() + item1.getBoundsWidth(); 133 134 // Check that the two items left values are close 135 if (Math.abs(item1.getX() - item2.getX()) > COLUMN_WIDTH) 136 return false; 137 138 // Ensure the two items 139 if ((minX >= startX && minX <= endX) 140 || (maxX >= startX && maxX <= endX) 141 || (startX >= minX && startX <= maxX) 142 || (endX >= minX && endX <= maxX)) 143 return true; 144 145 return false; 146 } 147 148 public static boolean sameBulletType(String bullet1, String bullet2) 149 { 150 if (bullet1 == null || bullet2 == null) 151 return false; 152 153 if (bullet1.equals("") || bullet2.equals("")) 154 return false; 155 156 if (Character.isLetter(bullet1.charAt(0)) 157 && Character.isLetter(bullet2.charAt(0))) 158 return true; 159 160 if (Character.isDigit(bullet1.charAt(0)) 161 && Character.isDigit(bullet2.charAt(0))) 162 return true; 163 164 // TODO make this more sofisticated 165 166 return false; 167 } 168 169 private static boolean needsRenumbering(String s) { 170 if (s == null || s.equals("")) 171 return false; 172 if (!Character.isLetterOrDigit(s.charAt(0))) 173 return false; 174 175 s = s.trim(); 176 // if its all letters then we dont want to auto adjust 177 if (s.length() > 2) { 178 for (int i = 0; i < s.length() - 1; i++) { 179 if (!Character.isLetter(s.charAt(i))) 180 return true; 181 } 182 } else 183 return true; 184 185 return false; 186 } 187 188 /** 189 * 190 * @param toAlign 191 * @param moveAll 192 * @param adjust 193 * @return 194 */ 195 public static int Align(List<Text> toAlign, boolean moveAll, int adjust, 196 List<Item> changedItems) { 197 Collections.sort(toAlign); 198 199 /* 200 * Single items dont need alignment But if there are two items we may 201 * still want to format them... ie if they are too close together. 202 */ 203 if (toAlign.size() < 1) 204 return 0; 205 206 // get the first item 207 Text from = toAlign.get(0); 208 if (from.getParent() == null) 209 from = toAlign.get(1); 210 int x = from.getX(); 211 212 Frame curr = from.getParent(); 213 Text above = curr.getTextAbove(from); 214 215 String lastBullet = ""; 216 217 if (above != null && curr.isNormalTextItem(above)) 218 lastBullet = StandardGestureActions.getAutoBullet(above.getText()); 219 else { 220 lastBullet = StandardGestureActions.getBullet(toAlign.get(0) 221 .getText()); 222 } 223 if (needsRenumbering(lastBullet)) { 224 // renumber... 225 for (int i = 0; i < toAlign.size(); i++) { 226 227 Text currentText = toAlign.get(i); 228 String currentBullet = StandardGestureActions.getAutoBullet(currentText.getText()); 229 230 if (sameBulletType(lastBullet, currentBullet)) { 231 String oldText = currentText.getText(); 232 233 currentText.stripFirstWord(); 234 235 currentText.setText(lastBullet + currentText.getText()); 236 lastBullet = StandardGestureActions.getAutoBullet(currentText.getText()); 237 238 // if we changed the item, add to changedItems list 239 if (changedItems != null 240 && oldText != currentText.getText() 241 && !changedItems.contains(currentText)) { 242 Item copy = currentText.copy(); 243 copy.setID(currentText.getID()); 244 copy.setText(oldText); 245 changedItems.add(copy); 246 } 247 } 248 } 249 } 250 251 // work out the spacing between the first item and the one above it 252 253 int space = 10 + adjust; 254 255 // if we are dropping from the title make the space a little bigger 256 // than normal 257 258 // If there are only two items get the gap from the start item on the 259 // zero frame if there is one 260 if (above == curr.getTitleItem()) { 261 Frame zero = FrameIO.LoadFrame(curr.getFramesetName() + '0'); 262 String strGap = zero.getAnnotationValue("start"); 263 if (strGap != null) { 264 try { 265 int gap = Integer.parseInt(strGap); 266 space = gap; 267 } catch (NumberFormatException nfe) { 268 269 } 270 } 271 } else if (above != null) { 272 // Make the gap between all items the same as the gap between 273 // the first two 274 space = (int) (from.getBounds().getMinY() - above.getBounds().getMaxY()); 275 276 if (space < MINIMUM_INTERITEM_SPACING) 277 space = MINIMUM_INTERITEM_SPACING; 278 279 if (UserSettings.FormatSpacingMax.get() != null) { 280 double maxSpace = UserSettings.FormatSpacingMax.get() 281 * above.getSize(); 282 if (maxSpace < space) { 283 space = (int) Math.round(maxSpace); 284 } 285 } 286 287 if (UserSettings.FormatSpacingMin.get() != null) { 288 double minSpace = UserSettings.FormatSpacingMin.get() 289 * above.getSize(); 290 if (minSpace > space) { 291 space = (int) Math.round(minSpace); 292 } 293 } 294 295 // Need to do things differently for FORMAT than for DROPPING 296 if (moveAll && above != curr.getNameItem() 297 && above != curr.getTitleItem()) { 298 x = above.getX(); 299 int y = (int) above.getBounds().getMaxY() 300 + space 301 + ((int) (from.getY() - from.getBounds().getMinY())); 302 303 if (changedItems != null 304 && (from.getX() != x || from.getY() != y) 305 && !changedItems.contains(from)) { 306 Item copy = from.copy(); 307 copy.setID(from.getID()); 308 changedItems.add(copy); 309 } 310 from.setPosition(x, y); 311 } else { 312 x = from.getX(); 313 } 314 315 space += adjust; 316 } 317 for (int i = 1; i < toAlign.size(); i++) { 318 Item current = toAlign.get(i); 319 Item top = toAlign.get(i - 1); 320 321 // The bottom of the previous item 322 int bottom = (int) top.getBounds().getMaxY(); 323 324 // the difference between the current item's Y coordinate and 325 // the top of the highlight box 326 int diff = (int) (current.getY() - current.getBounds().getMinY()); 327 328 int newPos = bottom + space + diff; 329 330 if (changedItems != null 331 && ((moveAll && current.getX() != x) || current.getY() != newPos) 332 && !changedItems.contains(current)) { 333 Item copy = current.copy(); 334 copy.setID(current.getID()); 335 changedItems.add(copy); 336 } 337 338 if (moveAll) { 339 current.setPosition(x, newPos); 340 } else if (newPos > current.getY()) { 341 current.setY(newPos); 342 } 343 344 } 345 346 // if (insert != null) 347 // return insert.getY(); 348 349 // Michael thinks we return the y value for the next new item?? 350 int y = from.getY() + from.getBoundsHeight() + space; 351 return y; 352 } 353 354 public static int Align(List<Text> toAlign, boolean moveAll, int adjust) { 355 return Align(toAlign, moveAll, adjust, null); 356 } 357 358 public static boolean LeavingFrame(Frame current) { 359 checkTDFCItemWaiting(current); 360 // active overlay frames may also require saving if they have been 361 // changed 362 for (Overlay o : current.getOverlays()) 363 if (!SaveCheck(o.Frame)) 364 return false; 365 366 // if the check fails there is no point continuing 367 if (!SaveCheck(current)) 368 return false; 369 370 for (Item i : current.getItems()) { 371 i.setHighlightMode(Item.HighlightMode.None); 372 i.setHighlightColorToDefault(); 373 } 374 return true; 375 } 376 377 private static boolean SaveCheck(Frame toSave) { 378 // don't bother saving frames that haven't changed 379 if (!toSave.hasChanged()) 380 return true; 381 382 // if the frame has been changed, then save it 383 if (DisplayController.isTwinFramesOn()) { 384 Frame opposite = DisplayController.getOppositeFrame(); 385 386 String side = "left"; 387 if (DisplayController.getCurrentSide() == DisplayController.TwinFramesSide.RIGHT) 388 side = "right"; 389 390 // if the two frames both have changes, prompt the user for the 391 // next move 392 if (opposite.hasChanged() && opposite.equals(toSave)) { 393 if (EcosystemManager.getGraphicsManager().showDialog("Changes", "Leaving this frame will discard changes made in the " + side + " Frame. Continue?")) { 394 FrameIO.SaveFrame(toSave); 395 DisplayController.Reload(DisplayController.getSideFrameIsOn(opposite)); 396 return true; 397 } else 398 return false; 399 } else if (opposite.hasOverlay(toSave)) { 400 if (toSave.hasChanged()) 401 if (EcosystemManager.getGraphicsManager().showDialog("Changes", "Leaving this frame will discard changes made in the " + side + " Frame. Continue?")) { 402 FrameIO.SaveFrame(toSave); 403 DisplayController.Reload(DisplayController.getSideFrameIsOn(opposite)); 404 return true; 405 } else 406 return false; 407 } 408 409 // save the current frame and restore the other side 410 FrameIO.SaveFrame(toSave); 411 return true; 412 } 413 414 // single-frame mode can just save and return 415 FrameIO.SaveFrame(toSave); 416 return true; 417 } 418 419 // TODO: consider reloating this method to Frame class? 420 protected static Item getAnnotation(Frame frame, String annotationStr) 421 { 422 Item matched_item = null; 423 424 // check for an updated template... 425 for (Item i : frame.getAnnotationItems()) { 426 427 if (ItemUtils.startsWithTag(i, annotationStr)) { 428 429 matched_item = i; 430 break; 431 } 432 } 433 434 return matched_item; 435 } 436 437 protected static void doFrameTransition(Item frameTransition, Frame from, Frame to) 438 { 439 String s = frameTransition.getText(); 440 String[] s_array = s.split(":"); 441 if(s_array.length > 1){ 442 String slide_mode_method = s_array[1].trim(); 443 444 FrameTransition transition = new FrameTransition(from.getBuffer(), slide_mode_method); 445 446 DisplayController.setTransition(from, transition); 447 448 System.out.println("Triggered on annotation: " + s); 449 } else { 450 System.err.println("Warning: failed to detect frameTransition type"); 451 // TODO: print list as a result of reflection listing 452 } 453 } 454 455 /** 456 * Displays the given Frame on the display. If the current frame has changed 457 * since the last save then it will be saved before the switch is made. The 458 * caller can also dictate whether the current frame is added to the 459 * back-stack or not. 460 * 461 * @param toDisplay 462 * The Frame to display on the screen 463 * @param addToBack 464 * True if the current Frame should be added to the back-stack, 465 * False otherwise 466 */ 467 public static void DisplayFrame(Frame toDisplay, boolean addToBack, boolean incrementStats) 468 { 469 if (toDisplay == null) 470 return; 471 472 Frame current = DisplayController.getCurrentFrame(); 473 474 // Dont need to do anything if the frame to display is already being 475 // displayed 476 if (current.equals(toDisplay)) 477 return; 478 479 // move any anchored connected items 480 if (FreeItems.hasItemsAttachedToCursor()) { 481 List<Item> toAdd = new ArrayList<Item>(); 482 List<Item> toCheck = new ArrayList<Item>(FreeItems.getInstance()); 483 484 while (toCheck.size() > 0) { 485 Item i = toCheck.get(0); 486 Collection<Item> connected = i.getAllConnected(); 487 488 // // Only move completely enclosed items 489 // if (!toCheck.containsAll(connected)) { 490 // connected.retainAll(FreeItems.getInstance()); 491 // FreeItems.getInstance().removeAll(connected); 492 // toCheck.removeAll(connected); 493 // FrameMouseActions.anchor(connected); 494 // } else { 495 // toCheck.removeAll(connected); 496 // } 497 498 // Anchor overlay items where they belong 499 if (i.getParent() != null && i.getParent() != current) { 500 FreeItems.getInstance().removeAll(connected); 501 toCheck.removeAll(connected); 502 StandardGestureActions.anchor(connected); 503 } else { 504 // Add stuff that is partially enclosed 505 // remove all the connected items from our list to check 506 toCheck.removeAll(connected); 507 // Dont add the items that are free 508 connected.removeAll(FreeItems.getInstance()); 509 toAdd.addAll(connected); 510 } 511 } 512 513 current.removeAllItems(toAdd); 514 515 boolean oldChange = toDisplay.hasChanged(); 516 toDisplay.updateIDs(toAdd); 517 toDisplay.addAllItems(toAdd); 518 toDisplay.setChanged(oldChange); 519 } 520 521 if (addToBack && current != toDisplay) { 522 FrameIO.checkTDFC(current); 523 } 524 525 // if the saving happened properly, we can continue 526 if (!LeavingFrame(current)) { 527 MessageBay.displayMessage("Navigation cancelled"); 528 return; 529 } 530 531 if (addToBack && current != toDisplay) { 532 DisplayController.addToBack(current); 533 } 534 535 Parse(toDisplay); 536 537 if (DisplayController.isAudienceMode()) { 538 // Only need to worry about frame transitions when in Audience Mode 539 540 // Test to see if frame transition specified through annotation, and perform it if one if found 541 Item frameTransition = getAnnotation(toDisplay, "@frameTransition"); 542 if (frameTransition != null) { 543 doFrameTransition(frameTransition,current,toDisplay); 544 } 545 } 546 547 DisplayController.setCurrentFrame(toDisplay, incrementStats); 548 StandardGestureActions.updateCursor(); 549 // FrameMouseActions.getInstance().refreshHighlights(); 550 // update response timer 551 _LastResponse = ResponseTimer.getElapsedSeconds(); 552 _ResponseTimeSum += _LastResponse; 553 DisplayController.updateTitle(); 554 } 555 556 /** 557 * Loads and displays the Frame with the given framename, and adds the 558 * current frame to the back-stack if required. 559 * 560 * @param framename 561 * The name of the Frame to load and display 562 * @param addToBack 563 * True if the current Frame should be added to the back-stack, 564 * false otherwise 565 */ 566 public static void DisplayFrame(String frameName, boolean addToBack, 567 boolean incrementStats) { 568 Frame newFrame = getFrame(frameName); 569 570 if (newFrame != null) 571 // display the frame 572 DisplayFrame(newFrame, addToBack, incrementStats); 573 } 574 575 /** 576 * Loads and displays the Frame with the given framename and adds the 577 * current frame to the back-stack. This is the same as calling 578 * DisplayFrame(framename, true) 579 * 580 * @param framename 581 * The name of the Frame to load and display 582 */ 583 public static void DisplayFrame(String framename) { 584 DisplayFrame(framename, true, true); 585 } 586 587 public static Frame getFrame(String frameName) { 588 // if the new frame does not exist then tell the user 589 Frame f = FrameIO.LoadFrame(frameName); 590 591 if (f == null) { 592 MessageBay.errorMessage("Frame '" + frameName + "' could not be found."); 593 } 594 595 return f; 596 } 597 598 /** 599 * Creates a new Picture Item from the given Text source Item and adds it to 600 * the given Frame. 601 * 602 * @return True if the image was created successfully, false otherwise 603 */ 604 private static boolean createPicture(Frame frame, Text txt) { 605 // attempt to create the picture 606 Picture pic = ItemUtils.CreatePicture(txt); 607 608 // if the picture could not be created successfully 609 if (pic == null) { 610 String imagePath = txt.getText(); 611 assert (imagePath != null); 612 imagePath = new AttributeValuePair(imagePath).getValue().trim(); 613 if (imagePath.length() == 0) { 614 return false; 615 // MessageBay.errorMessage("Expected image path after @i:"); 616 } else { 617 MessageBay.errorMessage("Image " + imagePath 618 + " could not be loaded"); 619 } 620 return false; 621 } 622 frame.addItem(pic); 623 624 return true; 625 } 626 627 /** 628 * Creates an interactive widget and adds it to a frame. If txt has no 629 * parent the parent will be set to frame. 630 * 631 * @param frame 632 * Frame to add widget to. Must not be null. 633 * 634 * @param txt 635 * Text to create the widget from. Must not be null. 636 * 637 * @return True if created/added. False if could not create. 638 * 639 * @author Brook Novak 640 */ 641 private static boolean createWidget(Frame frame, Text txt) { 642 643 if (frame == null) 644 throw new NullPointerException("frame"); 645 if (txt == null) 646 throw new NullPointerException("txt"); 647 648 // Safety 649 if (txt.getParent() == null) 650 txt.setParent(frame); 651 652 Widget iw = null; 653 260 654 try { 261 int gap = Integer.parseInt(strGap); 262 space = gap; 263 } catch (NumberFormatException nfe) { 264 265 } 266 } 267 } else if (above != null) { 268 // Make the gap between all items the same as the gap between 269 // the first two 270 space = (int) (from.getPolygon().getBounds().getMinY() - above 271 .getPolygon().getBounds().getMaxY()); 272 273 if (space < MINIMUM_INTERITEM_SPACING) 274 space = MINIMUM_INTERITEM_SPACING; 275 276 if (UserSettings.FormatSpacingMax.get() != null) { 277 double maxSpace = UserSettings.FormatSpacingMax.get() 278 * above.getSize(); 279 if (maxSpace < space) { 280 space = (int) Math.round(maxSpace); 281 } 282 } 283 284 if (UserSettings.FormatSpacingMin.get() != null) { 285 double minSpace = UserSettings.FormatSpacingMin.get() 286 * above.getSize(); 287 if (minSpace > space) { 288 space = (int) Math.round(minSpace); 289 } 290 } 291 292 // Need to do things differently for FORMAT than for DROPPING 293 if (moveAll && above != curr.getNameItem() 294 && above != curr.getTitleItem()) { 295 x = above.getX(); 296 int y = (int) above.getPolygon().getBounds().getMaxY() 297 + space 298 + ((int) (from.getY() - from.getPolygon().getBounds() 299 .getMinY())); 300 301 if (changedItems != null 302 && (from.getX() != x || from.getY() != y) 303 && !changedItems.contains(from)) { 304 Item copy = from.copy(); 305 copy.setID(from.getID()); 306 changedItems.add(copy); 307 } 308 from.setPosition(x, y); 309 } else { 310 x = from.getX(); 311 } 312 313 space += adjust; 314 } 315 for (int i = 1; i < toAlign.size(); i++) { 316 Item current = toAlign.get(i); 317 Item top = toAlign.get(i - 1); 318 319 // The bottom of the previous item 320 int bottom = (int) top.getPolygon().getBounds().getMaxY(); 321 322 // the difference between the current item's Y coordinate and 323 // the top of the highlight box 324 int diff = (int) (current.getY() - current.getPolygon().getBounds() 325 .getMinY()); 326 327 int newPos = bottom + space + diff; 328 329 if (changedItems != null 330 && ((moveAll && current.getX() != x) || current.getY() != newPos) 331 && !changedItems.contains(current)) { 332 Item copy = current.copy(); 333 copy.setID(current.getID()); 334 changedItems.add(copy); 335 } 336 337 if (moveAll) { 338 current.setPosition(x, newPos); 339 } else if (newPos > current.getY()) { 340 current.setY(newPos); 341 } 342 343 } 344 345 // if (insert != null) 346 // return insert.getY(); 347 348 // Michael thinks we return the y value for the next new item?? 349 int y = from.getY() + from.getBoundsHeight() + space; 350 return y; 351 } 352 353 public static int Align(List<Text> toAlign, boolean moveAll, int adjust) { 354 return Align(toAlign, moveAll, adjust, null); 355 } 356 357 public static boolean LeavingFrame(Frame current) { 358 checkTDFCItemWaiting(current); 359 // active overlay frames may also require saving if they have been 360 // changed 361 for (Overlay o : current.getOverlays()) 362 if (!SaveCheck(o.Frame)) 363 return false; 364 365 // if the check fails there is no point continuing 366 if (!SaveCheck(current)) 367 return false; 368 369 for (Item i : current.getItems()) 370 i.setHighlightMode(Item.HighlightMode.None); 371 return true; 372 } 373 374 private static boolean SaveCheck(Frame toSave) { 375 // don't bother saving frames that haven't changed 376 if (!toSave.hasChanged()) 377 return true; 378 379 // if the frame has been changed, then save it 380 if (DisplayIO.isTwinFramesOn()) { 381 Frame opposite = DisplayIO.getOppositeFrame(); 382 383 String side = "left"; 384 if (DisplayIO.getCurrentSide() == 0) 385 side = "right"; 386 387 // if the two frames both have changes, prompt the user for the 388 // next move 389 if (opposite.hasChanged() && opposite.equals(toSave)) { 390 if (DisplayIO.DisplayConfirmDialog( 391 "Leaving this frame will discard changes made in the " 392 + side + " Frame. Continue?", "Changes", 393 DisplayIO.TYPE_WARNING, DisplayIO.OPTIONS_OK_CANCEL, 394 DisplayIO.RESULT_OK)) { 395 FrameIO.SaveFrame(toSave); 396 DisplayIO.Reload(DisplayIO.FrameOnSide(opposite)); 397 return true; 398 } else 399 return false; 400 } else if (opposite.hasOverlay(toSave)) { 401 if (toSave.hasChanged()) 402 if (DisplayIO.DisplayConfirmDialog( 403 "Leaving this frame will discard changes made in the " 404 + side + " Frame. Continue?", "Changes", 405 DisplayIO.TYPE_WARNING, 406 DisplayIO.OPTIONS_OK_CANCEL, DisplayIO.RESULT_OK)) { 407 FrameIO.SaveFrame(toSave); 408 DisplayIO.Reload(DisplayIO.FrameOnSide(opposite)); 409 return true; 410 } else 655 656 iw = Widget.createWidget(txt); 657 658 } catch (InteractiveWidgetNotAvailableException e) { 659 e.printStackTrace(); 660 MessageBay.errorMessage("Cannot create iWidget: " + e.getMessage()); 661 } catch (InteractiveWidgetInitialisationFailedException e) { 662 e.printStackTrace(); 663 MessageBay.errorMessage("Cannot create iWidget: " + e.getMessage()); 664 } catch (IllegalArgumentException e) { 665 e.printStackTrace(); 666 MessageBay.errorMessage("Cannot create iWidget: " + e.getMessage()); 667 } 668 669 if (iw == null) 411 670 return false; 412 } 413 414 // save the current frame and restore the other side 415 FrameIO.SaveFrame(toSave); 416 return true; 417 } 418 419 // single-frame mode can just save and return 420 FrameIO.SaveFrame(toSave); 421 return true; 422 } 423 424 // TODO: consider reloating this method to Frame class? 425 protected static Item getAnnotation(Frame frame, String annotationStr) 426 { 427 Item matched_item = null; 671 672 frame.removeItem(txt); 673 674 frame.addAllItems(iw.getItems()); 675 676 return true; 677 } 678 679 public static List<String> ParseProfile(Frame profile) 680 { 681 List<String> errors = new LinkedList<String>(); 682 683 if (profile == null) return errors; 684 685 /* 686 * Make sure the correct cursor shows when turning off the custom cursor 687 * and reparsing the profile frame 688 */ 689 FreeItems.getCursor().clear(); 690 DisplayController.setCursor(Item.HIDDEN_CURSOR); 691 DisplayController.setCursor(Item.DEFAULT_CURSOR); 692 693 // check for settings tags 694 for (Text item : profile.getBodyTextItems(true)) { 695 try { 696 697 AttributeValuePair avp = new AttributeValuePair(item.getText()); 698 String attributeFullCase = avp.getAttributeOrValue(); 699 700 if (attributeFullCase == null) continue; 701 702 String attribute = attributeFullCase.trim().toLowerCase().replaceAll("^@", ""); 703 704 if (attribute.equals("settings")) Settings.parseSettings(item); 705 706 } catch (Exception e) { 707 if (e.getMessage() != null) { 708 errors.add(e.getMessage()); 709 } else { 710 e.printStackTrace(); 711 errors.add("Error parsing [" + item.getText() + "] on " + profile.getName()); 712 } 713 } 714 } 715 716 return errors; 717 } 718 719 /** 720 * Sets the first frame to be displayed. 721 * 722 * @param profile 723 */ 724 public static void loadFirstFrame(Frame profile) 725 { 726 if (UserSettings.HomeFrame.get() == null) UserSettings.HomeFrame.set(profile.getName()); 727 728 Frame firstFrame = FrameIO.LoadFrame(UserSettings.HomeFrame.get()); 729 if (firstFrame == null) { 730 MessageBay.warningMessage("Home frame not found: " + UserSettings.HomeFrame); 731 UserSettings.HomeFrame.set(profile.getName()); 732 DisplayController.setCurrentFrame(profile, true); 733 } else { 734 DisplayController.setCurrentFrame(firstFrame, true); 735 } 736 737 } 738 739 public static Colour[] getColorWheel(Frame frame) 740 { 741 if (frame != null) { 742 List<Text> textItems = frame.getBodyTextItems(false); 743 Colour[] colorList = new Colour[textItems.size() + 1]; 744 for (int i = 0; i < textItems.size(); i++) { 745 colorList[i] = textItems.get(i).getColor(); 746 } 747 // Make the last item transparency or default for forecolor 748 colorList[colorList.length - 1] = null; 749 750 return colorList; 751 } 752 return new Colour[] { Colour.BLACK, Colour.WHITE, null }; 753 } 754 755 public static String getLink(Item item, String alt) 756 { 757 if (item == null || !(item instanceof Text)) return alt; 758 759 AttributeValuePair avp = new AttributeValuePair(item.getText()); 760 assert (avp != null); 761 762 if (avp.hasPair() && avp.getValue().trim().length() != 0) { 763 item.setLink(avp.getValue()); 764 return avp.getValue(); 765 } else if (item.getLink() != null) { 766 return item.getAbsoluteLink(); 767 } 768 769 return alt; 770 } 771 772 public static String getDir(String name) 773 { 774 if (name != null) { 775 File tester = new File(name); 776 if (tester.exists() && tester.isDirectory()) { 777 if (name.endsWith(File.separator)) { 778 return name; 779 } else { 780 return name + File.separator; 781 } 782 } else { 783 throw new RuntimeException("Directory not found: " + name); 784 } 785 } 786 throw new RuntimeException("Missing value for profile attribute" + name); 787 } 788 789 public static ArrayList<String> getDirs(Item item) 790 { 791 ArrayList<String> dirsToAdd = new ArrayList<String>(); 792 String dirListFrameName = item.getAbsoluteLink(); 793 if (dirListFrameName != null) { 794 Frame dirListFrame = FrameIO.LoadFrame(dirListFrameName); 795 if (dirListFrame != null) { 796 for (Text t : dirListFrame.getBodyTextItems(false)) { 797 String dirName = t.getText().trim(); 798 File tester = new File(dirName); 799 if (tester.exists() && tester.isDirectory()) { 800 if (dirName.endsWith(File.separator)) 801 dirsToAdd.add(dirName); 802 else 803 dirsToAdd.add(dirName + File.separator); 804 } 805 } 806 } 807 } 808 809 return dirsToAdd; 810 } 811 812 public static void Parse(Frame toParse) 813 { 814 Parse(toParse, false); 815 } 816 817 /** 818 * Checks for any special Annotation items and updates the display as 819 * necessary. Special Items: Images, overlays, sort. 820 * 821 */ 822 public static void Parse(Frame toParse, boolean firstParse) 823 { 824 Parse(toParse, firstParse, false); 825 } 826 827 /** 828 * 829 * @param toParse 830 * @param firstParse 831 * @param ignoreAnnotations 832 * used to prevent infinate loops such as when performing TDFC 833 * with an ao tag linked to a frame with an frameImage of a frame 834 * which also has an ao tag on it. 835 */ 836 public static void Parse(Frame toParse, boolean firstParse, boolean ignoreAnnotations) 837 { 838 // TODO check why we are getting toParse == null... when profile frame 839 // is being created and change the lines below 840 if (toParse == null) return; 841 842 if (firstParse) ItemUtils.EnclosedCheck(toParse.getItems()); 843 844 List<Item> items = toParse.getItems(); 845 846 // if XRayMode is on, replace pictures with their underlying text 847 if (DisplayController.isXRayMode()) { 848 849 // BROOK: Must handle these a little different 850 List<Widget> widgets = toParse.getInteractiveWidgets(); 851 852 for (Item i : items) { 853 if (i instanceof XRayable) { 854 toParse.removeItem(i); 855 // Show the items 856 for (Item item : ((XRayable) i).getConnected()) { 857 item.setVisible(true); 858 item.removeEnclosure(i); 859 } 860 } else if (i instanceof WidgetCorner) { 861 toParse.removeItem(i); 862 } else if (i instanceof WidgetEdge) { 863 toParse.removeItem(i); 864 } else if (i.hasFormula()) { 865 i.setText(i.getFormula()); 866 } else if (i.hasOverlay()) { 867 i.setVisible(true); 868 // int x = i.getBoundsHeight(); 869 } 870 } 871 872 for (Widget iw : widgets) { 873 toParse.addItem(iw.getSource()); 874 } 875 } 876 877 // Text title = null; 878 // Text template = UserSettingsTemplate.copy(); 879 880 List<Overlay> overlays = new ArrayList<Overlay>(); 881 List<Vector> vectors = new ArrayList<Vector>(); 882 883 // disable reading of cached overlays if in twinframes mode 884 if (DisplayController.isTwinFramesOn()) FrameIO.SuspendCache(); 885 886 DotType pointtype = DotType.square; 887 boolean filledPoints = true; 888 889 UserAppliedPermission permission = toParse.getUserAppliedPermission(); 890 toParse.clearAnnotations(); 891 892 // check for any new overlay items 893 for (Item i : toParse.getItems()) { 894 try { 895 // reset overlay permission 896 i.setOverlayPermission(null); 897 // i.setPermission(permission); 898 if (i instanceof WidgetCorner) { 899 // TODO improve efficiency so it only updates once... using 900 // observer design pattern 901 i.update(); 902 } else if (i instanceof Text) { 903 if (i.isAnnotation()) { 904 if (ItemUtils.startsWithTag(i, ItemUtils.TAG_POINTTYPE)) { 905 Text txt = (Text) i; 906 String line = txt.getFirstLine(); 907 line = ItemUtils.StripTag(line, 908 ItemUtils.GetTag(ItemUtils.TAG_POINTTYPE)); 909 910 if (line != null) { 911 line = line.toLowerCase(); 912 if (line.indexOf(" ") > 0) { 913 String fill = line.substring(line 914 .indexOf(" ") + 1); 915 if (fill.startsWith("nofill")) 916 filledPoints = false; 917 else 918 filledPoints = true; 919 } 920 921 if (line.startsWith("circle")) 922 pointtype = DotType.circle; 923 else 924 pointtype = DotType.square; 925 } 926 }// check for new VECTOR items 927 else if (!DisplayController.isXRayMode() 928 && ItemUtils.startsWithTag(i, 929 ItemUtils.TAG_VECTOR) 930 && i.getLink() != null) { 931 if (!i.getAbsoluteLink().equals(toParse.getName())) 932 addVector(vectors, UserAppliedPermission.none, 933 permission, i); 934 } else if (!DisplayController.isXRayMode() 935 && ItemUtils.startsWithTag(i, 936 ItemUtils.TAG_ACTIVE_VECTOR) 937 && i.getLink() != null) { 938 if (!i.getAbsoluteLink().equals(toParse.getName())) 939 addVector(vectors, 940 UserAppliedPermission.followLinks, 941 permission, i); 942 } 943 // check for new OVERLAY items 944 else if (!ignoreAnnotations && ItemUtils.startsWithTag(i, ItemUtils.TAG_OVERLAY) && i.getLink() != null) { 945 if (i.getAbsoluteLink().equalsIgnoreCase(toParse.getName())) { 946 // This frame contains an active overlay which 947 // points to itself 948 MessageBay.errorMessage(toParse.getName() + " contains an @o which links to itself"); 949 continue; 950 } 951 952 Frame overlayFrame = FrameIO.LoadFrame(i.getAbsoluteLink()); 953 // Parse(overlay); 954 if (overlayFrame != null && Overlay.getOverlay(overlays, overlayFrame) == null) { 955 overlays.add(new Overlay(overlayFrame, UserAppliedPermission.none)); 956 } 957 } 958 // check for ACTIVE_OVERLAY items 959 else if (!ignoreAnnotations 960 && ItemUtils.startsWithTag(i, 961 ItemUtils.TAG_ACTIVE_OVERLAY) 962 && i.getLink() != null) { 963 String link = i.getAbsoluteLink(); 964 if (link.equalsIgnoreCase(toParse.getName())) { 965 // This frame contains an active overlay which 966 // points to itself 967 MessageBay 968 .errorMessage(toParse.getName() 969 + " contains an @ao which links to itself"); 970 continue; 971 } 972 Frame overlayFrame = null; 973 974 Frame current = DisplayController.getCurrentFrame(); 975 if (current != null) { 976 for (Overlay o : current.getOverlays()) { 977 if (o.Frame.getName() 978 .equalsIgnoreCase(link)) 979 overlayFrame = o.Frame; 980 } 981 } 982 if (overlayFrame == null) 983 overlayFrame = FrameIO.LoadFrame(link); 984 985 // get level if specified 986 String level = new AttributeValuePair(i.getText()) 987 .getValue(); 988 // default permission (if none is specified) 989 PermissionPair permissionLevel = new PermissionPair( 990 level, UserAppliedPermission.followLinks); 991 992 if (overlayFrame != null) { 993 Overlay existingOverlay = Overlay.getOverlay( 994 overlays, overlayFrame); 995 // If it wasn't in the list create it and add 996 // it. 997 if (existingOverlay == null) { 998 Overlay newOverlay = new Overlay( 999 overlayFrame, 1000 permissionLevel 1001 .getPermission(overlayFrame 1002 .getOwner())); 1003 i.setOverlay(newOverlay); 1004 overlays.add(newOverlay); 1005 } else { 1006 existingOverlay.Frame 1007 .setPermission(permissionLevel); 1008 } 1009 } 1010 } 1011 // check for Images and widgets 1012 else { 1013 if (!DisplayController.isXRayMode()) { 1014 if (ItemUtils.startsWithTag(i, 1015 ItemUtils.TAG_IMAGE, true)) { 1016 if (!i.hasEnclosures()) { 1017 createPicture(toParse, (Text) i); 1018 } 1019 // check for frame images 1020 } else if (ItemUtils.startsWithTag(i, 1021 ItemUtils.TAG_FRAME_IMAGE) 1022 && i.getLink() != null 1023 && !i.getAbsoluteLink() 1024 .equalsIgnoreCase( 1025 toParse.getName())) { 1026 XRayable image = null; 1027 if (i.hasEnclosures()) { 1028 // i.setHidden(true); 1029 // image = 1030 // i.getEnclosures().iterator().next(); 1031 // image.refresh(); 1032 } else { 1033 image = new FrameImage((Text) i, null); 1034 } 1035 // TODO Add the image when creating new 1036 // FrameImage 1037 toParse.addItem(image); 1038 } else if (ItemUtils.startsWithTag(i, 1039 ItemUtils.TAG_BITMAP_IMAGE) 1040 && i.getLink() != null 1041 && !i.getAbsoluteLink() 1042 .equalsIgnoreCase( 1043 toParse.getName())) { 1044 XRayable image = null; 1045 if (i.hasEnclosures()) { 1046 // image = 1047 // i.getEnclosures().iterator().next(); 1048 // image.refresh(); 1049 // i.setHidden(true); 1050 } else { 1051 // If a new bitmap is created for a 1052 // frame which already has a bitmap dont 1053 // recreate the bitmap 1054 image = new FrameBitmap((Text) i, null); 1055 } 1056 toParse.addItem(image); 1057 } else if (ItemUtils.startsWithTag(i, "@c")) { 1058 // Can only have a @c 1059 if (!i.hasEnclosures() 1060 && i.getLines().size() == 1) { 1061 toParse.addItem(new Circle((Text) i)); 1062 } 1063 // Check for JSItem 1064 } else if(ItemUtils.startsWithTag(i, "@js")) { 1065 toParse.addItem(new JSItem((Text) i)); 1066 // Check for interactive widgets 1067 } else if (ItemUtils.startsWithTag(i, ItemUtils.TAG_IWIDGET)) { 1068 createWidget(toParse, (Text) i); 1069 } 1070 } 1071 // TODO decide exactly what to do here!! 1072 toParse.addAnnotation((Text) i); 1073 } 1074 } else if (!DisplayController.isXRayMode() && i.hasFormula()) { 1075 i.calculate(i.getFormula()); 1076 } 1077 } 1078 } catch (Exception e) { 1079 Logger.Log(e); 1080 e.printStackTrace(); 1081 MessageBay.warningMessage("Exception occured when loading " 1082 + i.getClass().getSimpleName() + "(ID: " + i.getID() 1083 + ") " + e.getMessage() != null ? e.getMessage() : ""); 1084 } 1085 } 1086 1087 /* 1088 * for (Item i : items) { if (i instanceof Dot) { ((Dot) 1089 * i).setPointType(pointtype); ((Dot) i).useFilledPoints(filledPoints); 1090 * } } 1091 */ 1092 1093 FrameIO.ResumeCache(); 1094 1095 toParse.clearOverlays(); 1096 toParse.clearVectors(); 1097 toParse.addAllOverlays(overlays); 1098 toParse.addAllVectors(vectors); 1099 1100 } 1101 1102 /** 1103 * TODO: Comment. cts16 1104 * 1105 * @param vectors 1106 * @param permission 1107 * @param i 1108 */ 1109 private static void addVector(List<Vector> vectors, UserAppliedPermission defaultPermission, UserAppliedPermission framePermission, Item i) 1110 { 1111 // TODO It is possible to get into an infinite loop if a 1112 // frame contains an @ao which leads to a frame with an 1113 // @v which points back to the frame with the @ao 1114 Frame vector = FrameIO.LoadFrame(i.getAbsoluteLink()); 1115 1116 // Get the permission from off the vector frame 1117 UserAppliedPermission vectorPermission = UserAppliedPermission.getPermission(vector.getAnnotationValue("permission"), defaultPermission); 1118 1119 // If the frame permission is lower, use that 1120 vectorPermission = UserAppliedPermission.min(vectorPermission, framePermission); 1121 1122 // Highest permissable permission for vectors is copy 1123 vectorPermission = UserAppliedPermission.min(vectorPermission, UserAppliedPermission.copy); 1124 if (vector != null) { 1125 String scaleString = new AttributeValuePair(i.getText()).getValue(); 1126 Float scale = 1F; 1127 try { 1128 scale = Float.parseFloat(scaleString); 1129 } catch (Exception e) { 1130 } 1131 Vector newVector = new Vector(vector, vectorPermission, scale, i); 1132 i.setOverlay(newVector); 1133 i.setVisible(false); 1134 vectors.add(newVector); 1135 } 1136 } 1137 1138 public static Item onItem(float floatX, float floatY, boolean changeLastEdited) 1139 { 1140 return onItem(DisplayController.getCurrentFrame(), floatX, floatY, changeLastEdited); 1141 } 1142 1143 /** 1144 * Searches through the list of items on this frame to find one at the given 1145 * x,y coordinates. 1146 * 1147 * @param x 1148 * The x coordinate 1149 * @param y 1150 * The y coordinate 1151 * @return The Item at the given coordinates, or NULL if none is found. 1152 */ 1153 public static Item onItem(Frame toCheck, float floatX, float floatY, boolean bResetLastEdited) 1154 { 1155 // System.out.println("MouseX: " + floatX + " MouseY: " + floatY); 1156 int x = Math.round(floatX); 1157 int y = Math.round(floatY); 1158 if (toCheck == null) 1159 return null; 1160 1161 List<Item> possibles = new ArrayList<Item>(0); 1162 1163 // if the mouse is in the message area 1164 if (y >= DisplayController.getMessageBayPaintArea().getMinY()) { 1165 // check the individual message items 1166 for (Item message : MessageBay.getMessages()) { 1167 if (message != null) { 1168 if (message.contains(new Point(x, y))) { 1169 message.setOverlayPermission(UserAppliedPermission.copy); 1170 possibles.add(message); 1171 } else { 1172 // Not sure why but if the line below is removed then 1173 // several items can be highlighted at once 1174 message.setHighlightMode(Item.HighlightMode.None); 1175 message.setHighlightColorToDefault(); 1176 } 1177 } 1178 } 1179 1180 // check the link to the message frame 1181 if (MessageBay.getMessageLink() != null) { 1182 if (MessageBay.getMessageLink().contains(new Point(x, y))) { 1183 MessageBay.getMessageLink().setOverlayPermission(UserAppliedPermission.copy); 1184 possibles.add(MessageBay.getMessageLink()); 1185 } 1186 } 1187 1188 // this is taken into account in contains 1189 // y -= FrameGraphics.getMaxFrameSize().height; 1190 // otherwise, the mouse is on the frame 1191 } else { 1192 if (LastEdited != null) { 1193 if (LastEdited.contains(x, y) 1194 && !FreeItems.getInstance().contains(LastEdited) 1195 && LastEdited.getParent() == DisplayController.getCurrentFrame() 1196 && LastEdited.getParent().getItems().contains(LastEdited)) 1197 { 1198 LastEdited.setOverlayPermission(UserAppliedPermission.full); 1199 return LastEdited; 1200 } else if (bResetLastEdited) { 1201 setLastEdited(null); 1202 } 1203 } 1204 ArrayList<Item> checkList = new ArrayList<Item>(); 1205 checkList.addAll(toCheck.getInteractableItems()); 1206 checkList.add(toCheck.getNameItem()); 1207 1208 for (Item i : checkList) { 1209 1210 // do not check annotation items in audience mode 1211 //TODO: Upon hover of Rubbish Bin, Undo and Restore Widgets, flickering occurs depending on the mouse distance from a corner. Resolve this. 1212 if (i.isVisible() && !(DisplayController.isAudienceMode() && i.isAnnotation())) { 1213 if (i instanceof WidgetCorner) { 1214 WidgetCorner wc = (WidgetCorner) i; 1215 if (wc.getWidgetSource() instanceof ButtonWidget) { 1216 ButtonWidget bw = (ButtonWidget) wc.getWidgetSource(); 1217 1218 if (bw.getdropInteractableStatus() == true) { 1219 Widget iw = wc.getWidgetSource(); 1220 1221 if(iw.getBounds().contains(x, y)){ 1222 1223 if( !FreeItems.getInstance().contains(i)) 1224 { 1225 possibles.add(i); 1226 } 1227 } 1228 } 1229 } 1230 } 1231 1232 if (i.contains(new Point(x, y))){ 1233 if(!FreeItems.getInstance().contains(i)) { 1234 possibles.add(i); 1235 } 1236 } 1237 1238 } 1239 } 1240 } 1241 1242 // if there are no possible items, return null 1243 if (possibles.size() == 0) 1244 return null; 1245 1246 // if there is only one possibility, return it 1247 if (possibles.size() == 1) 1248 return possibles.get(0); 1249 1250 // return closest x,y pair to mouse 1251 Item closest = possibles.get(0); 1252 int distance = (int) Math.round(Math.sqrt(Math.pow( 1253 Math.abs(closest.getX() - x), 2) 1254 + Math.pow(Math.abs(closest.getY() - y), 2))); 1255 1256 for (Item i : possibles) { 1257 int d = (int) Math.round(Math.sqrt(Math.pow(Math.abs(i.getX() - x), 1258 2) + Math.pow(Math.abs(i.getY() - y), 2))); 1259 1260 // System.out.println(d); 1261 if (d <= distance) { 1262 distance = d; 1263 1264 // dots take precedence over lines 1265 if ((!(closest instanceof Dot && i instanceof Line)) 1266 && (!(closest instanceof Text && i instanceof Line))) 1267 closest = i; 1268 1269 } 1270 1271 } 1272 1273 return closest; 1274 } 428 1275 429 // check for an updated template... 430 for (Item i : frame.getAnnotationItems()) { 431 432 if (ItemUtils.startsWithTag(i, annotationStr)) { 433 434 matched_item = i; 435 break; 436 } 437 } 438 439 return matched_item; 440 } 441 442 protected static void doFrameTransition(Item frameTransition, Frame from, Frame to) 443 { 444 String s = frameTransition.getText(); 445 String[] s_array = s.split(":"); 446 if(s_array.length > 1){ 447 String slide_mode_method = s_array[1].trim(); 448 449 FrameTransitions.setSlideModeMethod(slide_mode_method); 450 System.out.println("Triggered on annotation: " + s); 451 FrameTransitions.setSlideTrue(); 452 FrameTransitions.setSlideModeBaseImage(FrameGraphics.getBuffer(from, false, false)); 453 } 454 else { 455 System.err.println("Warning: failed to detect frameTransition type"); 456 // TODO: print list as a result of reflection listing 457 } 458 } 459 460 /** 461 * Displays the given Frame on the display. If the current frame has changed 462 * since the last save then it will be saved before the switch is made. The 463 * caller can also dictate whether the current frame is added to the 464 * back-stack or not. 465 * 466 * @param toDisplay 467 * The Frame to display on the screen 468 * @param addToBack 469 * True if the current Frame should be added to the back-stack, 470 * False otherwise 471 */ 472 public static void DisplayFrame(Frame toDisplay, boolean addToBack, 473 boolean incrementStats) { 474 if (toDisplay == null) 475 return; 476 477 Frame current = DisplayIO.getCurrentFrame(); 478 479 // Dont need to do anything if the frame to display is already being 480 // displayed 481 if (current.equals(toDisplay)) 482 return; 483 484 // move any anchored connected items 485 if (FreeItems.itemsAttachedToCursor()) { 486 List<Item> toAdd = new ArrayList<Item>(); 487 List<Item> toCheck = new ArrayList<Item>(FreeItems.getInstance()); 488 489 while (toCheck.size() > 0) { 490 Item i = toCheck.get(0); 491 Collection<Item> connected = i.getAllConnected(); 492 493 // // Only move completely enclosed items 494 // if (!toCheck.containsAll(connected)) { 495 // connected.retainAll(FreeItems.getInstance()); 496 // FreeItems.getInstance().removeAll(connected); 497 // toCheck.removeAll(connected); 498 // FrameMouseActions.anchor(connected); 499 // } else { 500 // toCheck.removeAll(connected); 501 // } 502 503 // Anchor overlay items where they belong 504 if (i.getParent() != null && i.getParent() != current) { 505 FreeItems.getInstance().removeAll(connected); 506 toCheck.removeAll(connected); 507 FrameMouseActions.anchor(connected); 1276 /** 1277 * Checks if the mouse is currently over an item. 1278 * 1279 * @return 1280 * True if the mouse is over any item, false otherwise. 1281 */ 1282 public static boolean hasCurrentItem() 1283 { 1284 return getCurrentItem() != null; 1285 } 1286 1287 public synchronized static Item getCurrentItem() 1288 { 1289 return onItem(DisplayController.getCurrentFrame(), DisplayController.getMouseX(), DisplayController.getMouseY(), true); 1290 } 1291 1292 public static PolygonBounds getEnlosingPolygon() 1293 { 1294 Collection<Item> enclosure = getEnclosingLineEnds(); 1295 1296 if (enclosure == null || enclosure.size() == 0) return null; 1297 1298 return enclosure.iterator().next().getEnclosedShape(); 1299 } 1300 1301 /** 1302 * 1303 * @param currentItem 1304 * @return 1305 */ 1306 public static Collection<Item> getCurrentItems() 1307 { 1308 return getCurrentItems(getCurrentItem()); 1309 } 1310 1311 public static Collection<Item> getCurrentItems(Item currentItem) 1312 { 1313 Collection<Item> enclosure = getEnclosingLineEnds(); 1314 1315 if (enclosure == null || enclosure.size() == 0) return null; 1316 1317 Item firstItem = enclosure.iterator().next(); 1318 1319 Collection<Item> enclosed = getItemsEnclosedBy(DisplayController.getCurrentFrame(), firstItem.getEnclosedShape()); 1320 1321 // Brook: enclosed widgets are to be fully enclosed, never partially 1322 /* 1323 * MIKE says: but doesn't this mean that widgets are treated differently 1324 * from ALL other object which only need to be partially enclosed to be 1325 * picked up 1326 */ 1327 List<Widget> enclosedWidgets = new LinkedList<Widget>(); 1328 for (Item i : enclosed) { 1329 // Don't want to lose the highlighting from the current item 1330 if (i == currentItem || enclosure.contains(i)) { 1331 continue; 1332 } 1333 // Don't want to lose the highlighting of connected Dots 1334 // TODO: this code does nothing (perhaps the continue is meant for the outer 1335 // for loop?). cts16 1336 if (i instanceof Dot && i.getHighlightMode() == HighlightMode.Connected) { 1337 for (Line l : i.getLines()) { 1338 if (l.getOppositeEnd(i).getHighlightMode() == HighlightMode.Normal) { 1339 continue; 1340 } 1341 } 1342 } 1343 1344 if (i instanceof WidgetCorner) { 1345 if (!enclosedWidgets.contains(((WidgetCorner) i).getWidgetSource())) { 1346 enclosedWidgets.add(((WidgetCorner) i).getWidgetSource()); 1347 } 1348 } 1349 1350 i.setHighlightMode(Item.HighlightMode.None); 1351 i.setHighlightColorToDefault(); 1352 } 1353 1354 for (Widget iw : enclosedWidgets) { 1355 for (Item i : iw.getItems()) { 1356 if (!enclosed.contains(i)) { 1357 enclosed.add(i); 1358 } 1359 } 1360 } 1361 1362 return enclosed; 1363 } 1364 1365 /** 1366 * Gets the collection of Dot items that form the enclosure nearest to the current mouse position. 1367 */ 1368 public static Collection<Item> getEnclosingLineEnds() 1369 { 1370 return getEnclosingLineEnds(new Point(DisplayController.getMouseX(), DisplayController.getMouseY())); 1371 } 1372 1373 /** 1374 * Gets the collection of Dot items that form the enclosure nearest to the given position. 1375 */ 1376 public static Collection<Item> getEnclosingLineEnds(Point position) 1377 { 1378 // update enclosed shapes 1379 Frame current = DisplayController.getCurrentFrame(); 1380 if (current == null) return null; 1381 List<Item> items = current.getItems(); 1382 1383 // Remove all items that are connected to freeItems 1384 List<Item> freeItems = new ArrayList<Item>(FreeItems.getInstance()); 1385 while (freeItems.size() > 0) { 1386 Item item = freeItems.get(0); 1387 Collection<Item> connected = item.getAllConnected(); 1388 items.removeAll(connected); 1389 freeItems.removeAll(connected); 1390 } 1391 1392 List<Item> used = new ArrayList<Item>(0); 1393 1394 while (items.size() > 0) { 1395 Item i = items.get(0); 1396 items.remove(i); 1397 if (i.isEnclosed()) { 1398 PolygonBounds p = i.getEnclosedShape(); 1399 if (p.contains(position)) { 1400 used.add(i); 1401 items.removeAll(i.getEnclosingDots()); 1402 } 1403 } 1404 } 1405 1406 if (used.size() == 0) return null; 1407 1408 // if there is only one possibility, return it 1409 if (used.size() == 1) { 1410 return used.get(0).getEnclosingDots(); 1411 // otherwise, determine which polygon is closest to the cursor 508 1412 } else { 509 // Add stuff that is partially enclosed 510 // remove all the connected items from our list to check 511 toCheck.removeAll(connected); 512 // Dont add the items that are free 513 connected.removeAll(FreeItems.getInstance()); 514 toAdd.addAll(connected); 515 } 516 } 517 518 current.removeAllItems(toAdd); 519 520 boolean oldChange = toDisplay.hasChanged(); 521 toDisplay.updateIDs(toAdd); 522 toDisplay.addAllItems(toAdd); 523 toDisplay.setChanged(oldChange); 524 } 525 526 if (addToBack && current != toDisplay) { 527 FrameIO.checkTDFC(current); 528 } 529 530 // if the saving happened properly, we can continue 531 if (!LeavingFrame(current)) { 532 MessageBay.displayMessage("Navigation cancelled"); 533 return; 534 } 535 536 if (addToBack && current != toDisplay) { 537 DisplayIO.addToBack(current); 538 } 539 540 Parse(toDisplay); 541 542 if (FrameGraphics.isAudienceMode()) { 543 // Only need to worry about frame transitions when in Audience Mode 1413 Collections.sort(used, new Comparator<Item>() { 1414 public int compare(Item d1, Item d2) { 1415 PolygonBounds p1 = d1.getEnclosedShape(); 1416 PolygonBounds p2 = d2.getEnclosedShape(); 1417 1418 int closest = Integer.MAX_VALUE; 1419 int close2 = Integer.MAX_VALUE; 1420 1421 int mouseX = DisplayController.getMouseX(); 1422 int mouseY = DisplayController.getMouseY(); 1423 1424 for (int i = 0; i < p1.getPointCount(); i++) { 1425 int diff = Math.abs(p1.getPoint(i).x - mouseX) + Math.abs(p1.getPoint(i).y - mouseY); 1426 int diff2 = Integer.MAX_VALUE; 1427 1428 if (i < p2.getPointCount()) 1429 diff2 = Math.abs(p2.getPoint(i).x - mouseX) + Math.abs(p2.getPoint(i).y - mouseY); 1430 1431 if (diff < Math.abs(closest)) { 1432 close2 = closest; 1433 closest = diff; 1434 } else if (diff < Math.abs(close2)) 1435 close2 = diff; 1436 1437 if (diff2 < Math.abs(closest)) { 1438 close2 = closest; 1439 closest = -diff2; 1440 } else if (diff2 < Math.abs(close2)) 1441 close2 = diff2; 1442 } 1443 1444 if (closest > 0 && close2 > 0) 1445 return -10; 1446 1447 if (closest < 0 && close2 < 0) 1448 return 10; 1449 1450 if (closest > 0) 1451 return -10; 1452 1453 return 10; 1454 } 1455 1456 }); 1457 1458 return used.get(0).getEnclosingDots(); 1459 } 1460 } 1461 1462 // TODO Remove this method!! 1463 // Can just getItemsWithin be used? 1464 public static Collection<Item> getItemsEnclosedBy(Frame frame, PolygonBounds poly) 1465 { 1466 Collection<Item> contained = frame.getItemsWithin(poly); 1467 1468 Collection<Item> results = new LinkedHashSet<Item>(contained.size()); 1469 1470 // check for correct permissions 1471 for (Item item : contained) { 1472 // if the item is on the frame 1473 if (item.getParent() == frame || item.getParent() == null) { 1474 // item.Permission = Permission.full; 1475 results.add(item); 1476 // otherwise, it must be on an overlay frame 1477 } else { 1478 for (Overlay overlay : frame.getOverlays()) { 1479 if (overlay.Frame == item.getParent()) { 1480 item.setOverlayPermission(overlay.permission); 1481 results.add(item); 1482 break; 1483 } 1484 } 1485 } 1486 } 1487 1488 return results; 1489 } 1490 1491 /** 1492 * Fills the given Frame with default profile tags 1493 */ 1494 public static void CreateDefaultProfile(String username, Frame profile) 1495 { 1496 Text title = profile.getTitleItem(); 1497 if (username.equals(UserSettings.DEFAULT_PROFILE_NAME)) { 1498 title.setText("Default Profile Frame"); 1499 } else { 1500 // if this profile is not the default profile, copy it from the default profile instead of generating a new profile 1501 // (this allows the possibility of modifying the default profile and having any new profiles get those modifications) 1502 Frame nextDefault = FrameIO.LoadProfile(UserSettings.DEFAULT_PROFILE_NAME); 1503 if (nextDefault == null) { 1504 try { 1505 nextDefault = FrameIO.CreateNewProfile(UserSettings.DEFAULT_PROFILE_NAME); 1506 } catch (Exception e) { 1507 // TODO tell the user that there was a problem creating the 1508 // profile frame and close nicely 1509 e.printStackTrace(); 1510 } 1511 } 1512 // load profile frame and set title correctly 1513 profile.reset(); 1514 profile.removeAllItems(profile.getAllItems()); 1515 // set relative link on all items so their links will correctly point to the page on the current profile rather than on the default profile 1516 for(Item i : nextDefault.getAllItems()) { 1517 i.setRelativeLink(); 1518 } 1519 profile.addAllItems(ItemUtils.CopyItems(nextDefault.getAllItems())); 1520 profile.setTitle(username + "'s Profile Frame"); 1521 FrameIO.SaveFrame(profile); 1522 1523 Frame nextProfile = profile; 1524 MessageBay.suppressMessages(true); 1525 while((nextDefault = FrameIO.LoadNext(nextDefault)) != null) { 1526 // in case there are gaps in the frame numbering of the default profile (e.g. if a user has edited it), 1527 // we need to replicate those gaps in the copied profile so the links will work correctly 1528 while(nextProfile.getNumber() < nextDefault.getNumber()) { 1529 nextProfile = FrameIO.CreateFrame(profile.getFramesetName(), null, null); 1530 } 1531 // if the new profile has a frame number higher than the current frame number in the default profile, 1532 // the new profile must already exist, so just exit 1533 // (TODO: should we wipe the frames instead?) 1534 if(nextProfile.getNumber() > nextDefault.getNumber()) { 1535 break; 1536 } 1537 nextProfile.reset(); 1538 nextProfile.removeAllItems(nextProfile.getAllItems()); 1539 // set relative link on all items so their links will correctly point to the page on the current profile rather than on the default profile 1540 for(Item i : nextDefault.getAllItems()) { 1541 i.setRelativeLink(); 1542 } 1543 nextProfile.addAllItems(ItemUtils.CopyItems(nextDefault.getAllItems())); 1544 FrameIO.SaveFrame(nextProfile); 1545 } 1546 MessageBay.suppressMessages(false); 1547 1548 return; 1549 } 1550 1551 // int spacing = 50; 1552 final int intialYPos = 75; 1553 int xPos = 75; 1554 int yPos = intialYPos; 1555 1556 // yPos += spacing; 1557 // profile.addText(xPos, yPos, "@HomeFrame", null, profile.getName()); 1558 // yPos += spacing; 1559 // String defaultFrameName = profile.getFramesetName() + "0"; 1560 // profile.addText(xPos, yPos, "@DefaultFrame", null, defaultFrameName); 1561 // yPos += spacing; 1562 // 1563 // profile.addText(xPos, yPos, "@InitialWidth: " 1564 // + UserSettings.InitialWidth, null); 1565 // yPos += spacing; 1566 // 1567 // profile.addText(xPos, yPos, "@InitialHeight: " 1568 // + UserSettings.InitialHeight, null); 1569 // yPos += spacing; 1570 // 1571 // Text t = profile.addText(xPos, yPos, "@ItemTemplate", null); 1572 // t.setColor(null); 1573 // 1574 // yPos += spacing; 1575 // t = profile.addText(xPos, yPos, "@AnnotationTemplate", null); 1576 // t.setColor(Color.gray); 1577 // 1578 // yPos += spacing; 1579 // t = profile.addText(xPos, yPos, "@CommentTemplate", null); 1580 // t.setColor(Color.green.darker()); 1581 // 1582 // yPos += spacing; 1583 // t = profile.addText(xPos, yPos, "@StatsTemplate", null); 1584 // t.setColor(Color.BLACK); 1585 // t.setBackgroundColor(new Color(0.9F, 0.9F, 0.9F)); 1586 // t.setFamily(Text.MONOSPACED_FONT); 1587 // t.setSize(14); 1588 1589 Text t; 1590 1591 xPos = 300; 1592 // yPos = intialYPos + spacing; 1593 yPos = 100; 1594 1595 // Add documentation links 1596 File helpDirectory = new File(FrameIO.HELP_PATH); 1597 if (helpDirectory != null) { 1598 File[] helpFramesets = helpDirectory.listFiles(); 1599 if (helpFramesets != null) { 1600 1601 // Add the title for the help index 1602 Text help = profile.addText(xPos, yPos, "@Expeditee Help", null); 1603 help.setSize(25); 1604 help.setFontStyle("Bold"); 1605 help.setFamily("SansSerif"); 1606 help.setColor(TemplateSettings.ColorWheel.get()[3]); 1607 1608 xPos += 25; 1609 System.out.println("Installing frameset: "); 1610 1611 boolean first_item = true; 1612 1613 for (File helpFrameset : helpFramesets) { 1614 String framesetName = helpFrameset.getName(); 1615 if (!FrameIO.isValidFramesetName(framesetName)) { 1616 continue; 1617 } 1618 1619 if (first_item) { 1620 System.out.print(" " + framesetName); 1621 first_item = false; 1622 } 1623 else { 1624 System.out.print(", " + framesetName); 1625 } 1626 System.out.flush(); 1627 1628 Frame indexFrame = FrameIO.LoadFrame(framesetName + '1'); 1629 // Look through the folder for help index pages 1630 if (indexFrame != null 1631 && ItemUtils.FindTag(indexFrame.getItems(), 1632 "@HelpIndex") != null) { 1633 // yPos += spacing; 1634 yPos += 30; 1635 t = profile.addText(xPos, yPos, 1636 '@' + indexFrame.getFramesetName(), null); 1637 t.setLink(indexFrame.getName()); 1638 t.setColor(Colour.GREY); 1639 } 1640 } 1641 System.out.println(); 1642 } 1643 } 1644 1645 xPos = 50; 1646 yPos = 100; 1647 1648 // Populate Start Pages and Settings 1649 File framesetDirectory = new File(FrameIO.FRAME_PATH); 1650 1651 if (framesetDirectory.exists()) { 1652 File[] startpagesFramesets = framesetDirectory.listFiles(); 1653 1654 if (startpagesFramesets != null) { 1655 // Add Start Page title 1656 Text templates = profile.addText(xPos, yPos, "@Start Pages", 1657 null); 1658 templates.setSize(25); 1659 templates.setFontStyle("Bold"); 1660 templates.setFamily("SansSerif"); 1661 templates.setColor(TemplateSettings.ColorWheel.get()[3]); 1662 1663 xPos += 25; 1664 1665 // Start Pages should be the first frame in its own frameset + 1666 // frameset name should be present in FrameUtils.startPages[]. 1667 for (File startpagesFrameset : startpagesFramesets) { 1668 String framesetName = startpagesFrameset.getName(); 1669 1670 // Only add link if frameset is a startpage 1671 for (int i = 0; i < startPages.length; i++) { 1672 if (framesetName.equals(startPages[i])) { 1673 Frame indexFrame = FrameIO 1674 .LoadFrame(framesetName + '1'); 1675 1676 // Add start page link 1677 if (indexFrame != null) { 1678 yPos += 30; 1679 t = profile.addText(xPos, yPos, 1680 '@' + indexFrame.getFramesetName(), 1681 null); 1682 t.setLink(indexFrame.getName()); 1683 t.setColor(Colour.GREY); 1684 } 1685 } 1686 } 1687 } 1688 } 1689 } 1690 1691 FrameIO.SaveFrame(profile); 1692 1693 // Populate settings frameset 1694 Settings.Init(); 1695 t = profile.addText(550, 100, "@Settings", null); 1696 t.setSize((float) 25.0); 1697 t.setFamily("SansSerif"); 1698 t.setFontStyle("Bold"); 1699 t.setColor(Colour.GREY); 1700 Settings.generateSettingsTree(t); 1701 1702 FrameIO.SaveFrame(profile); 1703 } 1704 1705 private static void checkTDFCItemWaiting(Frame currentFrame) 1706 { 1707 Item tdfcItem = FrameUtils.getTdfcItem(); 1708 // if there is a TDFC Item waiting 1709 if (tdfcItem != null) { 1710 boolean change = currentFrame.hasChanged(); 1711 boolean saved = currentFrame.isSaved(); 1712 // Save the parent of the item if it has not been saved 1713 if (!change && !saved) { 1714 tdfcItem.setLink(null); 1715 tdfcItem.getParent().setChanged(true); 1716 FrameIO.SaveFrame(tdfcItem.getParent()); 1717 DisplayController.requestRefresh(true); 1718 } else { 1719 SessionStats.CreatedFrame(); 1720 } 1721 1722 setTdfcItem(null); 1723 } 1724 } 1725 1726 public static void setTdfcItem(Item _tdfcItem) 1727 { 1728 FrameUtils._tdfcItem = _tdfcItem; 1729 } 1730 1731 public static Item getTdfcItem() 1732 { 1733 return FrameUtils._tdfcItem; 1734 } 1735 1736 public static void setLastEdited(Text lastEdited) 1737 { 1738 // If the lastEdited is being changed then check if its @i 1739 Frame toReparse = null; 1740 Frame toRecalculate = null; 1741 Frame toUpdateObservers = null; 1742 1743 if (LastEdited == null) { 1744 // System.out.print("N"); 1745 } else if (LastEdited != null) { 1746 // System.out.print("T"); 1747 Frame parent = LastEdited.getParentOrCurrentFrame(); 1748 1749 if (lastEdited != LastEdited) { 1750 if (LastEdited.startsWith("@i")) { 1751 // Check if its an image that can be resized to fit a box 1752 // around it 1753 String text = LastEdited.getText(); 1754 if (text.startsWith("@i:") 1755 && !Character 1756 .isDigit(text.charAt(text.length() - 1))) { 1757 Collection<Item> enclosure = FrameUtils 1758 .getEnclosingLineEnds(LastEdited.getPosition()); 1759 if (enclosure != null) { 1760 for (Item i : enclosure) { 1761 if (i.isLineEnd() && i.isEnclosed()) { 1762 DisplayController.getCurrentFrame().removeAllItems( 1763 enclosure); 1764 AxisAlignedBoxBounds rect = i.getEnclosedBox(); 1765 LastEdited 1766 .setText(LastEdited.getText() 1767 + " " 1768 + Math.round(rect 1769 .getWidth())); 1770 LastEdited.setPosition(rect.getTopLeft()); 1771 LastEdited.setThickness(i.getThickness()); 1772 LastEdited.setBorderColor(i.getColor()); 1773 break; 1774 } 1775 } 1776 StandardGestureActions.deleteItems(enclosure, false); 1777 } 1778 } 1779 toReparse = parent; 1780 } else if (LastEdited.recalculateWhenChanged()) { 1781 toRecalculate = parent; 1782 } 1783 1784 if (parent.hasObservers()) { 1785 toUpdateObservers = parent; 1786 } 1787 // Update the formula if in XRay mode 1788 if (DisplayController.isXRayMode() && LastEdited.hasFormula()) { 1789 LastEdited.setFormula(LastEdited.getText()); 1790 } 1791 } 1792 if (lastEdited != LastEdited && LastEdited.getText().length() == 0) { 1793 parent.removeItem(LastEdited); 1794 } 1795 } 1796 LastEdited = lastEdited; 1797 1798 if (!DisplayController.isXRayMode()) { 1799 if (toReparse != null) { 1800 Parse(toReparse, false, false); 1801 } else { 1802 if (toRecalculate != null) { 1803 toRecalculate.recalculate(); 1804 } 1805 1806 if (toUpdateObservers != null) { 1807 toUpdateObservers.notifyObservers(false); 1808 } 1809 } 1810 } 1811 } 1812 1813 /** 1814 * Extracts files/folders from the assets/resources folder directly into 1815 * ${PARENT_FOLDER} (~/.expeditee) 1816 * 1817 * @param force if true, resources will be extracted even if they have already been extracted before 1818 */ 1819 public static void extractResources(boolean force) 1820 { 1821 File check = new File(FrameIO.PARENT_FOLDER + ".res"); 544 1822 545 // Test to see if frame transition specified through annotation, and perform it if one if found 546 Item frameTransition = getAnnotation(toDisplay, "@frameTransition"); 547 if (frameTransition != null) { 548 doFrameTransition(frameTransition,current,toDisplay); 549 } 550 } 551 552 DisplayIO.setCurrentFrame(toDisplay, incrementStats); 553 FrameMouseActions.updateCursor(); 554 // FrameMouseActions.getInstance().refreshHighlights(); 555 // update response timer 556 _LastResponse = ResponseTimer.getElapsedSeconds(); 557 _ResponseTimeSum += _LastResponse; 558 DisplayIO.UpdateTitle(); 559 } 560 561 /** 562 * Loads and displays the Frame with the given framename, and adds the 563 * current frame to the back-stack if required. 564 * 565 * @param framename 566 * The name of the Frame to load and display 567 * @param addToBack 568 * True if the current Frame should be added to the back-stack, 569 * false otherwise 570 */ 571 public static void DisplayFrame(String frameName, boolean addToBack, 572 boolean incrementStats) { 573 Frame newFrame = getFrame(frameName); 574 575 if (newFrame != null) 576 // display the frame 577 DisplayFrame(newFrame, addToBack, incrementStats); 578 } 579 580 /** 581 * Loads and displays the Frame with the given framename and adds the 582 * current frame to the back-stack. This is the same as calling 583 * DisplayFrame(framename, true) 584 * 585 * @param framename 586 * The name of the Frame to load and display 587 */ 588 public static void DisplayFrame(String framename) { 589 DisplayFrame(framename, true, true); 590 } 591 592 public static Frame getFrame(String frameName) { 593 // if the new frame does not exist then tell the user 594 Frame f = FrameIO.LoadFrame(frameName); 595 596 if (f == null) { 597 MessageBay.errorMessage("Frame '" + frameName 598 + "' could not be found."); 599 } 600 601 return f; 602 } 603 604 /** 605 * Creates a new Picture Item from the given Text source Item and adds it to 606 * the given Frame. 607 * 608 * @return True if the image was created successfully, false otherwise 609 */ 610 private static boolean createPicture(Frame frame, Text txt) { 611 // attempt to create the picture 612 Picture pic = ItemUtils.CreatePicture(txt, frame); 613 614 // if the picture could not be created successfully 615 if (pic == null) { 616 String imagePath = txt.getText(); 617 assert (imagePath != null); 618 imagePath = new AttributeValuePair(imagePath).getValue().trim(); 619 if (imagePath.length() == 0) { 620 return false; 621 // MessageBay.errorMessage("Expected image path after @i:"); 622 } else { 623 MessageBay.errorMessage("Image " + imagePath 624 + " could not be loaded"); 625 } 626 return false; 627 } 628 frame.addItem(pic); 629 630 return true; 631 } 632 633 /** 634 * Creates an interactive widget and adds it to a frame. If txt has no 635 * parent the parent will be set to frame. 636 * 637 * @param frame 638 * Frame to add widget to. Must not be null. 639 * 640 * @param txt 641 * Text to create the widget from. Must not be null. 642 * 643 * @return True if created/added. False if coul not create. 644 * 645 * @author Brook Novak 646 */ 647 private static boolean createWidget(Frame frame, Text txt) { 648 649 if (frame == null) 650 throw new NullPointerException("frame"); 651 if (txt == null) 652 throw new NullPointerException("txt"); 653 654 // Safety 655 if (txt.getParent() == null) 656 txt.setParent(frame); 657 658 InteractiveWidget iw = null; 659 660 try { 661 662 iw = InteractiveWidget.createWidget(txt); 663 664 } catch (InteractiveWidgetNotAvailableException e) { 665 e.printStackTrace(); 666 MessageBay.errorMessage("Cannot create iWidget: " + e.getMessage()); 667 } catch (InteractiveWidgetInitialisationFailedException e) { 668 e.printStackTrace(); 669 MessageBay.errorMessage("Cannot create iWidget: " + e.getMessage()); 670 } catch (IllegalArgumentException e) { 671 e.printStackTrace(); 672 MessageBay.errorMessage("Cannot create iWidget: " + e.getMessage()); 673 } 674 675 if (iw == null) 676 return false; 677 678 frame.removeItem(txt); 679 680 frame.addAllItems(iw.getItems()); 681 682 return true; 683 } 684 685 public static Collection<String> ParseProfile(Frame profile) { 686 Collection<String> errors = new LinkedList<String>(); 687 if (profile == null) 688 return errors; 689 690 /* 691 * Make sure the correct cursor shows when turning off the custom cursor 692 * and reparsing the profile frame 693 */ 694 FreeItems.getCursor().clear(); 695 DisplayIO.setCursor(Item.HIDDEN_CURSOR); 696 DisplayIO.setCursor(Item.DEFAULT_CURSOR); 697 698 // check for settings tags 699 for (Text item : profile.getBodyTextItems(true)) { 700 try { 701 702 AttributeValuePair avp = new AttributeValuePair(item.getText()); 703 String attributeFullCase = avp.getAttributeOrValue(); 704 705 if (attributeFullCase == null) { 706 continue; 707 } 708 String attribute = attributeFullCase.trim().toLowerCase() 709 .replaceAll("^@", ""); 710 711 if (attribute.equals("settings")) { 712 Settings.parseSettings(item); 713 } 714 715 } catch (Exception e) { 716 if (e.getMessage() != null) { 717 errors.add(e.getMessage()); 718 } else { 719 e.printStackTrace(); 720 errors.add("Error parsing [" + item.getText() + "] on " 721 + profile.getName()); 722 } 723 } 724 } 725 726 return errors; 727 } 728 729 /** 730 * Sets the first frame to be displayed. 731 * 732 * @param profile 733 */ 734 public static void loadFirstFrame(Frame profile) { 735 if (UserSettings.HomeFrame.get() == null) 736 UserSettings.HomeFrame.set(profile.getName()); 737 738 Frame firstFrame = FrameIO.LoadFrame(UserSettings.HomeFrame.get()); 739 if (firstFrame == null) { 740 MessageBay.warningMessage("Home frame not found: " 741 + UserSettings.HomeFrame); 742 UserSettings.HomeFrame.set(profile.getName()); 743 DisplayIO.setCurrentFrame(profile, true); 744 } else { 745 DisplayIO.setCurrentFrame(firstFrame, true); 746 } 747 748 } 749 750 public static Color[] getColorWheel(Frame frame) { 751 if (frame != null) { 752 List<Text> textItems = frame.getBodyTextItems(false); 753 Color[] colorList = new Color[textItems.size() + 1]; 754 for (int i = 0; i < textItems.size(); i++) { 755 colorList[i] = textItems.get(i).getColor(); 756 } 757 // Make the last item transparency or default for forecolor 758 colorList[colorList.length - 1] = null; 759 760 return colorList; 761 } 762 return new Color[] { Color.black, Color.white, null }; 763 } 764 765 public static String getLink(Item item, String alt) { 766 if (item == null || !(item instanceof Text)) 767 return alt; 768 769 AttributeValuePair avp = new AttributeValuePair(item.getText()); 770 assert (avp != null); 771 772 if (avp.hasPair() && avp.getValue().trim().length() != 0) { 773 item.setLink(avp.getValue()); 774 return avp.getValue(); 775 } else if (item.getLink() != null) { 776 return item.getAbsoluteLink(); 777 } 778 779 return alt; 780 } 781 782 public static String getDir(String name) { 783 if (name != null) { 784 File tester = new File(name); 785 if (tester.exists() && tester.isDirectory()) { 786 if (name.endsWith(File.separator)) 787 return name; 788 else 789 return name + File.separator; 790 } else { 791 throw new RuntimeException("Directory not found: " + name); 792 } 793 } 794 throw new RuntimeException("Missing value for profile attribute" + name); 795 } 796 797 public static ArrayList<String> getDirs(Item item) { 798 ArrayList<String> dirsToAdd = new ArrayList<String>(); 799 String dirListFrameName = item.getAbsoluteLink(); 800 if (dirListFrameName != null) { 801 Frame dirListFrame = FrameIO.LoadFrame(dirListFrameName); 802 if (dirListFrame != null) { 803 for (Text t : dirListFrame.getBodyTextItems(false)) { 804 String dirName = t.getText().trim(); 805 File tester = new File(dirName); 806 if (tester.exists() && tester.isDirectory()) { 807 if (dirName.endsWith(File.separator)) 808 dirsToAdd.add(dirName); 809 else 810 dirsToAdd.add(dirName + File.separator); 811 } 812 } 813 } 814 } 815 816 return dirsToAdd; 817 } 818 819 public static void Parse(Frame toParse) { 820 Parse(toParse, false); 821 } 822 823 /** 824 * Checks for any special Annotation items and updates the display as 825 * necessary. Special Items: Images, overlays, sort. 826 * 827 */ 828 public static void Parse(Frame toParse, boolean firstParse) { 829 Parse(toParse, firstParse, false); 830 } 831 832 /** 833 * 834 * @param toParse 835 * @param firstParse 836 * @param ignoreAnnotations 837 * used to prevent infinate loops such as when performing TDFC 838 * with an ao tag linked to a frame with an frameImage of a frame 839 * which also has an ao tag on it. 840 */ 841 public static void Parse(Frame toParse, boolean firstParse, 842 boolean ignoreAnnotations) { 843 // TODO check why we are getting toParse == null... when profile frame 844 // is being created and change the lines below 845 if (toParse == null) 846 return; 847 // System.out.println(firstParse); 848 if (firstParse) 849 ItemUtils.EnclosedCheck(toParse.getItems()); 850 List<Item> items = toParse.getItems(); 851 852 // if XRayMode is on, replace pictures with their underlying text 853 if (FrameGraphics.isXRayMode()) { 854 855 // BROOK: Must handle these a little different 856 List<InteractiveWidget> widgets = toParse.getInteractiveWidgets(); 857 858 for (Item i : items) { 859 if (i instanceof XRayable) { 860 toParse.removeItem(i); 861 // Show the items 862 for (Item item : ((XRayable) i).getConnected()) { 863 item.setVisible(true); 864 item.removeEnclosure(i); 865 } 866 } else if (i instanceof WidgetCorner) { 867 toParse.removeItem(i); 868 } else if (i instanceof WidgetEdge) { 869 toParse.removeItem(i); 870 } else if (i.hasFormula()) { 871 i.setText(i.getFormula()); 872 } else if (i.hasOverlay()) { 873 i.setVisible(true); 874 // int x = i.getBoundsHeight(); 875 } 876 } 877 878 for (InteractiveWidget iw : widgets) { 879 toParse.addItem(iw.getSource()); 880 } 881 } 882 883 // Text title = null; 884 // Text template = UserSettingsTemplate.copy(); 885 886 List<Overlay> overlays = new ArrayList<Overlay>(); 887 List<Vector> vectors = new ArrayList<Vector>(); 888 889 // disable reading of cached overlays if in twinframes mode 890 if (DisplayIO.isTwinFramesOn()) 891 FrameIO.SuspendCache(); 892 893 DotType pointtype = DotType.square; 894 boolean filledPoints = true; 895 896 UserAppliedPermission permission = toParse.getUserAppliedPermission(); 897 toParse.clearAnnotations(); 898 899 // check for any new overlay items 900 for (Item i : toParse.getItems()) { 901 try { 902 // reset overlay permission 903 i.setOverlayPermission(null); 904 // i.setPermission(permission); 905 if (i instanceof WidgetCorner) { 906 // TODO improve efficiency so it only updates once... using 907 // observer design pattern 908 i.update(); 909 } else if (i instanceof Text) { 910 if (i.isAnnotation()) { 911 if (ItemUtils.startsWithTag(i, ItemUtils.TAG_POINTTYPE)) { 912 Text txt = (Text) i; 913 String line = txt.getFirstLine(); 914 line = ItemUtils.StripTag(line, 915 ItemUtils.GetTag(ItemUtils.TAG_POINTTYPE)); 916 917 if (line != null) { 918 line = line.toLowerCase(); 919 if (line.indexOf(" ") > 0) { 920 String fill = line.substring(line 921 .indexOf(" ") + 1); 922 if (fill.startsWith("nofill")) 923 filledPoints = false; 924 else 925 filledPoints = true; 926 } 927 928 if (line.startsWith("circle")) 929 pointtype = DotType.circle; 930 else 931 pointtype = DotType.square; 932 } 933 }// check for new VECTOR items 934 else if (!FrameGraphics.isXRayMode() 935 && ItemUtils.startsWithTag(i, 936 ItemUtils.TAG_VECTOR) 937 && i.getLink() != null) { 938 if (!i.getAbsoluteLink().equals(toParse.getName())) 939 addVector(vectors, UserAppliedPermission.none, 940 permission, i); 941 } else if (!FrameGraphics.isXRayMode() 942 && ItemUtils.startsWithTag(i, 943 ItemUtils.TAG_ACTIVE_VECTOR) 944 && i.getLink() != null) { 945 if (!i.getAbsoluteLink().equals(toParse.getName())) 946 addVector(vectors, 947 UserAppliedPermission.followLinks, 948 permission, i); 949 } 950 // check for new OVERLAY items 951 else if (!ignoreAnnotations 952 && ItemUtils.startsWithTag(i, 953 ItemUtils.TAG_OVERLAY) 954 && i.getLink() != null) { 955 if (i.getAbsoluteLink().equalsIgnoreCase( 956 toParse.getName())) { 957 // This frame contains an active overlay which 958 // points to itself 959 MessageBay 960 .errorMessage(toParse.getName() 961 + " contains an @o which links to itself"); 962 continue; 963 } 964 965 Frame overlayFrame = FrameIO.LoadFrame(i 966 .getAbsoluteLink()); 967 // Parse(overlay); 968 if (overlayFrame != null 969 && Overlay.getOverlay(overlays, 970 overlayFrame) == null) 971 overlays.add(new Overlay(overlayFrame, 972 UserAppliedPermission.none)); 973 } 974 // check for ACTIVE_OVERLAY items 975 else if (!ignoreAnnotations 976 && ItemUtils.startsWithTag(i, 977 ItemUtils.TAG_ACTIVE_OVERLAY) 978 && i.getLink() != null) { 979 String link = i.getAbsoluteLink(); 980 if (link.equalsIgnoreCase(toParse.getName())) { 981 // This frame contains an active overlay which 982 // points to itself 983 MessageBay 984 .errorMessage(toParse.getName() 985 + " contains an @ao which links to itself"); 986 continue; 987 } 988 Frame overlayFrame = null; 989 990 Frame current = DisplayIO.getCurrentFrame(); 991 if (current != null) { 992 for (Overlay o : current.getOverlays()) { 993 if (o.Frame.getName() 994 .equalsIgnoreCase(link)) 995 overlayFrame = o.Frame; 996 } 997 } 998 if (overlayFrame == null) 999 overlayFrame = FrameIO.LoadFrame(link); 1000 1001 // get level if specified 1002 String level = new AttributeValuePair(i.getText()) 1003 .getValue(); 1004 // default permission (if none is specified) 1005 PermissionPair permissionLevel = new PermissionPair( 1006 level, UserAppliedPermission.followLinks); 1007 1008 if (overlayFrame != null) { 1009 Overlay existingOverlay = Overlay.getOverlay( 1010 overlays, overlayFrame); 1011 // If it wasn't in the list create it and add 1012 // it. 1013 if (existingOverlay == null) { 1014 Overlay newOverlay = new Overlay( 1015 overlayFrame, 1016 permissionLevel 1017 .getPermission(overlayFrame 1018 .getOwner())); 1019 i.setOverlay(newOverlay); 1020 overlays.add(newOverlay); 1021 } else { 1022 existingOverlay.Frame 1023 .setPermission(permissionLevel); 1024 } 1025 } 1026 } 1027 // check for Images and widgets 1028 else { 1029 if (!FrameGraphics.isXRayMode()) { 1030 if (ItemUtils.startsWithTag(i, 1031 ItemUtils.TAG_IMAGE, true)) { 1032 if (!i.hasEnclosures()) { 1033 createPicture(toParse, (Text) i); 1034 } 1035 // check for frame images 1036 } else if (ItemUtils.startsWithTag(i, 1037 ItemUtils.TAG_FRAME_IMAGE) 1038 && i.getLink() != null 1039 && !i.getAbsoluteLink() 1040 .equalsIgnoreCase( 1041 toParse.getName())) { 1042 XRayable image = null; 1043 if (i.hasEnclosures()) { 1044 // i.setHidden(true); 1045 // image = 1046 // i.getEnclosures().iterator().next(); 1047 // image.refresh(); 1048 } else { 1049 image = new FrameImage((Text) i, 1050 toParse, null); 1051 } 1052 // TODO Add the image when creating new 1053 // FrameImage 1054 toParse.addItem(image); 1055 } else if (ItemUtils.startsWithTag(i, 1056 ItemUtils.TAG_BITMAP_IMAGE) 1057 && i.getLink() != null 1058 && !i.getAbsoluteLink() 1059 .equalsIgnoreCase( 1060 toParse.getName())) { 1061 XRayable image = null; 1062 if (i.hasEnclosures()) { 1063 // image = 1064 // i.getEnclosures().iterator().next(); 1065 // image.refresh(); 1066 // i.setHidden(true); 1067 } else { 1068 // If a new bitmap is created for a 1069 // frame which already has a bitmap dont 1070 // recreate the bitmap 1071 image = new FrameBitmap((Text) i, 1072 toParse, null); 1073 } 1074 toParse.addItem(image); 1075 } else if (ItemUtils.startsWithTag(i, "@c")) { 1076 // Can only have a @c 1077 if (!i.hasEnclosures() 1078 && i.getLines().size() == 1) { 1079 toParse.addItem(new Circle((Text) i)); 1080 } 1081 // Check for JSItem 1082 } else if(ItemUtils.startsWithTag(i, "@js")) { 1083 toParse.addItem(new JSItem((Text) i)); 1084 // Check for interactive widgets 1085 } else if (ItemUtils.startsWithTag(i, 1086 ItemUtils.TAG_IWIDGET)) { 1087 createWidget(toParse, (Text) i); 1088 } 1089 } 1090 // TODO decide exactly what to do here!! 1091 toParse.addAnnotation((Text) i); 1092 } 1093 } else if (!FrameGraphics.isXRayMode() && i.hasFormula()) { 1094 i.calculate(i.getFormula()); 1095 } 1096 } 1097 } catch (Exception e) { 1098 Logger.Log(e); 1099 e.printStackTrace(); 1100 MessageBay.warningMessage("Exception occured when loading " 1101 + i.getClass().getSimpleName() + "(ID: " + i.getID() 1102 + ") " + e.getMessage() != null ? e.getMessage() : ""); 1103 } 1104 } 1105 1106 /* 1107 * for (Item i : items) { if (i instanceof Dot) { ((Dot) 1108 * i).setPointType(pointtype); ((Dot) i).useFilledPoints(filledPoints); 1109 * } } 1110 */ 1111 1112 FrameIO.ResumeCache(); 1113 1114 toParse.clearOverlays(); 1115 toParse.clearVectors(); 1116 toParse.addAllOverlays(overlays); 1117 toParse.addAllVectors(vectors); 1118 1119 } 1120 1121 /** 1122 * @param vectors 1123 * @param permission 1124 * @param i 1125 */ 1126 private static void addVector(List<Vector> vectors, 1127 UserAppliedPermission defaultPermission, 1128 UserAppliedPermission framePermission, Item i) { 1129 // TODO It is possible to get into an infinate loop if a 1130 // frame contains an @ao which leads to a frame with an 1131 // @v which points back to the frame with the @ao 1132 Frame vector = FrameIO.LoadFrame(i.getAbsoluteLink()); 1133 1134 // Get the permission from off the vector frame 1135 UserAppliedPermission vectorPermission = UserAppliedPermission 1136 .getPermission(vector.getAnnotationValue("permission"), 1137 defaultPermission); 1138 // If the frame permission is lower, use that 1139 vectorPermission = UserAppliedPermission.min(vectorPermission, 1140 framePermission); 1141 // Highest permissable permission for vectors is copy 1142 vectorPermission = UserAppliedPermission.min(vectorPermission, 1143 UserAppliedPermission.copy); 1144 if (vector != null) { 1145 String scaleString = new AttributeValuePair(i.getText()).getValue(); 1146 Float scale = 1F; 1147 try { 1148 scale = Float.parseFloat(scaleString); 1149 } catch (Exception e) { 1150 } 1151 Vector newVector = new Vector(vector, vectorPermission, scale, i); 1152 i.setOverlay(newVector); 1153 i.setVisible(false); 1154 vectors.add(newVector); 1155 } 1156 } 1157 1158 public static Item onItem(float floatX, float floatY, 1159 boolean changeLastEdited) { 1160 return onItem(DisplayIO.getCurrentFrame(), floatX, floatY, 1161 changeLastEdited); 1162 } 1163 1164 /** 1165 * Searches through the list of items on this frame to find one at the given 1166 * x,y coordinates. 1167 * 1168 * @param x 1169 * The x coordinate 1170 * @param y 1171 * The y coordinate 1172 * @return The Item at the given coordinates, or NULL if none is found. 1173 */ 1174 public static Item onItem(Frame toCheck, float floatX, float floatY, 1175 boolean bResetLastEdited) { 1176 // System.out.println("MouseX: " + floatX + " MouseY: " + floatY); 1177 int x = Math.round(floatX); 1178 int y = Math.round(floatY); 1179 if (toCheck == null) 1180 return null; 1181 1182 List<Item> possibles = new ArrayList<Item>(0); 1183 1184 // if the mouse is in the message area 1185 if (y > FrameGraphics.getMaxFrameSize().getHeight()) { 1186 // check the individual message items 1187 for (Item message : MessageBay.getMessages()) { 1188 if (message != null) { 1189 if (message.contains(x, y)) { 1190 message.setOverlayPermission(UserAppliedPermission.copy); 1191 possibles.add(message); 1192 } else { 1193 // Not sure why but if the line below is removed then 1194 // several items can be highlighted at once 1195 message.setHighlightMode(Item.HighlightMode.None); 1196 } 1197 } 1198 } 1199 1200 // check the link to the message frame 1201 if (MessageBay.getMessageLink() != null) { 1202 if (MessageBay.getMessageLink().contains(x, y)) { 1203 MessageBay.getMessageLink().setOverlayPermission( 1204 UserAppliedPermission.copy); 1205 possibles.add(MessageBay.getMessageLink()); 1206 } 1207 } 1208 1209 // this is taken into account in contains 1210 // y -= FrameGraphics.getMaxFrameSize().height; 1211 // otherwise, the mouse is on the frame 1212 } else { 1213 if (LastEdited != null) { 1214 if (LastEdited.contains(x, y) 1215 && !FreeItems.getInstance().contains(LastEdited) 1216 && LastEdited.getParent() == DisplayIO 1217 .getCurrentFrame() 1218 && LastEdited.getParent().getItems() 1219 .contains(LastEdited)) { 1220 LastEdited.setOverlayPermission(UserAppliedPermission.full); 1221 return LastEdited; 1222 } else if (bResetLastEdited) { 1223 setLastEdited(null); 1224 } 1225 } 1226 ArrayList<Item> checkList = new ArrayList<Item>(); 1227 checkList.addAll(toCheck.getInteractableItems()); 1228 checkList.add(toCheck.getNameItem()); 1229 1230 for (Item i : checkList) { 1231 1232 // do not check annotation items in audience mode 1233 //TODO: Upon hover of Rubbish Bin, Undo and Restore Widgets, flickering occurs depending on the mouse distance from a corner. Resolve this. 1234 if (i.isVisible() 1235 && !(FrameGraphics.isAudienceMode() && i.isAnnotation())) { 1236 if(i instanceof WidgetCorner){ 1237 WidgetCorner wc = (WidgetCorner)i; 1238 if(wc.getWidgetSource() instanceof ButtonWidget){ 1239 ButtonWidget bw = (ButtonWidget) wc.getWidgetSource(); 1240 1241 if(bw.getdropInteractableStatus() == true){ 1242 InteractiveWidget iw = wc.getWidgetSource(); 1243 1244 if(iw.getBounds().contains(x, y)){ 1245 1246 if( !FreeItems.getInstance().contains(i)) 1247 { 1248 possibles.add(i); 1249 } 1250 } 1251 } 1252 1253 } 1254 1255 } 1256 1257 if (i.contains(x, y)){ 1258 if( !FreeItems.getInstance().contains(i)) 1259 { 1260 possibles.add(i); 1261 } 1262 } 1263 1264 } 1265 } 1266 } 1267 1268 // if there are no possible items, return null 1269 if (possibles.size() == 0) 1270 return null; 1271 1272 // if there is only one possibility, return it 1273 if (possibles.size() == 1) 1274 return possibles.get(0); 1275 1276 // return closest x,y pair to mouse 1277 Item closest = possibles.get(0); 1278 int distance = (int) Math.round(Math.sqrt(Math.pow( 1279 Math.abs(closest.getX() - x), 2) 1280 + Math.pow(Math.abs(closest.getY() - y), 2))); 1281 1282 for (Item i : possibles) { 1283 int d = (int) Math.round(Math.sqrt(Math.pow(Math.abs(i.getX() - x), 1284 2) + Math.pow(Math.abs(i.getY() - y), 2))); 1285 1286 // System.out.println(d); 1287 if (d <= distance) { 1288 distance = d; 1289 1290 // dots take precedence over lines 1291 if ((!(closest instanceof Dot && i instanceof Line)) 1292 && (!(closest instanceof Text && i instanceof Line))) 1293 closest = i; 1294 1295 } 1296 1297 } 1298 1299 return closest; 1300 } 1301 1302 public synchronized static Item getCurrentItem() { 1303 return onItem(DisplayIO.getCurrentFrame(), DisplayIO.getMouseX(), 1304 FrameMouseActions.getY(), true); 1305 } 1306 1307 public static Polygon getEnlosingPolygon() { 1308 Collection<Item> enclosure = getEnclosingLineEnds(); 1309 if (enclosure == null || enclosure.size() == 0) 1310 return null; 1311 1312 return enclosure.iterator().next().getEnclosedShape(); 1313 } 1314 1315 /** 1316 * 1317 * @param currentItem 1318 * @return 1319 */ 1320 public static Collection<Item> getCurrentItems() { 1321 return getCurrentItems(getCurrentItem()); 1322 } 1323 1324 public static Collection<Item> getCurrentItems(Item currentItem) { 1325 1326 Collection<Item> enclosure = getEnclosingLineEnds(); 1327 if (enclosure == null || enclosure.size() == 0) 1328 return null; 1329 1330 Item firstItem = enclosure.iterator().next(); 1331 1332 Collection<Item> enclosed = getItemsEnclosedBy( 1333 DisplayIO.getCurrentFrame(), firstItem.getEnclosedShape()); 1334 1335 // Brook: enclosed widgets are to be fully enclosed, never partially 1336 /* 1337 * MIKE says: but doesnt this mean that widgets are treated differently 1338 * from ALL other object which only need to be partially enclosed to be 1339 * picked up 1340 */ 1341 List<InteractiveWidget> enclosedWidgets = new LinkedList<InteractiveWidget>(); 1342 for (Item i : enclosed) { 1343 // Don't want to lose the highlighting from the current item 1344 if (i == currentItem || enclosure.contains(i)) { 1345 continue; 1346 } 1347 // Don't want to lose the highlighting of connected Dots 1348 if (i instanceof Dot 1349 && i.getHighlightMode() == HighlightMode.Connected) { 1350 for (Line l : i.getLines()) { 1351 if (l.getOppositeEnd(i).getHighlightMode() == HighlightMode.Normal) { 1352 continue; 1353 } 1354 } 1355 } 1356 if (i instanceof WidgetCorner) { 1357 if (!enclosedWidgets.contains(((WidgetCorner) i) 1358 .getWidgetSource())) 1359 enclosedWidgets.add(((WidgetCorner) i).getWidgetSource()); 1360 } 1361 i.setHighlightMode(Item.HighlightMode.None); 1362 } 1363 1364 for (InteractiveWidget iw : enclosedWidgets) { 1365 for (Item i : iw.getItems()) { 1366 if (!enclosed.contains(i)) { 1367 enclosed.add(i); 1368 } 1369 } 1370 } 1371 1372 return enclosed; 1373 } 1374 1375 public static Collection<Item> getEnclosingLineEnds() { 1376 return getEnclosingLineEnds(new Point(DisplayIO.getMouseX(), 1377 FrameMouseActions.getY())); 1378 } 1379 1380 public static Collection<Item> getEnclosingLineEnds(Point position) { 1381 // update enclosed shapes 1382 Frame current = DisplayIO.getCurrentFrame(); 1383 List<Item> items = current.getItems(); 1384 1385 // Remove all items that are connected to freeItems 1386 List<Item> freeItems = new ArrayList<Item>(FreeItems.getInstance()); 1387 while (freeItems.size() > 0) { 1388 Item item = freeItems.get(0); 1389 Collection<Item> connected = item.getAllConnected(); 1390 items.removeAll(connected); 1391 freeItems.removeAll(connected); 1392 } 1393 1394 List<Item> used = new ArrayList<Item>(0); 1395 1396 while (items.size() > 0) { 1397 Item i = items.get(0); 1398 items.remove(i); 1399 if (i.isEnclosed()) { 1400 Polygon p = i.getEnclosedShape(); 1401 if (p.contains(position.x, position.y)) { 1402 used.add(i); 1403 items.removeAll(i.getEnclosingDots()); 1404 } 1405 } 1406 } 1407 1408 if (used.size() == 0) 1409 return null; 1410 1411 // if there is only one possibility, return it 1412 if (used.size() == 1) { 1413 return used.get(0).getEnclosingDots(); 1414 // otherwise, determine which polygon is closest to the cursor 1415 } else { 1416 Collections.sort(used, new Comparator<Item>() { 1417 public int compare(Item d1, Item d2) { 1418 Polygon p1 = d1.getEnclosedShape(); 1419 Polygon p2 = d2.getEnclosedShape(); 1420 1421 int closest = Integer.MAX_VALUE; 1422 int close2 = Integer.MAX_VALUE; 1423 1424 int mouseX = DisplayIO.getMouseX(); 1425 int mouseY = FrameMouseActions.getY(); 1426 1427 for (int i = 0; i < p1.npoints; i++) { 1428 int diff = Math.abs(p1.xpoints[i] - mouseX) 1429 + Math.abs(p1.ypoints[i] - mouseY); 1430 int diff2 = Integer.MAX_VALUE; 1431 1432 if (i < p2.npoints) 1433 diff2 = Math.abs(p2.xpoints[i] - mouseX) 1434 + Math.abs(p2.ypoints[i] - mouseY); 1435 1436 if (diff < Math.abs(closest)) { 1437 close2 = closest; 1438 closest = diff; 1439 } else if (diff < Math.abs(close2)) 1440 close2 = diff; 1441 1442 if (diff2 < Math.abs(closest)) { 1443 close2 = closest; 1444 closest = -diff2; 1445 } else if (diff2 < Math.abs(close2)) 1446 close2 = diff2; 1447 } 1448 1449 if (closest > 0 && close2 > 0) 1450 return -10; 1451 1452 if (closest < 0 && close2 < 0) 1453 return 10; 1454 1455 if (closest > 0) 1456 return -10; 1457 1458 return 10; 1459 } 1460 1461 }); 1462 1463 return used.get(0).getEnclosingDots(); 1464 } 1465 } 1466 1467 // TODO Remove this method!! 1468 // Can just getItemsWithin be used? 1469 public static Collection<Item> getItemsEnclosedBy(Frame frame, Polygon poly) { 1470 Collection<Item> contained = frame.getItemsWithin(poly); 1471 1472 Collection<Item> results = new LinkedHashSet<Item>(contained.size()); 1473 1474 // check for correct permissions 1475 for (Item item : contained) { 1476 // if the item is on the frame 1477 if (item.getParent() == frame || item.getParent() == null) { 1478 // item.Permission = Permission.full; 1479 results.add(item); 1480 // otherwise, it must be on an overlay frame 1481 } else { 1482 for (Overlay overlay : frame.getOverlays()) { 1483 if (overlay.Frame == item.getParent()) { 1484 item.setOverlayPermission(overlay.permission); 1485 results.add(item); 1486 break; 1487 } 1488 } 1489 } 1490 } 1491 1492 return results; 1493 } 1494 1495 /** 1496 * Fills the given Frame with default profile tags 1497 */ 1498 public static void CreateDefaultProfile(String username, Frame profile) { 1499 Text title = profile.getTitleItem(); 1500 if (username.equals(UserSettings.DEFAULT_PROFILE_NAME)) { 1501 title.setText("Default Profile Frame"); 1502 } else { 1503 // if this profile is not the default profile, copy it from the default profile instead of generating a new profile 1504 // (this allows the possibility of modifying the default profile and having any new profiles get those modifications) 1505 Frame nextDefault = FrameIO.LoadProfile(UserSettings.DEFAULT_PROFILE_NAME); 1506 if (nextDefault == null) { 1507 try { 1508 nextDefault = FrameIO.CreateNewProfile(UserSettings.DEFAULT_PROFILE_NAME); 1509 } catch (Exception e) { 1510 // TODO tell the user that there was a problem creating the 1511 // profile frame and close nicely 1512 e.printStackTrace(); 1513 } 1514 } 1515 // load profile frame and set title correctly 1516 profile.reset(); 1517 profile.removeAllItems(profile.getAllItems()); 1518 // set relative link on all items so their links will correctly point to the page on the current profile rather than on the default profile 1519 for(Item i : nextDefault.getAllItems()) { 1520 i.setRelativeLink(); 1521 } 1522 profile.addAllItems(ItemUtils.CopyItems(nextDefault.getAllItems())); 1523 profile.setTitle(username + "'s Profile Frame"); 1524 FrameIO.SaveFrame(profile); 1823 if(!force && check.exists()) return; 1525 1824 1526 Frame nextProfile = profile; 1527 MessageBay.suppressMessages(true); 1528 while((nextDefault = FrameIO.LoadNext(nextDefault)) != null) { 1529 // in case there are gaps in the frame numbering of the default profile (e.g. if a user has edited it), 1530 // we need to replicate those gaps in the copied profile so the links will work correctly 1531 while(nextProfile.getNumber() < nextDefault.getNumber()) { 1532 nextProfile = FrameIO.CreateFrame(profile.getFramesetName(), null, null); 1533 } 1534 // if the new profile has a frame number higher than the current frame number in the default profile, 1535 // the new profile must already exist, so just exit 1536 // (TODO: should we wipe the frames instead?) 1537 if(nextProfile.getNumber() > nextDefault.getNumber()) { 1538 break; 1539 } 1540 nextProfile.reset(); 1541 nextProfile.removeAllItems(nextProfile.getAllItems()); 1542 // set relative link on all items so their links will correctly point to the page on the current profile rather than on the default profile 1543 for(Item i : nextDefault.getAllItems()) { 1544 i.setRelativeLink(); 1545 } 1546 nextProfile.addAllItems(ItemUtils.CopyItems(nextDefault.getAllItems())); 1547 FrameIO.SaveFrame(nextProfile); 1548 } 1549 MessageBay.suppressMessages(false); 1825 System.out.println("Extracting/Installing resources:"); 1550 1826 1551 return;1552 }1553 1554 // int spacing = 50;1555 final int intialYPos = 75;1556 int xPos = 75;1557 int yPos = intialYPos;1558 1559 // yPos += spacing;1560 // profile.addText(xPos, yPos, "@HomeFrame", null, profile.getName());1561 // yPos += spacing;1562 // String defaultFrameName = profile.getFramesetName() + "0";1563 // profile.addText(xPos, yPos, "@DefaultFrame", null, defaultFrameName);1564 // yPos += spacing;1565 //1566 // profile.addText(xPos, yPos, "@InitialWidth: "1567 // + UserSettings.InitialWidth, null);1568 // yPos += spacing;1569 //1570 // profile.addText(xPos, yPos, "@InitialHeight: "1571 // + UserSettings.InitialHeight, null);1572 // yPos += spacing;1573 //1574 // Text t = profile.addText(xPos, yPos, "@ItemTemplate", null);1575 // t.setColor(null);1576 //1577 // yPos += spacing;1578 // t = profile.addText(xPos, yPos, "@AnnotationTemplate", null);1579 // t.setColor(Color.gray);1580 //1581 // yPos += spacing;1582 // t = profile.addText(xPos, yPos, "@CommentTemplate", null);1583 // t.setColor(Color.green.darker());1584 //1585 // yPos += spacing;1586 // t = profile.addText(xPos, yPos, "@StatsTemplate", null);1587 // t.setColor(Color.BLACK);1588 // t.setBackgroundColor(new Color(0.9F, 0.9F, 0.9F));1589 // t.setFamily(Text.MONOSPACED_FONT);1590 // t.setSize(14);1591 1592 Text t;1593 1594 xPos = 300;1595 // yPos = intialYPos + spacing;1596 yPos = 100;1597 1598 // Add documentation links1599 File helpDirectory = new File(FrameIO.HELP_PATH);1600 if (helpDirectory != null) {1601 File[] helpFramesets = helpDirectory.listFiles();1602 if (helpFramesets != null) {1603 1604 // Add the title for the help index1605 Text help = profile.addText(xPos, yPos, "@Expeditee Help", null);1606 help.setSize(25);1607 help.setFontStyle("Bold");1608 help.setFamily("SansSerif");1609 help.setColor(TemplateSettings.ColorWheel.get()[3]);1610 1611 xPos += 25;1612 System.out.println("Installing frameset: ");1613 1614 boolean first_item = true;1615 1616 for (File helpFrameset : helpFramesets) {1617 String framesetName = helpFrameset.getName();1618 if (!FrameIO.isValidFramesetName(framesetName)) {1619 continue;1620 }1621 1622 if (first_item) {1623 System.out.print(" " + framesetName);1624 first_item = false;1625 }1626 else {1627 System.out.print(", " + framesetName);1628 }1629 System.out.flush();1630 1631 Frame indexFrame = FrameIO.LoadFrame(framesetName + '1');1632 // Look through the folder for help index pages1633 if (indexFrame != null1634 && ItemUtils.FindTag(indexFrame.getItems(),1635 "@HelpIndex") != null) {1636 // yPos += spacing;1637 yPos += 30;1638 t = profile.addText(xPos, yPos,1639 '@' + indexFrame.getFramesetName(), null);1640 t.setLink(indexFrame.getName());1641 t.setColor(Color.gray);1642 }1643 }1644 System.out.println();1645 }1646 }1647 1648 xPos = 50;1649 yPos = 100;1650 1651 // Populate Start Pages and Settings1652 File framesetDirectory = new File(FrameIO.FRAME_PATH);1653 1654 if (framesetDirectory.exists()) {1655 File[] startpagesFramesets = framesetDirectory.listFiles();1656 1657 if (startpagesFramesets != null) {1658 // Add Start Page title1659 Text templates = profile.addText(xPos, yPos, "@Start Pages",1660 null);1661 templates.setSize(25);1662 templates.setFontStyle("Bold");1663 templates.setFamily("SansSerif");1664 templates.setColor(TemplateSettings.ColorWheel.get()[3]);1665 1666 xPos += 25;1667 1668 // Start Pages should be the first frame in its own frameset +1669 // frameset name should be present in FrameUtils.startPages[].1670 for (File startpagesFrameset : startpagesFramesets) {1671 String framesetName = startpagesFrameset.getName();1672 1673 // Only add link if frameset is a startpage1674 for (int i = 0; i < startPages.length; i++) {1675 if (framesetName.equals(startPages[i])) {1676 Frame indexFrame = FrameIO1677 .LoadFrame(framesetName + '1');1678 1679 // Add start page link1680 if (indexFrame != null) {1681 yPos += 30;1682 t = profile.addText(xPos, yPos,1683 '@' + indexFrame.getFramesetName(),1684 null);1685 t.setLink(indexFrame.getName());1686 t.setColor(Color.gray);1687 }1688 }1689 }1690 }1691 }1692 }1693 1694 FrameIO.SaveFrame(profile);1695 1696 // Populate settings frameset1697 Settings.Init();1698 t = profile.addText(550, 100, "@Settings", null);1699 t.setSize((float) 25.0);1700 t.setFamily("SansSerif");1701 t.setFontStyle("Bold");1702 t.setColor(Color.gray);1703 Settings.generateSettingsTree(t);1704 1705 FrameIO.SaveFrame(profile);1706 }1707 1708 private static void checkTDFCItemWaiting(Frame currentFrame) {1709 Item tdfcItem = FrameUtils.getTdfcItem();1710 // if there is a TDFC Item waiting1711 if (tdfcItem != null) {1712 boolean change = currentFrame.hasChanged();1713 boolean saved = currentFrame.isSaved();1714 // Save the parent of the item if it has not been saved1715 if (!change && !saved) {1716 tdfcItem.setLink(null);1717 tdfcItem.getParent().setChanged(true);1718 FrameIO.SaveFrame(tdfcItem.getParent());1719 FrameGraphics.Repaint();1720 } else {1721 SessionStats.CreatedFrame();1722 }1723 1724 setTdfcItem(null);1725 }1726 }1727 1728 public static void setTdfcItem(Item _tdfcItem) {1729 FrameUtils._tdfcItem = _tdfcItem;1730 }1731 1732 public static Item getTdfcItem() {1733 return FrameUtils._tdfcItem;1734 }1735 1736 private static Item _tdfcItem = null;1737 1738 public static void setLastEdited(Text lastEdited) {1739 1740 // If the lastEdited is being changed then check if its @i1741 Frame toReparse = null;1742 Frame toRecalculate = null;1743 Frame toUpdateObservers = null;1744 1745 if (LastEdited == null) {1746 // System.out.print("N");1747 } else if (LastEdited != null) {1748 // System.out.print("T");1749 Frame parent = LastEdited.getParentOrCurrentFrame();1750 1751 if (lastEdited != LastEdited) {1752 if (LastEdited.startsWith("@i")) {1753 // Check if its an image that can be resized to fit a box1754 // around it1755 String text = LastEdited.getText();1756 if (text.startsWith("@i:")1757 && !Character1758 .isDigit(text.charAt(text.length() - 1))) {1759 Collection<Item> enclosure = FrameUtils1760 .getEnclosingLineEnds(LastEdited.getPosition());1761 if (enclosure != null) {1762 for (Item i : enclosure) {1763 if (i.isLineEnd() && i.isEnclosed()) {1764 DisplayIO.getCurrentFrame().removeAllItems(1765 enclosure);1766 Rectangle rect = i.getEnclosedRectangle();1767 LastEdited1768 .setText(LastEdited.getText()1769 + " "1770 + Math.round(rect1771 .getWidth()));1772 LastEdited.setPosition(new Point(rect.x,1773 rect.y));1774 LastEdited.setThickness(i.getThickness());1775 LastEdited.setBorderColor(i.getColor());1776 break;1777 }1778 }1779 FrameMouseActions.deleteItems(enclosure, false);1780 }1781 }1782 toReparse = parent;1783 } else if (LastEdited.recalculateWhenChanged()) {1784 toRecalculate = parent;1785 }1786 1787 if (parent.hasObservers()) {1788 toUpdateObservers = parent;1789 }1790 // Update the formula if in XRay mode1791 if (FrameGraphics.isXRayMode() && LastEdited.hasFormula()) {1792 LastEdited.setFormula(LastEdited.getText());1793 }1794 }1795 if (lastEdited != LastEdited && LastEdited.getText().length() == 0) {1796 parent.removeItem(LastEdited);1797 }1798 }1799 LastEdited = lastEdited;1800 1801 if (!FrameGraphics.isXRayMode()) {1802 if (toReparse != null) {1803 Parse(toReparse, false, false);1804 } else {1805 if (toRecalculate != null) {1806 toRecalculate.recalculate();1807 }1808 1809 if (toUpdateObservers != null) {1810 toUpdateObservers.notifyObservers(false);1811 }1812 }1813 }1814 }1815 1816 /**1817 * Extracts files/folders from the assets/resources folder directly into1818 * ${PARENT_FOLDER} (~/.expeditee)1819 *1820 * @param force if true, resources will be extracted even if they have already been extracted before1821 */1822 public static void extractResources(boolean force) {1823 File check = new File(FrameIO.PARENT_FOLDER + ".res");1824 if(!force && check.exists()) {1825 return;1826 }1827 System.out.println("Extracting/Installing resources:");1828 1827 try { 1829 1828 check.getParentFile().mkdirs(); 1830 1831 1829 check.createNewFile(); 1830 1832 1831 ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 1833 1832 URL docURL = classLoader.getResource("org/expeditee/assets/resources"); 1834 1833 1835 1834 // copy files from the jar file to the profile folder 1836 1835 if (docURL.getProtocol().equals("jar")) { … … 1840 1839 String res = "org/expeditee/assets/resources/"; 1841 1840 int resLength = res.length(); 1842 1841 1843 1842 ZipEntry ze; 1844 1843 1845 1844 while(jarEntries.hasMoreElements()) { 1846 1845 ze = jarEntries.nextElement(); … … 1850 1849 File out = new File(FrameIO.PARENT_FOLDER + ze.getName().substring(resLength)); 1851 1850 // System.out.println("Didn't crash here " + out.getPath()); 1852 // if(out.exists()) {1853 // continue;1854 // }1851 // if(out.exists()) { 1852 // continue; 1853 // } 1855 1854 if(ze.isDirectory()) { 1856 1855 // System.out.println(out.getPath() + " IS DIRECTORY"); … … 1881 1880 } 1882 1881 } 1883 1884 // Copy files from the source folder to the profile folder1882 1883 // Copy files from the source folder to the profile folder 1885 1884 } else if (docURL.getProtocol().equals("bundleresource")) { 1886 1885 final URLConnection urlConnection = docURL.openConnection(); … … 1899 1898 } 1900 1899 1901 private static void extractResourcesFromFolder(File folder) throws IOException { 1902 LinkedList<File> items = new LinkedList<File>(); 1903 items.addAll(Arrays.asList(folder.listFiles())); 1904 LinkedList<File> files = new LinkedList<File>(); 1905 String res = "org" + File.separator + "expeditee" + File.separator + "assets" + File.separator + "resources"; 1906 int resLength = res.length(); 1907 1908 while (items.size() > 0) { 1909 File file = items.remove(0); 1910 if(file.isFile()) { 1911 if(!file.getName().contains(".svn")) { 1912 files.add(file); 1913 } 1914 } else { 1915 if (!file.getName().contains(".svn")) { 1916 items.addAll(Arrays.asList(file.listFiles())); 1917 } 1918 } 1919 } 1920 for (File file : files) { 1921 System.out.println(file.getPath()); 1922 File out = new File(FrameIO.PARENT_FOLDER + file.getPath().substring(file.getPath().indexOf(res) + resLength)); 1923 // if(out.exists()) { 1924 // continue; 1925 // } 1926 copyFile(file, out, true); 1927 } 1928 } 1929 1930 /** 1931 * @param src 1932 * @param dst 1933 * @throws IOException 1934 */ 1935 public static void copyFile(File src, File dst, boolean overWrite) throws IOException { 1936 if(!overWrite && dst.exists()) 1937 return; 1938 dst.getParentFile().mkdirs(); 1900 private static void extractResourcesFromFolder(File folder) throws IOException 1901 { 1902 LinkedList<File> items = new LinkedList<File>(); 1903 items.addAll(Arrays.asList(folder.listFiles())); 1904 LinkedList<File> files = new LinkedList<File>(); 1905 String res = "org" + File.separator + "expeditee" + File.separator + "assets" + File.separator + "resources"; 1906 int resLength = res.length(); 1907 1908 while (items.size() > 0) { 1909 File file = items.remove(0); 1910 if(file.isFile()) { 1911 if(!file.getName().contains(".svn")) { 1912 files.add(file); 1913 } 1914 } else { 1915 if (!file.getName().contains(".svn")) { 1916 items.addAll(Arrays.asList(file.listFiles())); 1917 } 1918 } 1919 } 1920 for (File file : files) { 1921 System.out.println(file.getPath()); 1922 File out = new File(FrameIO.PARENT_FOLDER + file.getPath().substring(file.getPath().indexOf(res) + resLength)); 1923 // if(out.exists()) { 1924 // continue; 1925 // } 1926 copyFile(file, out, true); 1927 } 1928 } 1929 1930 /** 1931 * @param src 1932 * @param dst 1933 * @throws IOException 1934 */ 1935 public static void copyFile(File src, File dst, boolean overWrite) throws IOException 1936 { 1937 if(!overWrite && dst.exists()) return; 1938 1939 dst.getParentFile().mkdirs(); 1939 1940 FileOutputStream fOut = null; 1940 1941 FileInputStream fIn = null; … … 1959 1960 } 1960 1961 } 1961 } 1962 1963 public static Text getLastEdited() { 1964 return LastEdited; 1965 } 1966 1967 public static Collection<Text> getCurrentTextItems() { 1968 Collection<Text> currentTextItems = new LinkedHashSet<Text>(); 1969 Collection<Item> currentItems = getCurrentItems(null); 1970 if (currentItems != null) { 1971 for (Item i : getCurrentItems(null)) { 1972 if (i instanceof Text && !i.isLineEnd()) { 1973 currentTextItems.add((Text) i); 1974 } 1975 } 1976 } 1977 return currentTextItems; 1978 } 1962 } 1963 1964 public static Text getLastEdited() 1965 { 1966 return LastEdited; 1967 } 1968 1969 public static Collection<Text> getCurrentTextItems() 1970 { 1971 Collection<Text> currentTextItems = new LinkedHashSet<Text>(); 1972 Collection<Item> currentItems = getCurrentItems(null); 1973 if (currentItems != null) { 1974 for (Item i : getCurrentItems(null)) { 1975 if (i instanceof Text && !i.isLineEnd()) { 1976 currentTextItems.add((Text) i); 1977 } 1978 } 1979 } 1980 return currentTextItems; 1981 } 1979 1982 } -
trunk/src/org/expeditee/gui/FreeItems.java
r919 r1102 19 19 package org.expeditee.gui; 20 20 21 import java.awt.Polygon;22 21 import java.util.ArrayList; 23 22 import java.util.Collection; … … 29 28 import java.util.Map; 30 29 30 import org.expeditee.core.bounds.PolygonBounds; 31 31 import org.expeditee.items.Dot; 32 32 import org.expeditee.items.Item; … … 42 42 private static FreeItems _cursor = new FreeItems(); 43 43 44 private FreeItems() { 45 } 46 47 public static FreeItems getCursor() { 44 public static FreeItems getCursor() 45 { 48 46 return _cursor; 49 47 } 50 48 51 public static FreeItems getInstance() { 49 public static FreeItems getInstance() 50 { 52 51 return _instance; 53 52 } 54 53 55 @Override 56 public void clear() { 54 /** Singleton class (although there are two of them). */ 55 private FreeItems() 56 { 57 } 58 59 @Override 60 public void clear() 61 { 57 62 for (Item i : this) { 58 63 i.invalidateAll(); … … 63 68 64 69 @Override 65 public Item remove(int index) { 70 public Item remove(int index) 71 { 66 72 Item i = get(index); 67 73 remove(i); … … 70 76 71 77 @Override 72 public boolean remove(Object o) { 78 public boolean remove(Object o) 79 { 73 80 if (o instanceof Item) { 74 81 ((Item) o).invalidateAll(); 75 82 ((Item) o).invalidateFill(); 76 83 } 84 77 85 return super.remove(o); 78 86 } … … 84 92 * @return true if at least one item is attached to the cursor. 85 93 */ 86 public static boolean itemsAttachedToCursor() { 94 public static boolean hasItemsAttachedToCursor() 95 { 87 96 return getInstance().size() > 0; 88 97 } … … 94 103 * attached are text items. 95 104 */ 96 public static boolean textOnlyAttachedToCursor() {97 if (!itemsAttachedToCursor())98 99 for (Item i : getInstance()) {100 if (!(i instanceof Text)) {101 102 103 }105 public static boolean textOnlyAttachedToCursor() 106 { 107 if (!hasItemsAttachedToCursor()) return false; 108 109 for (Item i : getInstance()) { 110 if (!(i instanceof Text)) return false; 111 } 112 104 113 return true; 105 114 } 106 115 107 public static Item getItemAttachedToCursor() { 108 if (itemsAttachedToCursor()) 109 return getInstance().get(0); 116 public static Item getItemAttachedToCursor() 117 { 118 if (hasItemsAttachedToCursor()) return getInstance().get(0); 119 110 120 return null; 111 121 } 112 122 113 public static Text getTextAttachedToCursor() { 114 if (textOnlyAttachedToCursor()) 115 return (Text) getInstance().get(0); 123 public static Text getTextAttachedToCursor() 124 { 125 if (textOnlyAttachedToCursor()) return (Text) getInstance().get(0); 126 116 127 return null; 117 128 } … … 121 132 * @return the list of free text items 122 133 */ 123 public static Collection<Text> getTextItems() { 134 public static Collection<Text> getTextItems() 135 { 124 136 Collection<Text> textItems = new LinkedList<Text>(); 125 for (Item i : getInstance()) { 126 if (i instanceof Text) { 127 textItems.add((Text) i); 128 } 137 138 for (Item i : getInstance()) { 139 if (i instanceof Text) textItems.add((Text) i); 129 140 } 130 141 … … 132 143 } 133 144 134 public static Map<String, Collection<String>> getGroupedText() { 145 public static Map<String, Collection<String>> getGroupedText() 146 { 135 147 Map<String, Collection<String>> groupedText = new HashMap<String, Collection<String>>(); 148 136 149 // Go throught the lineEnds 137 150 Collection<Item> addedItems = new HashSet<Item>(); 138 151 for (Item i : getInstance()) { 139 if (!(i instanceof Text) || !i.isLineEnd()) { 140 continue; 141 } 152 if (!(i instanceof Text) || !i.isLineEnd()) continue; 153 142 154 // Check for text inside the box 143 155 Collection<String> textList = new LinkedList<String>(); … … 146 158 addedItems.add(enclosed); 147 159 } 160 148 161 if (textList.size() > 0) { 149 162 groupedText.put(i.getText(), textList); 150 163 } 151 164 } 165 152 166 // Now add the items that were not contained in any of the boxes 153 167 Collection<String> outsideList = new LinkedList<String>(); … … 157 171 } 158 172 } 173 159 174 groupedText.put("", outsideList); 160 175 … … 169 184 * @return 170 185 */ 171 private Collection<Text> getTextWithin(Item lineEnd) { 172 Polygon poly = lineEnd.getEnclosedShape(); 186 private Collection<Text> getTextWithin(Item lineEnd) 187 { 188 PolygonBounds poly = lineEnd.getEnclosedShape(); 189 173 190 Collection<Text> results = new LinkedHashSet<Text>(); 174 191 for (Item i : this) { … … 177 194 } 178 195 } 196 179 197 return results; 180 198 } 181 199 182 public static boolean hasCursor() { 200 public static boolean hasCursor() 201 { 183 202 return getCursor().size() > 0; 184 203 } 185 204 186 public static void setCursor(Collection<Item> cursor) { 205 public static void setCursor(Collection<Item> cursor) 206 { 187 207 _cursor.clear(); 188 208 _cursor.addAll(cursor); 189 209 } 190 210 191 public static boolean hasMultipleVisibleItems() { 211 public static boolean hasMultipleVisibleItems() 212 { 192 213 List<Item> toCount = new LinkedList<Item>(getInstance()); 214 193 215 int c = 0; 194 216 while(!toCount.isEmpty()) { … … 199 221 } 200 222 } 223 201 224 return false; 202 225 } 203 226 204 public static boolean isDrawingPolyLine() { 227 public static boolean isDrawingPolyLine() 228 { 205 229 List<Item> tmp = getInstance(); 230 206 231 return tmp.size() == 2 && tmp.get(0) instanceof Dot && tmp.get(1) instanceof Line; 207 232 } 233 234 /** 235 * Checks if lines are being rubber banded. 236 * 237 * @return true if the user is rubberBanding one or more lines 238 */ 239 public static boolean rubberBanding() 240 { 241 if (getInstance().size() != 2) return false; 242 243 // if rubber-banding, there will be 1 line end and the rest will be lines 244 boolean foundLineEnd = false; 245 for (Item i : getInstance()) { 246 if (i.isLineEnd()) { 247 if (foundLineEnd) return false; 248 foundLineEnd = true; 249 } else if (!(i instanceof Line) || !i.isVisible()) { 250 return false; 251 } 252 } 253 254 return true; 255 } 256 257 @Override 258 public FreeItems clone() 259 { 260 FreeItems ret = new FreeItems(); 261 ret.addAll(this); 262 return ret; 263 } 208 264 } -
trunk/src/org/expeditee/gui/FunctionKey.java
r919 r1102 19 19 package org.expeditee.gui; 20 20 21 / /these numbers correspond to the Function Key numbers (0 = Escape key)21 /** Enumerates the Function Key numbers (0 = Escape key) */ 22 22 public enum FunctionKey { 23 DropDown, SizeUp, SizeDown, ChangeColor, ToggleAnnotation, InsertDate, NewFrameset, ChangeFontStyle, ChangeFontFamily, 24 AudienceMode, XRayMode, Save, Refresh; 23 DropDown, 24 SizeUp, 25 SizeDown, 26 ChangeColor, 27 ToggleAnnotation, 28 InsertDate, 29 NewFrameset, 30 ChangeFontStyle, 31 ChangeFontFamily, 32 AudienceMode, 33 XRayMode, 34 Save, 35 Refresh 25 36 } -
trunk/src/org/expeditee/gui/Help.java
r919 r1102 26 26 import org.expeditee.items.Picture; 27 27 import org.expeditee.items.Text; 28 import org.expeditee.items.widgets. InteractiveWidget;28 import org.expeditee.items.widgets.Widget; 29 29 import org.expeditee.items.widgets.WidgetCorner; 30 30 import org.expeditee.items.widgets.WidgetEdge; 31 31 import org.expeditee.settings.experimental.ExperimentalFeatures; 32 33 32 34 33 public class Help { … … 120 119 if((mod & shift) == 0)return "Extend line"; 121 120 break; 121 default: 122 break; 122 123 } 123 124 if((other & cursor) != 0) return "Stamp copy"; … … 152 153 } 153 154 break; 155 default: 156 break; 154 157 } 155 158 return "Delete"; … … 165 168 if((other & cursor) == 0) return "Select text region"; 166 169 break; 170 default: 171 break; 167 172 } 168 173 return null; … … 174 179 case text: 175 180 if((other & cursor) == 0) return "Cut text region"; 181 default: 182 break; 176 183 } 177 184 return null; … … 187 194 case text: 188 195 if((other & cursor) == 0) return "Copy text region"; 196 default: 197 break; 189 198 } 190 199 return null; … … 192 201 193 202 194 public static void updateStatus() { 203 public static void updateStatus(boolean controlDown, boolean shiftDown) 204 { 195 205 Item current = FrameUtils.getCurrentItem(); 196 206 Collection<Item> currents; 197 207 Context context; 198 InteractiveWidget iw = null;208 Widget iw = null; 199 209 if(current != null) { 200 210 if(current instanceof Line) { … … 232 242 } 233 243 } 234 int mod = ( FrameMouseActions.isControlDown() ? control : 0) | (FrameMouseActions.isShiftDown()? shift : 0);244 int mod = (controlDown ? control : 0) | (shiftDown ? shift : 0); 235 245 int other = (ExperimentalFeatures.MousePan.get() ? panning : 0) | 236 246 (current != null && current.hasAction() ? action : 0)| 237 247 (current != null && current.hasLink() ? link : 0) | 238 (FreeItems. itemsAttachedToCursor() ? cursor : 0);248 (FreeItems.hasItemsAttachedToCursor() ? cursor : 0); 239 249 String status = ""; 240 250 … … 264 274 } 265 275 266 267 276 MessageBay.setStatus(status); 268 277 } -
trunk/src/org/expeditee/gui/MessageBay.java
r929 r1102 19 19 package org.expeditee.gui; 20 20 21 import java.awt.Color;22 import java.awt.Font;23 import java.awt.Graphics;24 import java.awt.Graphics2D;25 import java.awt.GraphicsEnvironment;26 import java.awt.Rectangle;27 import java.awt.RenderingHints;28 import java.awt.geom.Area;29 import java.awt.image.VolatileImage;30 21 import java.util.LinkedList; 31 22 import java.util.List; 32 23 24 import org.expeditee.Util; 33 25 import org.expeditee.actions.Misc; 26 import org.expeditee.core.Clip; 27 import org.expeditee.core.Colour; 28 import org.expeditee.core.Dimension; 29 import org.expeditee.core.Font; 30 import org.expeditee.core.Image; 31 import org.expeditee.gio.EcosystemManager; 32 import org.expeditee.gio.GraphicsManager; 34 33 import org.expeditee.items.Item; 35 34 import org.expeditee.items.Text; 36 35 37 36 /** 38 * The bay at the bottom of the expeditee browser which displays messages. TODO 39 * make it thread safe! 40 * 37 * The bay at the bottom of the expeditee browser which displays messages. 38 * TODO: Make it thread safe! 41 39 */ 42 40 public final class MessageBay { 43 41 44 45 public static final int MESSAGE_BUFFER_HEIGHT = 105; 46 42 /** The distance from the top of the message bay to the Message frame link. */ 47 43 private static final int MESSAGE_LINK_Y_OFFSET = 100; 48 44 45 /** TODO: Comment. cts16 */ 49 46 private static final int MESSAGE_LINK_X = 50; 50 47 51 public static final Color ERROR_COLOR = Color.red; 52 48 /** TODO: Comment. cts16 */ 49 public static final Colour ERROR_COLOR = Colour.RED; 50 51 /** TODO: Comment. cts16 */ 53 52 public static final String MESSAGES_FRAMESET_NAME = "Messages"; 54 53 55 / / messages shown in the message window54 /** The list of messages shown in the message bay. */ 56 55 private static List<Item> _messages = new LinkedList<Item>(); 56 57 /** Messages which were delayed because they couldn't be shown at time of creation. */ 58 private static List<DelayedMessage> _delayedMessages = new LinkedList<DelayedMessage>(); 59 60 /** TODO: Comment. cts16 */ 57 61 private static Text _status = null; 58 62 59 / / buffer of the message window60 private static VolatileImage _messageBuffer = null;61 62 / / creator for creating the message frames63 /** Buffer image of the message window. */ 64 private static Image _messageBuffer = null; 65 66 /** Creator for creating the message frames. */ 63 67 private static FrameCreator _creator = null; 64 68 65 / / font used for the messages66 private static Font _messageFont = Font.decode("Serif-Plain-16");67 68 / / the number of messages currently shown (used for scrolling up)69 /** Font used for the messages. */ 70 private static Font _messageFont = new Font("Serif-Plain-16"); 71 72 /** The number of messages currently shown (used for scrolling up). */ 69 73 private static int _messageCount = 0; 70 74 71 / / if true, error messages are not shown to the user75 /** If true, error messages are not shown to the user. */ 72 76 private static boolean _suppressMessages = false; 73 77 74 // The link to the message frameset 75 private static Item _messageLink = new Text(-2, "@" 76 + MESSAGES_FRAMESET_NAME, Color.black, Color.white); 77 78 private static List<Rectangle> _dirtyAreas = new LinkedList<Rectangle>(); 79 78 /** The link to the message frameset. */ 79 private static Item _messageLink = new Text(-2, "@" + MESSAGES_FRAMESET_NAME, Colour.BLACK, Colour.WHITE); 80 81 /** TODO: Comment. cts16 */ 80 82 private static String _lastMessage = null; 81 83 82 private MessageBay() { 83 } 84 85 /** 86 * Syncs messsage bay size according to FrameGraphics max size. 87 * 88 */ 89 static void updateSize() { 90 91 _messageBuffer = null; 92 84 /** TODO: Comment. cts16 */ 85 private static boolean isLinkInitialized = false; 86 87 /** Static-only class. */ 88 private MessageBay() 89 { 90 } 91 92 /** Whether the message bay is ready to display messages. */ 93 public static boolean isReady() 94 { 95 return Browser.isInitComplete(); 96 } 97 98 /** Syncs message bay size according to FrameGraphics max size. */ 99 static void updateSize() 100 { 93 101 for(Item i : _messages) { 94 102 if(i != null) { 95 i.setOffset(0, -FrameGraphics.getMaxFrameSize().height); 96 // i.setMaxWidth(FrameGraphics.getMaxFrameSize().width); 103 i.setOffset(0, -DisplayController.getMessageBayPaintArea().getMinY()); 97 104 } 98 105 } 99 106 100 _messageLink.setOffset(0, -FrameGraphics.getMaxFrameSize().height); 101 // _messageLink.setMaxWidth(FrameGraphics.getMaxFrameSize().width); 102 // _messageLink.setPosition(FrameGraphics.getMaxFrameSize().width 103 // - MESSAGE_LINK_Y_OFFSET, MESSAGE_LINK_X); 107 _messageLink.setOffset(0, -DisplayController.getMessageBayPaintArea().getMinY()); 108 104 109 updateLink(); 105 initBuffer(); 106 } 107 108 /** 109 * @param i 110 * @return True if i is an item in the message bay 111 */ 112 public static boolean isMessageItem(Item i) { 113 114 return _messages.contains(i) || i == _messageLink; 115 } 116 117 public synchronized static void addDirtyArea(Rectangle r) { 118 _dirtyAreas.add(r); 119 } 120 121 static synchronized int getMessageBufferHeight() { 122 if (_messageBuffer != null) 123 return _messageBuffer.getHeight(); 124 return 0; 125 } 126 127 public synchronized static Item getMessageLink() { 110 } 111 112 /** Whether the given item is an item in the message bay. */ 113 public static boolean isMessageItem(Item i) 114 { 115 return _messages.contains(i) || i == _messageLink || i == _status; 116 } 117 118 /** TODO: Comment. cts16 */ 119 public synchronized static Item getMessageLink() 120 { 128 121 return _messageLink; 129 122 } 130 123 131 public synchronized static List<Item> getMessages() { 124 /** TODO: Comment. cts16 */ 125 public synchronized static List<Item> getMessages() 126 { 132 127 return _messages; 133 128 } 134 129 135 public synchronized static boolean isDirty() { 136 return !_dirtyAreas.isEmpty(); 137 } 138 139 public synchronized static void invalidateFullBay() { 140 if (_messageBuffer != null) { 141 _dirtyAreas.clear(); 142 addDirtyArea(new Rectangle(0, 143 FrameGraphics.getMaxFrameSize().height, _messageBuffer 144 .getWidth(), _messageBuffer.getHeight())); 145 } 146 } 147 148 private synchronized static boolean initBuffer() { 149 if (_messageBuffer == null) { 150 if (FrameGraphics.isAudienceMode() 151 || FrameGraphics.getMaxSize().width <= 0) 152 return false; 153 154 GraphicsEnvironment ge = GraphicsEnvironment 155 .getLocalGraphicsEnvironment(); 156 _messageBuffer = ge.getDefaultScreenDevice() 157 .getDefaultConfiguration().createCompatibleVolatileImage( 158 FrameGraphics.getMaxSize().width, 159 MESSAGE_BUFFER_HEIGHT); 160 } 161 return true; 162 } 163 164 private static boolean isLinkInitialized = false; 165 166 private static void updateLink() { 167 168 if (!isLinkInitialized && FrameGraphics.getMaxSize().width > 0) { 130 /** Causes the entire message bay area to be invalidated. */ 131 public synchronized static void invalidateFullBay() 132 { 133 DisplayController.invalidateArea(DisplayController.getMessageBayPaintArea()); 134 } 135 136 /** TODO: Comment. cts16 */ 137 private static void updateLink() 138 { 139 if (!isLinkInitialized && DisplayController.getFramePaintArea().getWidth() > 0) { 169 140 // set up 'Messages' link on the right hand side 170 _messageLink.setPosition(FrameGraphics.getMaxSize().width 171 - MESSAGE_LINK_Y_OFFSET, MESSAGE_LINK_X); 172 _messageLink.setOffset(0, -FrameGraphics.getMaxFrameSize().height); 141 _messageLink.setPosition(DisplayController.getMessageBayPaintArea().getWidth() - MESSAGE_LINK_Y_OFFSET, MESSAGE_LINK_X); 142 _messageLink.setOffset(0, -DisplayController.getMessageBayPaintArea().getMinY()); 173 143 isLinkInitialized = true; 174 175 144 } else { 176 _messageLink.setPosition(FrameGraphics.getMaxSize().width 177 - MESSAGE_LINK_Y_OFFSET, MESSAGE_LINK_X); 178 } 179 } 180 181 /** 182 * Repaints the message bay. Updates the message bay buffer and draws to 183 * given graphics. 184 * 185 * @param useInvalidation 186 * Set to true of repinting dirty areas only. Otherwise false for 187 * full-repaint. 188 * 189 * @param g 190 * 191 * @param background 192 * The color of the message background 193 */ 194 public static synchronized void refresh(boolean useInvalidation, 195 Graphics g, Color background) { 196 197 if(g == null) 198 return; 199 200 if (FrameGraphics.getMaxSize().width <= 0) 201 return; 202 203 Area clip = null; 204 205 if (useInvalidation) { // build clip 206 207 if (!_dirtyAreas.isEmpty()) { 208 209 for (Rectangle r : _dirtyAreas) { 210 r.y = (r.y < 0) ? 0 : r.y; 211 r.x = (r.x < 0) ? 0 : r.x; 212 if (clip == null) 213 clip = new Area(r); 214 else 215 clip.add(new Area(r)); 145 _messageLink.setPosition(DisplayController.getMessageBayPaintArea().getWidth() - MESSAGE_LINK_Y_OFFSET, MESSAGE_LINK_X); 146 } 147 } 148 149 /** TODO: Comment. cts16 */ 150 public static Image getImage(Clip clip, Dimension size) 151 { 152 // Can't get an image with an invalid size 153 if (size == null || size.width <= 0 || size.height <= 0) return null; 154 155 // Update the buffer 156 updateBuffer(Item.DEFAULT_BACKGROUND, clip, size); 157 158 // Return the image buffer 159 return _messageBuffer; 160 } 161 162 /** Updates the image buffer to reflect the current state of the message bay. */ 163 private static void updateBuffer(Colour background, Clip clip, Dimension size) 164 { 165 // If the buffer doesn't exist or is the wrong size, recreate it 166 if (_messageBuffer == null || !_messageBuffer.getSize().equals(size)) { 167 _messageBuffer = Image.createImage(size, true); 168 clip = null; // Need to recreate the entire image; 169 updateSize(); 170 } 171 172 GraphicsManager g = EcosystemManager.getGraphicsManager(); 173 g.pushDrawingSurface(_messageBuffer); 174 175 if (clip != null) g.pushClip(clip); 176 g.setAntialiasing(true); 177 178 g.clear(background); 179 180 g.setFont(_messageFont); 181 182 for (Item message : _messages) { 183 if (message != null) { 184 if (clip == null || clip.isNotClipped() || message.isInDrawingArea(clip.getBounds())) { 185 FrameGraphics.PaintItem(message); 216 186 } 217 } else 218 return; // nothing to render 219 } 220 221 _dirtyAreas.clear(); 222 223 // Update the buffer 224 updateBuffer(background, clip); 225 226 // Now repaint to screen 227 if (!FrameGraphics.isAudienceMode()) { 228 229 // Translate clip to messagebox coords 230 // clip.transform(t) // TODO 231 // g.setClip(clip); 232 233 g.drawImage(_messageBuffer, 0, FrameGraphics.getMaxFrameSize().height, null); 234 } 235 236 } 237 238 private static void updateBuffer(Color background, Area clip) { 239 if (!initBuffer()) 240 return; 241 242 Graphics2D g = _messageBuffer.createGraphics(); 243 244 g.setClip(clip); 245 246 g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, 247 RenderingHints.VALUE_TEXT_ANTIALIAS_ON); 248 g.setColor(background); 249 g.fillRect(0, 0, FrameGraphics.getMaxSize().width, 250 MESSAGE_BUFFER_HEIGHT); 251 g.setFont(_messageFont); 252 g.setColor(Color.BLACK); 253 g.drawLine(0, 0, FrameGraphics.getMaxSize().width, 0); 254 255 for (Item t : _messages) { 256 if (t == null) 257 continue; 258 if (clip == null || t.isInDrawingArea(clip)) 259 FrameGraphics.PaintItem(g, t); 260 } 261 if(_status != null) 262 FrameGraphics.PaintItem(g, _status); 263 264 if (// _messageLink.getLink() != null 265 // && 266 (clip == null || _messageLink.isInDrawingArea(clip))) { 267 FrameGraphics.PaintItem(g, _messageLink); 268 } 269 g.dispose(); 270 271 } 272 273 private static Text displayMessage(String message, String link, 274 List<String> actions, Color color) { 187 } 188 } 189 190 if (_status != null) FrameGraphics.PaintItem(_status); 191 192 if (clip == null || clip.isNotClipped() || _messageLink.isInDrawingArea(clip.getBounds())) { 193 FrameGraphics.PaintItem(_messageLink); 194 } 195 196 g.popDrawingSurface(); 197 } 198 199 /** TODO: Comment. cts16 */ 200 private static Text displayMessage(String message, String link, List<String> actions, Colour color) 201 { 275 202 return displayMessage(message, link, actions, color, true); 276 203 } 277 204 278 public synchronized static Text displayMessage(String message, String link, Color color, 279 boolean displayAlways, String action) { 205 /** TODO: Comment. cts16 */ 206 public synchronized static Text displayMessage(String message, String link, Colour color, boolean displayAlways, String action) 207 { 280 208 List<String> actions = new LinkedList<String>(); 281 if (action != null) 282 actions.add(action); 209 if (action != null) actions.add(action); 283 210 return displayMessage(message, link, actions, color, displayAlways); 284 211 } 285 286 private static Text newMessage(String message, String link, List<String> actions, Color color) { 212 213 /** TODO: Comment. cts16 */ 214 private static Text newMessage(String message, String link, List<String> actions, Colour color) 215 { 287 216 Text t = new Text(getMessagePrefix(true) + message); 288 217 t.setPosition(20, 15 + _messages.size() * 25); 289 t.setOffset(0, - FrameGraphics.getMaxFrameSize().height);218 t.setOffset(0, -DisplayController.getFramePaintArea().getHeight()); 290 219 t.setColor(color); 291 220 t.setLink(link); … … 296 225 return t; 297 226 } 298 299 private synchronized static Text displayMessage(String message, String link, 300 List<String> actions, Color color, boolean displayAlways, boolean redraw) { 227 228 /** TODO: Comment. cts16 */ 229 private synchronized static Text displayMessage(String message, String link, List<String> actions, Colour color, boolean displayAlways, boolean redraw) 230 { 231 assert (message != null); 232 233 if (!isReady()) { 234 delayMessage(message, link, actions, color, displayAlways, redraw); 235 return null; 236 } 237 301 238 System.out.println(message); 302 assert (message != null);303 239 304 240 // Invalidate whole area 305 241 invalidateFullBay(); 306 242 307 if (_suppressMessages) 308 return null; 243 if (_suppressMessages) return null; 309 244 310 245 if (!displayAlways && message.equals(_lastMessage)) { … … 312 247 return null; 313 248 } 249 314 250 _lastMessage = message; 315 251 316 252 if (_creator == null) { 317 _creator = new FrameCreator(MESSAGES_FRAMESET_NAME, 318 FrameIO.MESSAGES_PATH, MESSAGES_FRAMESET_NAME, true, false); 253 _creator = new FrameCreator(MESSAGES_FRAMESET_NAME, FrameIO.MESSAGES_PATH, MESSAGES_FRAMESET_NAME, true, false); 319 254 } 320 255 … … 336 271 _messageLink.setLink(_creator.getCurrent()); 337 272 273 // TODO: Can we just make this DisplayController.requestRefresh()? cts16 338 274 if(redraw) { 339 Graphics g = FrameGraphics.createGraphics(); 340 if (g != null) { 341 refresh(false, g, Item.DEFAULT_BACKGROUND); 342 } 275 DisplayController.requestRefresh(true); 343 276 } 344 277 … … 346 279 } 347 280 348 public synchronized static Text displayMessage(String message, String link, 349 List<String> actions, Color color, boolean displayAlways) { 281 /** TODO: Comment. cts16 */ 282 public synchronized static Text displayMessage(String message, String link, List<String> actions, Colour color, boolean displayAlways) 283 { 350 284 return displayMessage(message, link, actions, color, displayAlways, true); 351 285 } 352 286 353 public synchronized static void overwriteMessage(String message) { 287 /** TODO: Comment. cts16 */ 288 public synchronized static void overwriteMessage(String message) 289 { 354 290 overwriteMessage(message, null); 355 291 } 356 292 357 public synchronized static void overwriteMessage(String message, Color color) { 293 /** TODO: Comment. cts16 */ 294 public synchronized static void overwriteMessage(String message, Colour color) 295 { 358 296 _messages.remove(_messages.size() - 1); 359 297 Text t = newMessage(message, null, null, color); 360 298 _messages.add(t); 361 Graphics g = FrameGraphics.createGraphics(); 362 if (g != null) { 363 refresh(false, g, Item.DEFAULT_BACKGROUND); 364 } 365 } 366 367 private static String getMessagePrefix(int counter) { 299 DisplayController.requestRefresh(true); 300 } 301 302 /** TODO: Comment. cts16 */ 303 private static String getMessagePrefix(int counter) 304 { 368 305 return "@" + counter + ": "; 369 306 } 370 307 371 private static String getMessagePrefix(boolean incrementCounter) { 372 if (incrementCounter) 373 _messageCount++; 308 /** TODO: Comment. cts16 */ 309 private static String getMessagePrefix(boolean incrementCounter) 310 { 311 if (incrementCounter) _messageCount++; 312 374 313 return getMessagePrefix(_messageCount); 375 314 } … … 382 321 * the message to be displayed 383 322 */ 384 public synchronized static Text linkedErrorMessage(String message) {385 if (_suppressMessages)386 323 public synchronized static Text linkedErrorMessage(String message) 324 { 325 if (_suppressMessages) return null; 387 326 Misc.beep(); 388 327 String[] tokens = message.split(Text.FRAME_NAME_SEPARATOR); 389 328 String link = null; 390 if (tokens.length > 1) 391 link = tokens[tokens.length - 1]; 329 if (tokens.length > 1) link = tokens[tokens.length - 1]; 392 330 return displayMessage(message, link, null, ERROR_COLOR); 393 331 } 394 332 395 public synchronized static Text errorMessage(String message) { 396 if (_suppressMessages) 397 return null; 333 /** TODO: Comment. cts16 */ 334 public synchronized static Text errorMessage(String message) 335 { 336 if (_suppressMessages) return null; 398 337 Misc.beep(); 399 338 return displayMessage(message, null, null, ERROR_COLOR, false); … … 407 346 * The message to display to the user in the message area 408 347 */ 409 public synchronized static Text displayMessage(String message) { 348 public synchronized static Text displayMessage(String message) 349 { 410 350 return displayMessageAlways(message); 411 351 } 412 352 413 public synchronized static Text displayMessageOnce(String message) { 414 return displayMessage(message, null, null, Color.BLACK, false); 415 } 416 417 public synchronized static Text displayMessage(String message, Color textColor) { 353 /** TODO: Comment. cts16 */ 354 public synchronized static Text displayMessageOnce(String message) 355 { 356 return displayMessage(message, null, null, Colour.BLACK, false); 357 } 358 359 /** TODO: Comment. cts16 */ 360 public synchronized static Text displayMessage(String message, Colour textColor) 361 { 418 362 return displayMessage(message, null, null, textColor); 419 // Misc.Beep(); 420 } 421 422 public synchronized static Text displayMessage(Text message) { 363 } 364 365 /** TODO: Comment. cts16 */ 366 public synchronized static Text displayMessage(Text message) 367 { 423 368 Text t = null; 424 369 String link = message.getLink(); 425 370 List<String> action = message.getAction(); 426 Colo r color = message.getColor();371 Colour color = message.getColor(); 427 372 for (String s : message.getTextList()) { 428 373 t = displayMessage(s, link, action, color); 429 374 } 430 375 return t; 376 } 377 378 /** TODO: Comment. cts16 */ 379 public synchronized static Text displayMessageAlways(String message) 380 { 381 return displayMessage(message, null, null, Colour.BLACK); 431 382 // Misc.Beep(); 432 383 } 433 384 434 public synchronized static Text displayMessageAlways(String message) { 435 return displayMessage(message, null, null, Color.BLACK); 436 // Misc.Beep(); 437 } 438 439 public synchronized static Text warningMessage(String message) { 440 return displayMessage(message, null, null, Color.MAGENTA); 441 // Misc.Beep(); 442 } 443 444 public synchronized static void suppressMessages(boolean val) { 385 /** TODO: Comment. cts16 */ 386 public synchronized static Text warningMessage(String message) 387 { 388 return displayMessage(message, null, null, Colour.MAGENTA); 389 } 390 391 /** TODO: Comment. cts16 */ 392 public synchronized static List<Text> warningMessages(List<String> messages) 393 { 394 if (messages == null) return null; 395 List<Text> ret = new LinkedList<Text>(); 396 for (String message : messages) ret.add(warningMessage(message)); 397 return ret; 398 } 399 400 /** TODO: Comment. cts16 */ 401 public synchronized static void suppressMessages(boolean val) 402 { 445 403 _suppressMessages = val; 446 404 } 447 448 public synchronized static void setStatus(String status) { 405 406 /** TODO: Comment. cts16 */ 407 public synchronized static void setStatus(String status) 408 { 449 409 if (_status == null) { 450 410 _status = new Text(status); 451 411 _status.setPosition(0, 85); 452 _status.setOffset(0, FrameGraphics.getMaxFrameSize().height);412 _status.setOffset(0, -DisplayController.getMessageBayPaintArea().getMinY()); 453 413 _status.setLink(null); // maybe link to a help frame? 454 _status.setFont( Font.decode(Text.MONOSPACED_FONT));414 _status.setFont(new Font(Text.MONOSPACED_FONT)); 455 415 } else { 456 416 _status.setText(status); 457 417 } 458 Graphics g = FrameGraphics.createGraphics(); 459 if (g != null) { 460 refresh(false, g, Item.DEFAULT_BACKGROUND); 461 } 462 } 463 464 public static final class Progress { 465 466 private static final String filled = "\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592"; 467 private static final String unfilled = "\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591"; 468 469 String message; 470 Text text; 471 472 protected Progress(String text) { 473 this.text = displayMessage(text, null, null, Color.GREEN.darker(), true, false); 474 //this.text.setFont(Font.decode(Text.MONOSPACED_FONT + "-16")); 475 this.message = this.text.getText(); 476 this.text.setText(this.message + " [" + unfilled + "] 0%"); 477 refresh(false, FrameGraphics.createGraphics(), Item.DEFAULT_BACKGROUND); 478 } 479 480 public void UpdateMessage(final String text, final int newProgress) throws Exception { 481 this.message = text; 418 419 //invalidateFullBay(); 420 DisplayController.requestRefresh(true); 421 } 422 423 /** TODO: Comment. cts16 */ 424 public static final class Progress 425 { 426 /** The colour progress bars should be displayed in. */ 427 private static final Colour BAR_COLOUR = Colour.GREEN.darker(); 428 429 /** The character used to assemble the uncompleted portions of the progress bar. */ 430 private static final char UNCOMPLETED_CHARACTER = '\u2591'; // ░ 431 /** The character used to assemble the completed portions of the progress bar. */ 432 private static final char COMPLETED_CHARACTER = '\u2592'; // ▒ 433 434 /** What the progress bar should look like when at 100% completion. */ 435 private static final String COMPLETED_BAR = Util.nCopiesOf(20, COMPLETED_CHARACTER); 436 /** What the progress bar should look like when at 0% completion. */ 437 private static final String UNCOMPLETED_BAR = Util.nCopiesOf(20, UNCOMPLETED_CHARACTER); 438 439 private String _message; 440 private Text _text; 441 442 protected Progress(String text) 443 { 444 this._text = displayMessage(text, null, null, BAR_COLOUR, true, false); 445 this._message = this._text.getText(); 446 this._text.setText(this._message + " [" + UNCOMPLETED_BAR + "] 0%"); 447 DisplayController.requestRefresh(true); 448 } 449 450 public void UpdateMessage(final String text, final int newProgress) throws Exception 451 { 452 this._message = text; 482 453 set(newProgress); 483 454 } 484 455 485 public String GetMessage() { 486 return message; 456 public String GetMessage() 457 { 458 return _message; 487 459 } 488 460 … … 493 465 * @throws Exception if progress out of bounds 494 466 */ 495 public boolean set(int progress) throws Exception { 467 public boolean set(int progress) throws Exception 468 { 496 469 if(progress < 0 || progress > 100) throw new Exception("Progress value out of bounds"); 497 470 int p = progress / 5; 498 if(isMessageItem(this. text)) {499 this. text.setText(this.message + " [" + filled.substring(0, p) + unfilled.substring(p) + "] " + progress + "%");500 refresh(false, FrameGraphics.createGraphics(), Item.DEFAULT_BACKGROUND);471 if(isMessageItem(this._text)) { 472 this._text.setText(this._message + " [" + COMPLETED_BAR.substring(0, p) + UNCOMPLETED_BAR.substring(p) + "] " + progress + "%"); 473 DisplayController.requestRefresh(true); 501 474 return true; 502 475 } … … 504 477 } 505 478 } 479 480 /** TODO: Comment. cts16 */ 481 public synchronized static Progress displayProgress(String message) 482 { 483 return new Progress(message); 484 } 506 485 507 public synchronized static Progress displayProgress(String message) { 508 return new Progress(message); 486 /** Remembers the arguments to a displayMessage call for later use. */ 487 private static class DelayedMessage { 488 489 private String _message; 490 private String _link; 491 private List<String> _actions; 492 private Colour _colour; 493 private boolean _displayAlways; 494 private boolean _redraw; 495 496 public DelayedMessage(String message, String link, List<String> actions, Colour color, boolean displayAlways, boolean redraw) 497 { 498 _message = message; 499 _link = link; 500 if (actions == null) { 501 _actions = null; 502 } else { 503 _actions = new LinkedList<String>(); 504 _actions.addAll(actions); 505 } 506 _colour = color == null ? null : color.clone(); 507 _displayAlways = displayAlways; 508 _redraw = redraw; 509 } 510 511 public void display() 512 { 513 displayMessage(_message, _link, _actions, _colour, _displayAlways, _redraw); 514 } 515 516 } 517 518 private static void delayMessage(String message, String link, List<String> actions, Colour color, boolean displayAlways, boolean redraw) 519 { 520 _delayedMessages.add(new DelayedMessage(message, link, actions, color, displayAlways, redraw)); 521 } 522 523 public static void showDelayedMessages() 524 { 525 if (isReady()) { 526 for (DelayedMessage message : _delayedMessages) message.display(); 527 _delayedMessages.clear(); 528 invalidateFullBay(); 529 DisplayController.requestRefresh(true); 530 } 509 531 } 510 532 -
trunk/src/org/expeditee/gui/Overlay.java
r919 r1102 20 20 21 21 import java.util.Collection; 22 import java.util.LinkedList; 23 import java.util.List; 22 24 23 25 import org.expeditee.items.UserAppliedPermission; 26 import org.expeditee.items.widgets.Widget; 24 27 28 /** TODO: Comment. cts16 */ 25 29 public class Overlay { 30 /** TODO: Comment. cts16 */ 26 31 public Frame Frame; 27 32 33 /** TODO: Comment. cts16 */ 28 34 public UserAppliedPermission permission; 29 35 36 /** TODO: Comment. cts16 */ 30 37 public Overlay(Frame overlay, UserAppliedPermission level) { 31 38 Frame = overlay; … … 34 41 35 42 @Override 36 public boolean equals(Object o) {37 if (o == null || o.getClass() != Overlay.class)38 43 public boolean equals(Object o) 44 { 45 if (!(o instanceof Overlay)) return false; 39 46 40 47 return ((Overlay) o).Frame == Frame; … … 42 49 43 50 @Override 44 public int hashCode() { 51 public int hashCode() 52 { 53 // TODO: Comment. cts16 45 54 return 0; 46 55 } 47 48 public static Overlay getOverlay(Collection<Overlay>overlays, Frame frame){ 56 57 /** TODO: Comment. cts16 */ 58 public static Overlay getOverlay(Collection<Overlay> overlays, Frame frame) 59 { 49 60 // Check the frame is in the list of overlays 50 61 for (Overlay o : overlays) { -
trunk/src/org/expeditee/gui/Popup.java
r919 r1102 19 19 package org.expeditee.gui; 20 20 21 import java.awt.BasicStroke; 22 import java.awt.Color; 23 import java.awt.Component; 24 import java.awt.Container; 25 import java.awt.Graphics; 26 import java.awt.Graphics2D; 27 import java.awt.LayoutManager; 28 29 import javax.swing.JComponent; 30 import javax.swing.JPanel; 31 21 import org.expeditee.core.Clip; 22 import org.expeditee.core.Colour; 23 import org.expeditee.core.EnforcedClipStack.EnforcedClipKey; 24 import org.expeditee.core.Fill; 25 import org.expeditee.core.Lifetime; 26 import org.expeditee.core.Stroke; 27 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 28 import org.expeditee.gio.EcosystemManager; 29 import org.expeditee.gio.GraphicsManager; 30 import org.expeditee.gui.PopupManager.PopupAnimator; 32 31 import org.expeditee.items.ItemUtils; 33 32 34 33 /** 34 * A Custom swing pop-up in Expeditee. 35 35 * 36 * A Custom swing popup in Expeditee. 37 * 38 * Expeditee popus can be re-used. Popups are always heavyweight (i.e. uses invalidation). 36 * Expeditee pop-ups can be re-used. Pop-ups are always heavyweight (i.e. uses invalidation). 39 37 * 40 38 * @see {@link PopupManager} 41 39 * 42 40 * @author Brook Novak 43 *44 41 */ 45 public abstract class Popup extends JPanel {46 42 public abstract class Popup 43 { 47 44 //Mike says: Can we get the border for the IW to which this popup corresponds? 48 // Brook says: Would be nice - but popups are actually independ ant from widgets45 // Brook says: Would be nice - but popups are actually independent from widgets 49 46 // =>Now: It is up to the user of the popup to set the border thickness 50 private static final BasicStroke DEFAULT_STROKE = new BasicStroke(2.0f); 51 52 private BasicStroke _borderStroke = DEFAULT_STROKE; 53 private Color _borderColor = Color.BLACK; 54 55 private boolean _isReadyToPaint = false; 47 private static final Stroke DEFAULT_STROKE = new Stroke(2.0f); 48 49 private Stroke _borderStroke = DEFAULT_STROKE; 50 private Colour _borderColour = Colour.BLACK; 51 private Fill _backgroundFill = new Fill(Colour.WHITE); 52 53 private PopupAnimator _animator = null; 54 55 private Lifetime _autoHideTime = new Lifetime(Lifetime.INFINITE_LIFETIME); 56 private Runnable _autoHideRoutine = new Runnable() 57 { 58 @Override 59 public void run() 60 { 61 hide(); 62 DisplayController.invalidateArea(getBounds()); 63 DisplayController.requestRefresh(true); 64 } 65 }; 66 67 private boolean _hidden = true; 68 56 69 private boolean _consumeBackClick = false; 57 private boolean _autoHide = true; 58 59 /** 60 * Creates a new popup. 61 * Autohide is set to true. 62 * 63 */ 64 public Popup() { 65 super(); 66 setVisible(false); 67 } 68 69 /** 70 * Creates a new popup. 71 * 72 * @param layout the LayoutManager to use 73 */ 74 public Popup(LayoutManager layout) { 75 super(layout); 76 setVisible(false); 77 } 78 79 @Override 80 public void paint(Graphics g) { 81 super.paint(g); 82 83 // Draw border - if not transparent 84 if (_borderStroke != null && _borderColor != null) { 85 g.setColor(_borderColor); 86 ((Graphics2D)g).setStroke(_borderStroke); 87 g.drawRect(0, 0, getWidth(), getHeight()); 88 } 89 } 90 91 private void ignoreAWTPainting(Component c) { 92 93 if (c instanceof JComponent) { 94 ((JComponent)c).setDoubleBuffered(false); 95 } 96 97 c.setIgnoreRepaint(true); 98 99 if (c instanceof Container) { 100 for (Component child : ((Container) c).getComponents()) { 101 102 if (child instanceof Container) { 103 ignoreAWTPainting(child); 104 } else { 105 if (child instanceof JComponent) { 106 ((JComponent)child).setDoubleBuffered(false); 107 } 108 109 child.setIgnoreRepaint(true); 70 71 /** 72 * Creates a new pop-up. 73 * Auto-hide is set to true. 74 */ 75 public Popup(PopupAnimator animator) 76 { 77 setAnimator(animator); 78 } 79 80 public Popup(PopupAnimator animator, long lifetime) 81 { 82 this(animator); 83 _autoHideTime.setLifetime(lifetime); 84 } 85 86 public Lifetime getAutoHideTime() 87 { 88 return _autoHideTime; 89 } 90 91 public void setAnimator(PopupAnimator animator) 92 { 93 _animator = animator; 94 } 95 96 public PopupAnimator getAnimator() 97 { 98 return _animator; 99 } 100 101 public boolean isShowing() 102 { 103 return !_hidden; 104 } 105 106 public void show() 107 { 108 if (_hidden) onShow(); 109 110 if (_animator != null) { 111 _animator.show(); 112 if (!_animator.isFinished()) { 113 _autoHideTime.cancelExpiry(); 114 } else { 115 _autoHideTime.refresh(); 116 _autoHideTime.onExpiry(_autoHideRoutine); 117 } 118 } else { 119 _autoHideTime.refresh(); 120 _autoHideTime.onExpiry(_autoHideRoutine); 121 } 122 123 _hidden = false; 124 } 125 126 public void hide() 127 { 128 if (!_hidden) onHide(); 129 130 if (_animator != null) _animator.hide(); 131 _autoHideTime.cancelExpiry(); 132 _hidden = true; 133 } 134 135 public boolean update() 136 { 137 if (_animator != null) { 138 if (!_hidden && !_animator.isFinished()) { 139 if (!_animator.update()) { 140 _autoHideTime.refresh(); 141 _autoHideTime.onExpiry(_autoHideRoutine); 110 142 } 111 143 } 112 } 113 114 } 115 116 /** 117 * Ensures that AWT painting turned off 118 */ 119 void prepareToPaint() { 120 if (!_isReadyToPaint) { 121 _isReadyToPaint = true; 122 ignoreAWTPainting(this); 123 } 124 } 125 126 /** 127 * Invoked when the popup becomes hidden, or when the popup is animating to show but cancelled. 128 */ 129 public void onHide() {} 130 131 /** 132 * Invoked when the popup shows. Note this might not eventuate for animated popups. 133 */ 134 public void onShow() {} 135 136 /** 137 * Invoked when popups is going to show. 138 * This always is invoked first. 139 */ 140 public void onShowing() {} 141 142 public boolean shouldConsumeBackClick() { 144 145 if (_hidden && !_animator.isFinished()) { 146 return _animator.update(); 147 } 148 } else { 149 if (_autoHideTime.hasExpired()) hide(); 150 } 151 152 return false; 153 154 } 155 156 public final void paint() 157 { 158 GraphicsManager g = EcosystemManager.getGraphicsManager(); 159 160 // Make sure the popup isn't hidden 161 AxisAlignedBoxBounds currentBounds = getBounds(); 162 if (currentBounds == null) return; 163 164 // Draw border and background 165 g.drawRectangle(currentBounds, 0.0, _backgroundFill, _borderColour, _borderStroke, null); 166 167 EnforcedClipKey key = g.pushClip(new Clip(currentBounds)); 168 169 paintInternal(); 170 171 g.popClip(key); 172 } 173 174 /** Draws the interior paint area of the popup. */ 175 protected abstract void paintInternal(); 176 177 /** Gets the bounds of this popup when it's fully shown. */ 178 public abstract AxisAlignedBoxBounds getFullBounds(); 179 180 /** Gets the bounds of this popup in its current animated state. */ 181 public AxisAlignedBoxBounds getBounds() 182 { 183 if (_animator == null) { 184 if (_autoHideTime.hasExpired()) { 185 return null; 186 } else { 187 return getFullBounds(); 188 } 189 } 190 191 return _animator.getAnimatedBounds(getFullBounds()); 192 } 193 194 /** Invoked when the popup becomes hidden, or when the popup is animating to show but cancelled. */ 195 public abstract void onHide(); 196 197 /** Invoked when the popup shows. Note this might not eventuate for animated popups. */ 198 public abstract void onShow(); 199 200 public boolean shouldConsumeBackClick() 201 { 143 202 return _consumeBackClick; 144 203 } … … 150 209 * consume the back-click event. 151 210 */ 152 protected void setConsumeBackClick(boolean consumeBackClick) { 211 protected void setConsumeBackClick(boolean consumeBackClick) 212 { 153 213 _consumeBackClick = consumeBackClick; 154 }155 156 /**157 * @param autoHideOn158 * Set to True if this popup should auto hide. (The default).159 * Set to false if this popup should be manually hidden.160 */161 protected void setAudoHide(boolean autoHideOn) {162 _autoHide = autoHideOn;163 214 } 164 215 … … 167 218 * True if this popup auto hides. 168 219 */ 169 public boolean doesAutoHide() { 170 return _autoHide; 220 public boolean doesAutoHide() 221 { 222 return _autoHideTime.remainingLifetime() != Lifetime.INFINITE_LIFETIME; 171 223 } 172 224 … … 177 229 * The new thickness to set. Null for no border. 178 230 */ 179 public void setBorderThickness(float thickness) { 231 public void setBorderThickness(float thickness) 232 { 180 233 assert(thickness >= 0); 181 234 182 if (_borderStroke != null && _borderStroke.getLineWidth() == thickness) 183 return; 235 if (_borderStroke != null && _borderStroke.thickness == thickness) return; 184 236 185 237 boolean posInvalidate = true; 186 238 187 if (thickness < _borderStroke. getLineWidth()) {239 if (thickness < _borderStroke.thickness) { 188 240 invalidateAppearance(); 189 241 posInvalidate = false; 190 242 } 191 243 192 if (thickness == 0) _borderStroke = null; 193 else _borderStroke = new BasicStroke(thickness); 244 if (thickness == 0) { 245 _borderStroke = null; 246 } else { 247 _borderStroke = new Stroke(thickness); 248 } 194 249 195 250 if (posInvalidate) invalidateAppearance(); … … 201 256 * The border thickness of this popup. Zero or more. 202 257 */ 203 public float getBorderThickness() { 258 public float getBorderThickness() 259 { 204 260 if (_borderStroke == null) return 0.0f; 205 return _borderStroke.getLineWidth(); 206 261 262 return _borderStroke.thickness; 207 263 } 208 264 … … 214 270 * The new color. Null for transparent. 215 271 */ 216 public void setBorderColor(Color c) { 217 218 if (c == null && _borderColor != null) 272 public void setBorderColor(Colour c) 273 { 274 if (c == null && _borderColour != null) invalidateAppearance(); 275 276 if (c != _borderColour) { 277 _borderColour = c; 219 278 invalidateAppearance(); 220 221 if (c != _borderColor) { 222 _borderColor = c; 223 invalidateAppearance(); 224 } 225 } 226 227 /** 228 * 279 } 280 } 281 282 /** 229 283 * @return 230 284 * The border color for the popup. NUll if transparent 231 285 */ 232 public Color getBorderColor() { 233 return _borderColor; 234 } 235 236 /** 237 * Invalidates the whole popup so that it must be fully repainted. 238 */ 239 public void invalidateAppearance() { 240 241 if (_borderColor != null && _borderStroke != null && _borderStroke.getLineWidth() > 0) { // border 242 FrameGraphics.invalidateArea(ItemUtils.expandRectangle(getBounds(), 243 (int)Math.ceil(getBorderThickness()) + 1)); 286 public Colour getBorderColor() 287 { 288 return _borderColour; 289 } 290 291 /** 292 * Invalidates the whole pop-up so that it must be fully repainted. 293 */ 294 public void invalidateAppearance() 295 { 296 AxisAlignedBoxBounds bounds = getBounds(); 297 298 if (bounds == null) return; 299 300 if (_borderColour != null && _borderStroke != null && _borderStroke.thickness > 0) { // border 301 DisplayController.invalidateArea(ItemUtils.expandRectangle(bounds, (int)Math.ceil(getBorderThickness()) + 1)); 244 302 } else { // no border 245 FrameGraphics.invalidateArea(getBounds()); 246 } 247 248 } 249 250 251 303 DisplayController.invalidateArea(bounds); 304 } 305 306 } 252 307 } -
trunk/src/org/expeditee/gui/PopupManager.java
r919 r1102 19 19 package org.expeditee.gui; 20 20 21 import java.awt.BasicStroke;22 import java.awt.Color;23 import java.awt.Component;24 import java.awt.Graphics;25 import java.awt.Graphics2D;26 import java.awt.Point;27 import java.awt.Rectangle;28 import java.awt.Stroke;29 import java.awt.geom.Area;30 import java.util.HashMap;31 import java.util.HashSet;32 21 import java.util.LinkedList; 33 34 import javax.swing.JLayeredPane; 35 import javax.swing.SwingUtilities; 22 import java.util.List; 23 24 import org.expeditee.core.Point; 25 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 26 import org.expeditee.gio.EcosystemManager; 27 import org.expeditee.gio.EcosystemManager.Ecosystem; 36 28 37 29 /** 38 * A centrali zed container for all custom popups in expeditee.30 * A centralised container for all custom pop-ups in expeditee. 39 31 * 40 32 * @author Brook Novak 41 33 */ 42 public final class PopupManager implements Display IOObserver {43 34 public final class PopupManager implements DisplayObserver 35 { 44 36 /** Singleton */ 45 private PopupManager() {} 37 private static PopupManager _instance = null; 38 39 /** 40 * @return The singleton instance. 41 */ 42 public static PopupManager getInstance() 43 { 44 // Only valid for Swing ecosystems 45 if (EcosystemManager.getType() != Ecosystem.Swing) return null; 46 47 // Construct the instance 48 if (_instance == null) _instance = new PopupManager(); 49 50 return _instance; 51 } 46 52 47 53 /** Singleton */ 48 private static PopupManager _instance = new PopupManager(); 49 50 /** 51 * @return The singleton instance. 52 */ 53 public static PopupManager getInstance() { 54 return _instance; 55 } 56 57 // popup->invoker 58 private HashMap<Popup, Component> _popups = new HashMap<Popup, Component>(); 59 // quick ref to invokers 60 private HashSet<Component> _invokers = new HashSet<Component>(); 61 62 private LinkedList<AnimatedPopup> _animatingPopups = new LinkedList<AnimatedPopup>(); 63 private AnimationThread _animationThread = null; 64 65 private final int ANIMATION_DURATION = 180; // Tume its takes for a maximize . minimize to animate. In ms. 66 private final int ANIMATION_RATE = 30; // in ms 67 68 /** 69 * Determines whether a given point is over a popup. 54 private PopupManager() 55 { 56 } 57 58 private LinkedList<Popup> _popups = new LinkedList<Popup>(); 59 60 /** Time its takes for a maximise/minimise to animate, in milliseconds. */ 61 //private final int ANIMATION_DURATION = 180; 62 /** in milliseconds. TODO: Expand. cts16 */ 63 //private final int ANIMATION_RATE = 30; 64 65 public void add(Popup p) 66 { 67 if (p == null) return; 68 69 synchronized(_popups) { 70 if (!_popups.contains(p)) _popups.add(p); 71 } 72 } 73 74 public void remove(Popup p) 75 { 76 if (p == null) return; 77 78 synchronized(_popups) { 79 if (_popups.contains(p)) _popups.remove(p); 80 } 81 } 82 83 public List<Popup> getPopups() 84 { 85 synchronized(_popups) { 86 return new LinkedList<Popup>(_popups); 87 } 88 } 89 90 /** 91 * Determines whether a given point is over a pop-up. 70 92 * 71 93 * @param p 72 94 * 73 * @return True if p is over a pop up95 * @return True if p is over a pop-up 74 96 * 75 97 * @throws NullPointerException 76 98 * If p is null 77 99 */ 78 public boolean isPointOverPopup(Point p) { 100 public boolean isPointOverPopup(Point p) 101 { 79 102 if (p == null) throw new NullPointerException("p"); 80 for (Popup pp : _popups.keySet()) { 81 if (pp.getBounds().contains(p)) { 82 return true; 103 104 synchronized(_popups) { 105 for (Popup popup : _popups) { 106 if (popup.getBounds().contains(p)) return true; 83 107 } 84 108 } 85 109 86 110 return false; 87 }88 89 /**90 * Tests a component to see if it is in invoker of an existing popup.91 *92 * @param c93 * Must not be null.94 *95 * @return96 * True if c is an invoker97 *98 * @throws NullPointerException99 * If c is null100 */101 public boolean isInvoker(Component c) {102 if (c == null) throw new NullPointerException("c");103 return _invokers.contains(c);104 }105 106 /**107 * Gets an invoker for a popup108 *109 * @param p110 * The popup to get the invoker for.111 *112 * @return113 * The invoker for the given popup.114 * Null if popup does not exist.115 */116 public Component getInvoker(Popup p) {117 if (p == null) throw new NullPointerException("p");118 return _popups.get(p);119 111 } 120 112 … … 130 122 * If p is null 131 123 */ 132 public boolean isShowing(Popup p) { 124 public boolean isShowing(Popup p) 125 { 133 126 if (p == null) throw new NullPointerException("p"); 134 return _popups.containsKey(p); 127 128 synchronized(_popups) { 129 return _popups.contains(p) && p.isShowing(); 130 } 135 131 } 136 132 137 133 /** 138 134 * @return 139 * True if a poup is showing. False otherwise. 140 */ 141 public boolean isAnyPopupsShowing () { 142 return !_popups.isEmpty(); 135 * True if a pop-up is showing. False otherwise. 136 */ 137 public boolean isAnyPopupsShowing() 138 { 139 synchronized(_popups) { 140 return !_popups.isEmpty(); 141 } 142 } 143 144 public void hideAutoHidePopups() 145 { 146 synchronized(_popups) { 147 for (Popup p : _popups) { 148 if (p.doesAutoHide()) p.hide(); 149 } 150 } 143 151 } 144 152 … … 146 154 * @return 147 155 * True if the mouse click event for going back a frame should be consumed 148 * Due to a popup requesting this event to be consumed currently showing. 149 */ 150 public boolean shouldConsumeBackClick() { 151 for (Popup p : _popups.keySet()) { 152 if (p.shouldConsumeBackClick()) 153 return true; 156 * due to a pop-up requesting this event to be consumed currently showing. 157 */ 158 public boolean shouldConsumeBackClick() 159 { 160 synchronized(_popups) { 161 for (Popup p : _popups) { 162 if (p.shouldConsumeBackClick()) return true; 163 } 154 164 } 155 165 … … 157 167 } 158 168 159 /** 160 * Clears all popups from the browser that are autohidden. 161 * Stops animations. 162 */ 163 public void hideAutohidePopups() { 164 165 166 // Get rid of all animations that are not non-auto-hidden pops that are expanding 167 synchronized (_animatingPopups) { 168 169 LinkedList<AnimatedPopup> animationsToClear = new LinkedList<AnimatedPopup>(); 170 171 for (AnimatedPopup ap : _animatingPopups) { 172 if (!(ap.popup != null && !ap.popup.doesAutoHide())) { 173 animationsToClear.add(ap); 174 } 175 } 176 177 _animatingPopups.removeAll(animationsToClear); 178 179 } 180 181 LinkedList<Popup> popupsToClear = new LinkedList<Popup>(); 182 LinkedList<Component> invokersToClear = new LinkedList<Component>(); 183 184 // Get ride of the actual popups 185 for (Popup p : _popups.keySet()) { 186 if (p.doesAutoHide()) { 187 188 popupsToClear.add(p); 189 invokersToClear.add(_popups.get(p)); 190 191 p.invalidateAppearance(); 192 p.setVisible(false); 193 Browser._theBrowser.getLayeredPane().remove(p); 194 p.onHide(); 195 } 196 } 197 198 assert (popupsToClear.size() == invokersToClear.size()); 199 200 for (int i = 0; i < popupsToClear.size(); i++) { 201 _popups.remove(popupsToClear.get(i)); 202 _invokers.remove(invokersToClear.get(i)); 203 } 204 205 206 207 } 208 209 210 211 // public void hideAllPopups() { 212 // 213 // for (Popup p : _popups.keySet()) { 214 // invalidatePopup(p); 215 // p.setVisible(false); 216 // Browser._theBrowser.getLayeredPane().remove(p); 217 // p.onHide(); 218 // } 219 // _popups.clear(); 220 // _invokers.clear(); 221 // 222 // // Get rid of all animations 223 // synchronized (_animatingPopups) { 224 // _animatingPopups.clear(); 225 // } 226 // } 227 228 public void frameChanged() { 229 // Remove any popups that are showing on the current frame 230 hideAutohidePopups(); 231 } 232 233 /** 234 * Hides a popup - if not already hidden. 235 * 236 * @param p 237 * Must not be null. 238 * 239 * @throws NullPointerException 240 * If p is null 241 */ 242 public void hidePopup(Popup p) { 243 if (p == null) throw new NullPointerException("p"); 244 245 if (!isShowing(p) && (!p.isVisible() || p.getParent() == null)) return; 246 247 248 // Cancel any showing animations 249 synchronized (_animatingPopups) { 250 AnimatedPopup toRemove = null; 251 for (AnimatedPopup ap : _animatingPopups) { 252 if (ap.popup == p) { 253 toRemove = ap; 254 break; 255 } 256 } 257 if (toRemove != null) 258 _animatingPopups.remove(toRemove); 259 } 260 261 p.invalidateAppearance(); 262 p.setVisible(false); 263 Browser._theBrowser.getLayeredPane().remove(p); 264 Component invoker = _popups.remove(p); 265 if (invoker != null) _invokers.remove(invoker); 266 p.onHide(); 267 268 } 269 270 /** 271 * Hides a popup - with animation. - if not already hidden. 272 * 273 * @param p 274 * Must not be null. 275 * @param animator 276 * Must not be null. 277 * 278 * @throws NullPointerException 279 * If p or animator is null 280 * 281 */ 282 public void hidePopup(Popup p, PopupAnimator animator) { 283 284 if (p == null) throw new NullPointerException("p"); 285 if (animator == null) throw new NullPointerException("animator"); 286 287 if (!isShowing(p) && (!p.isVisible() || p.getParent() == null)) return; 288 289 hidePopup(p); 290 AnimatedPopup ap = new AnimatedPopup( 291 animator, 292 System.currentTimeMillis(), 293 null, 294 false, 295 p.getLocation()); 296 297 animator.starting(false, p.getBounds()); 298 299 synchronized (_animatingPopups) { 300 _animatingPopups.add(ap); 301 } 302 303 if (_animationThread == null || !_animationThread.isAlive() || _animationThread.willDie) { 304 _animationThread = new AnimationThread(); 305 _animationThread.start(); 306 } 307 } 308 309 310 311 /** 312 * Displays a popup at a specific location. 313 * 314 * @param p 315 * Must not be null. 316 * 317 * @param invoker 318 * The component responsible for showing the popup. can be null. 319 * Used such that when invoker pressed, the popup will not auto hide. 320 * 321 * @param loc 322 * Must not be null. 323 * 324 * @throws NullPointerException 325 * If p or loc is null 326 * 327 */ 328 public void showPopup(Popup p, Point loc, Component invoker) { 329 if (p == null) throw new NullPointerException("p"); 330 if (loc == null) throw new NullPointerException("animator"); 331 332 333 if (_popups.containsKey(p)) return; 334 335 p.prepareToPaint(); 336 p.setLocation(loc); 337 p.setVisible(true); 338 339 Browser._theBrowser.getLayeredPane().add(p, JLayeredPane.POPUP_LAYER, 0); 340 341 _popups.put(p, invoker); 342 if (invoker != null) _invokers.add(invoker); 343 344 p.onShowing(); 345 p.onShow(); 346 347 // Invalidate the popup border 348 if (p.getBorderThickness() > 0.0f) { 349 p.invalidateAppearance(); 350 } 351 } 352 353 /** 354 * Displays a popup at a specific location - with animation. 355 * 356 * @param p 357 * Must not be null. 358 * 359 * @param invoker 360 * The component responsible for showing the popup. can be null. 361 * Used such that when invoker pressed, the popup will not auto hide. 362 * 363 * @param loc 364 * Must not be null. 365 * 366 * @param animator 367 * Must not be null. 368 * 369 * @throws NullPointerException 370 * If p, animator or loc is null 371 */ 372 public void showPopup(Popup p, Point loc, Component invoker, PopupAnimator animator) { 373 if (animator == null) 374 throw new NullPointerException("animator"); 375 if (p == null) 376 throw new NullPointerException("p"); 377 if (loc == null) 378 throw new NullPointerException("loc"); 379 380 if (_popups.containsKey(p)) return; 381 382 _popups.put(p, invoker); 383 if (invoker != null) _invokers.add(invoker); 384 385 386 AnimatedPopup ap = new AnimatedPopup( 387 animator, 388 System.currentTimeMillis(), 389 p, 390 true, 391 loc); 392 393 394 animator.starting(true, new Rectangle(loc.x, loc.y, p.getWidth(), p.getHeight())); 395 396 p.onShowing(); 397 398 synchronized (_animatingPopups) { 399 _animatingPopups.add(ap); 400 } 401 402 if (_animationThread == null || !_animationThread.isAlive() || _animationThread.willDie) { 403 _animationThread = new AnimationThread(); 404 _animationThread.start(); 405 } 406 407 } 408 409 /** 410 * Does a pure asynch animation with no popups involved. 411 * 412 * For example you may want to have an effect such that an item is expanding 413 * or moving into a new location on the screen. 414 * 415 * @param animator 416 * Must not be null. 417 * 418 * @param target 419 * Must not be null. 420 * 421 * @throws NullPointerException 422 * If animator or target is null 423 * 424 */ 425 public void doPureAnimation(PopupAnimator animator, Rectangle target) { 426 427 if (animator == null) 428 throw new NullPointerException("animator"); 429 if (target == null) 430 throw new NullPointerException("target"); 431 432 AnimatedPopup ap = new AnimatedPopup( 433 animator, 434 System.currentTimeMillis(), 435 null, 436 false, 437 target.getLocation()); 438 439 440 animator.starting(true, target); 441 442 synchronized (_animatingPopups) { 443 _animatingPopups.add(ap); 444 } 445 446 if (_animationThread == null || !_animationThread.isAlive() || _animationThread.willDie) { 447 _animationThread = new AnimationThread(); 448 _animationThread.start(); 449 } 450 451 } 452 453 454 /** 455 * Paints all popups in the browsers popup pane with the given graphics. 456 * 457 * @param g 458 * Where to paint to. 459 * 460 * @param clip 461 */ 462 void paintLayeredPane(Graphics g, Area clip) { 463 if (Browser._theBrowser == null) return; 464 465 Component[] compsOnPopup = Browser._theBrowser.getLayeredPane().getComponentsInLayer(JLayeredPane.POPUP_LAYER); 466 467 for (int i = 0; i < compsOnPopup.length; i++) { 468 Component c = compsOnPopup[i]; 469 470 Point p = c.getLocation(); 471 472 if (clip == null || clip.intersects(c.getBounds())) { 473 g.translate(p.x, p.y); 474 c.paint(g); 475 g.translate(-p.x, -p.y); 476 } 477 478 } 169 public void frameChanged() 170 { 479 171 } 480 172 … … 482 174 * Paints current popup animations to the expeditee browser content pane. 483 175 */ 484 void paintAnimations() { 485 486 if (Browser._theBrowser == null 487 || Browser._theBrowser.g == null) return; 488 489 Graphics g = Browser._theBrowser.g; 490 491 synchronized (_animatingPopups) { 492 493 for (AnimatedPopup ap : _animatingPopups) { 494 ap.animator.paint(g); 495 } 496 497 } 498 } 499 500 /** 501 * Proccesses animation on a dedicated thread. 176 public void paint() 177 { 178 synchronized (_popups) { 179 for (Popup popup : _popups) { 180 popup.update(); 181 popup.paint(); 182 } 183 } 184 } 185 186 /** 187 * Provides animations for a popup when hiding or when showing. 188 * 189 * Note that {@link PopupAnimator#paint(Graphics)} and {@link PopupAnimator#update(float)} 190 * will always be invoked at seperate times - so do not have to worry about thread-safety. 191 * 192 * These should only be used once... one per popup at a time. 502 193 * 503 194 * @author Brook Novak 504 * 505 */ 506 private class AnimationThread extends Thread { 507 508 private boolean willDie = false; 195 */ 196 public static abstract class PopupAnimator 197 { 198 /** True if animating to show the popup, false if to hide. */ 199 private boolean _showing = true; 200 201 /** Whether the animation is currently paused. */ 202 private boolean _paused = true; 203 204 private long _startTime; 205 private long _duration; 206 private long _animationCurrentTime; 207 208 public PopupAnimator() 209 { 210 _animationCurrentTime = _startTime = System.currentTimeMillis(); 211 _duration = getDurationMillis(); 212 } 213 214 /** 215 * @return False if the animation has finished, true if further updates are required. 216 */ 217 public boolean update() 218 { 219 long currentTime = System.currentTimeMillis(); 220 221 if (currentTime > _startTime + _duration) { 222 currentTime = _startTime + _duration; 223 } 224 225 // If paused, make sure elapsed time stays constant 226 if (_paused) { 227 _startTime += currentTime - _animationCurrentTime; 228 } 229 230 _animationCurrentTime = currentTime; 231 232 return !isFinished(); 233 } 234 235 public void hide() 236 { 237 if (!_showing) return; 238 239 _showing = false; 240 complementAnimationProgress(); 241 } 242 243 public void show() 244 { 245 if (_showing) return; 246 247 _showing = true; 248 complementAnimationProgress(); 249 } 250 251 public boolean isShowing() 252 { 253 return _showing; 254 } 255 256 public void start() 257 { 258 _animationCurrentTime = _startTime = System.currentTimeMillis(); 259 unpause(); 260 } 261 262 public void pause() 263 { 264 pause(true); 265 } 266 267 public void unpause() 268 { 269 pause(false); 270 } 271 272 public void pause(boolean pause) 273 { 274 _paused = pause; 275 } 276 277 private void complementAnimationProgress() 278 { 279 _startTime = _animationCurrentTime - ((_startTime + _duration) - _animationCurrentTime); 280 } 281 282 public float getProgress() 283 { 284 return (_animationCurrentTime - _startTime) / ((float) _duration); 285 } 286 287 public boolean isFinished() 288 { 289 return _animationCurrentTime != _startTime + _duration; 290 } 291 292 public abstract long getDurationMillis(); 293 294 public abstract AxisAlignedBoxBounds getAnimatedBounds(AxisAlignedBoxBounds fullBounds); 295 296 } 297 298 public static class ExpandShrinkAnimator extends PopupAnimator 299 { 300 public static final long DURATION_MS = 2000; 301 302 public AxisAlignedBoxBounds _initialBounds = null; 303 304 public ExpandShrinkAnimator() 305 { 306 } 307 308 public ExpandShrinkAnimator(AxisAlignedBoxBounds initialBounds) 309 { 310 setInitialBounds(initialBounds); 311 } 312 313 public void setInitialBounds(AxisAlignedBoxBounds initialBounds) 314 { 315 _initialBounds = initialBounds; 316 } 509 317 510 318 @Override 511 public void run() { 512 513 514 LinkedList<AnimatedPopup> finishedAnimations; 515 516 while (true) { 517 518 // Perform animation logic 519 finishedAnimations = animate(); 520 521 // Check if finished all animations 522 if (finishedAnimations == null) return; // done 523 524 // Check for finalization of animation. That is, adding the popups to the layered pane 525 boolean needsFinalization = false; 526 for (AnimatedPopup ap : finishedAnimations) { 527 if (ap.isShowing) { 528 needsFinalization = true; 529 break; 530 } 531 532 // FInal invalidation 533 FrameGraphics.invalidateArea(ap.animator.getCurrentDrawingArea()); 534 535 } 536 537 if (needsFinalization) { 538 SwingUtilities.invokeLater(new AnimationFinalizor(finishedAnimations)); 539 // Will repaint when a popup becomes anchored... 540 } else { 541 FrameGraphics.requestRefresh(true); 542 } 543 544 // Limit animation rate 545 try { 546 sleep(ANIMATION_RATE); 547 } catch (InterruptedException e) { 548 e.printStackTrace(); 549 } 550 551 } 552 553 } 554 555 /** 556 * Performs animations 557 * @return 558 */ 559 private LinkedList<AnimatedPopup> animate() { 560 561 LinkedList<AnimatedPopup> finishedPopups = null; 562 563 synchronized (_animatingPopups) { 564 565 if (_animatingPopups.isEmpty()) { 566 willDie = true; 567 return null; 568 } 569 570 long currentTime = System.currentTimeMillis(); 571 572 finishedPopups = new LinkedList<AnimatedPopup>(); 573 574 for (AnimatedPopup ap : _animatingPopups) { 575 576 long duration = currentTime - ap.startTime; 577 578 if (duration >= ANIMATION_DURATION) { // check if complete 579 580 finishedPopups.add(ap); 581 582 } else { 583 584 float percent = ((float)duration / (float)ANIMATION_DURATION); 585 assert (percent >= 0.0f); 586 assert (percent < 1.0f); 587 588 Rectangle dirty = ap.animator.update(percent); 589 if (dirty != null) 590 FrameGraphics.invalidateArea(dirty); 591 592 } 593 594 } 595 596 _animatingPopups.removeAll(finishedPopups); 597 598 } 599 600 return finishedPopups; 601 602 } 603 604 /** 605 * Adds popups to layered pane 606 * @author Brook Novak 607 * 608 */ 609 private class AnimationFinalizor implements Runnable { 610 611 private LinkedList<AnimatedPopup> finished; 612 613 AnimationFinalizor(LinkedList<AnimatedPopup> finished) { 614 this.finished = finished; 615 } 616 617 public void run() { 618 619 for (AnimatedPopup ap : finished) { 620 621 if (ap.isShowing && _popups.containsKey(ap.popup)) { 622 623 ap.popup.prepareToPaint(); 624 ap.popup.setLocation(ap.popupLocation); 625 ap.popup.setVisible(true); 626 627 Browser._theBrowser.getLayeredPane().add(ap.popup, JLayeredPane.POPUP_LAYER, 0); 628 629 ap.popup.onShow(); 630 631 // Invalidate the popup border 632 if (ap.popup.getBorderThickness() > 0.0f) { 633 ap.popup.invalidateAppearance(); 634 } 635 } 636 637 } 638 639 } 640 } 641 } 642 643 private class AnimatedPopup { 644 645 PopupAnimator animator; 646 long startTime; 647 Popup popup = null; 648 boolean isShowing; 649 Point popupLocation; 650 651 public AnimatedPopup(PopupAnimator animator, long startTime, Popup popup, 652 boolean isShowing, Point popupLocation) { 653 654 assert(animator != null); 655 assert(popupLocation != null); 656 657 // Only have popup if showing 658 assert (!isShowing && popup == null || (isShowing && popup != null)); 659 660 661 this.animator = animator; 662 this.startTime = startTime; 663 this.popup = popup; 664 this.isShowing = isShowing; 665 this.popupLocation = popupLocation; 666 667 } 668 669 } 670 671 /** 672 * Provides animations for a popup when hiding or when showing. 673 * 674 * Note that {@link PopupAnimator#paint(Graphics)} and {@link PopupAnimator#update(float)} 675 * will always be invoked at seperate times - so do not have to worry about thread-saefty. 676 * 677 * These should only be used once... one per popup at a time. 678 * 679 * @author Brook Novak 680 * 681 */ 682 public interface PopupAnimator { 683 684 /** 685 * Invoked before showing. Any prepaations are done here. 686 * 687 * @param isShowing 688 * True if this animation will be for a popup that is showing. 689 * False if this animation will be for a popup that is hiding. 690 * 691 * @param popupBounds 692 * The location of the popup. I.E. where it is, or where it will be. 693 * 694 */ 695 void starting(boolean isShowing, Rectangle popupBounds); 696 697 /** 698 * 699 * Called on an animation thread. 700 * 701 * @param percent 702 * The percent complete of the animations. 703 * Rangles from 0 to 1. 704 * 705 * @return dirty area that needs painting for last update... Null for no invalidation 706 * 707 * 708 */ 709 Rectangle update(float percent); 710 711 /** 712 * Paints the animation - on the swing thread. 713 * Note that this is always on the content pane - not the expeditee frame buffer. 714 * 715 * @param g 716 * 717 */ 718 void paint(Graphics g); 719 720 721 /** 722 * 723 * @return 724 * The area which the animation is drawn. Used for final invalidation. Null for no final invaliation 725 */ 726 Rectangle getCurrentDrawingArea(); 727 728 } 729 730 731 public class ExpandShrinkAnimator implements PopupAnimator { 732 733 private boolean isShowing; 734 private Rectangle popupBounds; 735 private Rectangle sourceRectangle; 736 private Rectangle currentRectangle; 737 private Color fillColor; 738 739 private final Stroke stroke = new BasicStroke(2.0f); 740 741 /** 742 * 743 * @param sourceRectangle 744 * @param fillColor 745 * The fill color of the animated rectangle. Null for no fill. 746 */ 747 public ExpandShrinkAnimator(Rectangle sourceRectangle, Color fillColor) { 748 if (sourceRectangle == null) throw new NullPointerException("sourceRectangle"); 749 750 this.fillColor = fillColor; 751 this.sourceRectangle = (Rectangle)sourceRectangle.clone(); 752 this.currentRectangle = (Rectangle)sourceRectangle.clone(); 753 } 754 755 public void paint(Graphics g) { 756 757 if (fillColor != null) { 758 g.setColor(fillColor); 759 g.fillRect(currentRectangle.x, currentRectangle.y, currentRectangle.width, currentRectangle.height); 760 } 761 762 g.setColor(Color.BLACK); 763 ((Graphics2D)g).setStroke(stroke); 764 g.drawRect(currentRectangle.x, currentRectangle.y, currentRectangle.width, currentRectangle.height); 765 } 766 767 public void starting(boolean isShowing, Rectangle popupBounds) { 768 this.isShowing = isShowing; 769 this.popupBounds = popupBounds; 770 771 if (isShowing) { 772 this.currentRectangle = (Rectangle)sourceRectangle.clone(); 773 } else { 774 this.currentRectangle = (Rectangle)sourceRectangle.clone(); 775 } 776 777 } 778 779 public Rectangle update(float percent) { 780 781 Rectangle oldBounds = currentRectangle; 782 783 if (!isShowing) { // if minimizing just reverse percent 784 percent = 1 - percent; 785 } 786 787 // update X 788 currentRectangle.x = sourceRectangle.x + 789 (int)((popupBounds.x - sourceRectangle.x) * percent); 790 791 // update Y 792 currentRectangle.y = sourceRectangle.y + 793 (int)((popupBounds.y - sourceRectangle.y) * percent); 794 795 // update width 796 currentRectangle.width = sourceRectangle.width + 797 (int)((popupBounds.width - sourceRectangle.width) * percent); 798 799 // update height 800 currentRectangle.height = sourceRectangle.height + 801 (int)((popupBounds.height - sourceRectangle.height) * percent); 802 803 int x = Math.min(oldBounds.x, currentRectangle.x); 804 int y = Math.min(oldBounds.y, currentRectangle.y); 805 int width = Math.min(oldBounds.x + oldBounds.width, currentRectangle.x + currentRectangle.width) - x; 806 int height = Math.min(oldBounds.y + oldBounds.height, currentRectangle.y + currentRectangle.height) - y; 807 808 return new Rectangle(x, y, width, height); 809 810 } 811 812 public Rectangle getCurrentDrawingArea() { 813 return currentRectangle; 814 } 815 816 817 } 818 819 319 public long getDurationMillis() { return DURATION_MS; } 320 321 @Override 322 public AxisAlignedBoxBounds getAnimatedBounds(AxisAlignedBoxBounds fullBounds) 323 { 324 if (_initialBounds == null) { 325 setInitialBounds(fullBounds.clone()); 326 _initialBounds.getTopLeft().y += _initialBounds.getSize().height; 327 _initialBounds.getSize().height = 0; 328 } 329 330 float percentShown = getProgress(); 331 if (!isShowing()) percentShown = 1 - percentShown; 332 333 return AxisAlignedBoxBounds.lerp(_initialBounds, fullBounds, percentShown); 334 } 335 } 820 336 } -
trunk/src/org/expeditee/gui/Reminders.java
r919 r1102 19 19 package org.expeditee.gui; 20 20 21 import java.awt.Color;22 21 import java.util.Date; 23 22 23 import org.expeditee.Util; 24 24 import org.expeditee.actions.Misc; 25 import org.expeditee.core.Colour; 25 26 import org.expeditee.items.Text; 26 import org.expeditee.items.widgets.charts.TimeSeries;27 27 28 28 public class Reminders { … … 46 46 } 47 47 48 Date date = TimeSeries.parseDate(dateString);48 Date date = Util.parseDate(dateString); 49 49 long millisToWait = date.getTime() - new Date().getTime(); 50 50 final long adjustedToWait; … … 69 69 MessageBay.displayMessage( 70 70 "Reminder: " + reminderString, null, 71 Colo r.red, false, "StopReminder");71 Colour.RED, false, "StopReminder"); 72 72 Thread.sleep(5000); 73 73 // newMessage.setColor(new Color(100, 70, 70)); -
trunk/src/org/expeditee/gui/Vector.java
r919 r1102 19 19 package org.expeditee.gui; 20 20 21 import java.awt.Color;22 import java.awt.Dimension;23 import java.awt.Point;24 21 import java.text.NumberFormat; 25 22 23 import org.expeditee.core.Colour; 24 import org.expeditee.core.Dimension; 25 import org.expeditee.core.Point; 26 26 import org.expeditee.items.Item; 27 27 import org.expeditee.items.UserAppliedPermission; 28 28 29 /** 30 * TODO: Explain WTF this is. cts16 31 */ 29 32 public class Vector extends Overlay { 30 33 34 /** TODO: Comment. cts16 */ 31 35 public Point Origin; 32 36 37 /** TODO: Comment. cts16 */ 33 38 public float Scale; 34 39 35 public Color Foreground; 40 /** TODO: Comment. cts16 */ 41 public Colour Foreground; 36 42 37 public Color Background; 38 43 /** TODO: Comment. cts16 */ 44 public Colour Background; 45 46 /** TODO: Comment. cts16 */ 39 47 public Item Source; 40 48 49 /** TODO: Comment. cts16 */ 41 50 public Dimension Size; 42 51 43 public Vector(Frame overlay, UserAppliedPermission permission, 44 Float scale, Item source) { 52 /** TODO: Comment. cts16 */ 53 public Vector(Frame overlay, UserAppliedPermission permission, Float scale, Item source) 54 { 45 55 super(overlay, permission); 46 56 Origin = source.getPosition(); … … 52 62 53 63 @Override 54 public boolean equals(Object o) { 55 if (o == null || o.getClass() != Vector.class) 56 return false; 57 Vector v = (Vector) o; 58 59 return v.Frame == Frame && Origin.equals(v.Origin) 60 && Scale == v.Scale && Foreground == v.Foreground 61 && Background == v.Background; 64 public boolean equals(Object o) 65 { 66 if (o instanceof Vector) { 67 Vector v = (Vector) o; 68 return v.Frame == Frame && 69 Origin.equals(v.Origin) && 70 Scale == v.Scale && 71 Foreground.equals(v.Foreground) && 72 Background.equals(v.Background); 73 } 74 75 return false; 76 62 77 } 63 78 64 79 @Override 65 public int hashCode() { 80 public int hashCode() 81 { 66 82 return 0; 67 83 } 68 84 69 /** 70 * Converts the given x position to be relative to the overlay frame. 71 * 72 * @param x 73 * @return 74 */ 75 public float getX(int x) { 85 /** Converts the given x position to be relative to the overlay frame. */ 86 public float getX(int x) 87 { 76 88 return (x - Origin.x) / Scale; 77 89 } 78 90 79 public float getY(int y) { 91 /** Converts the given y position to be relative to the overlay frame. */ 92 public float getY(int y) 93 { 80 94 return (y - Origin.y) / Scale; 81 95 } 82 96 83 public void setSize(int maxX, int maxY) { 97 /** TODO: Comment. cts16 */ 98 public void setSize(int maxX, int maxY) 99 { 84 100 Size = new Dimension(maxX, maxY); 85 101 } 86 102 87 public static NumberFormat getNumberFormatter() { 103 /** TODO: Comment. cts16 */ 104 public static NumberFormat getNumberFormatter() 105 { 88 106 NumberFormat nf = NumberFormat.getInstance(); 89 107 nf.setMaximumFractionDigits(4); -
trunk/src/org/expeditee/importer/FileImporter.java
r919 r1102 19 19 package org.expeditee.importer; 20 20 21 import java.awt.Point;22 21 import java.io.File; 23 22 import java.io.IOException; 24 23 24 import org.expeditee.core.Point; 25 25 import org.expeditee.items.Item; 26 26 -
trunk/src/org/expeditee/importer/FilePathImporter.java
r919 r1102 19 19 package org.expeditee.importer; 20 20 21 import java.awt.Point;22 21 import java.io.File; 23 22 import java.io.IOException; 24 23 24 import org.expeditee.core.Point; 25 import org.expeditee.gio.DragAndDropManager; 25 26 import org.expeditee.items.Item; 26 27 … … 36 37 public Item importFile(File f, Point location) throws IOException { 37 38 if (location != null && f != null) { 38 return FrameDNDTransferHandler.importString(f.getAbsolutePath(), location);39 return DragAndDropManager.importString(f.getAbsolutePath(), location); 39 40 } 40 41 -
trunk/src/org/expeditee/importer/FrameDNDTransferHandler.java
r919 r1102 19 19 package org.expeditee.importer; 20 20 21 import java.awt.Point;22 21 import java.awt.datatransfer.DataFlavor; 23 22 import java.awt.datatransfer.UnsupportedFlavorException; … … 32 31 import javax.swing.TransferHandler; 33 32 33 import org.expeditee.core.Point; 34 import org.expeditee.gio.swing.SwingConversions; 34 35 import org.expeditee.gui.DisplayIO; 35 36 import org.expeditee.gui.FrameGraphics; … … 65 66 } 66 67 67 private FrameDNDTransferHandler() {68 68 private FrameDNDTransferHandler() 69 { 69 70 // Add standard file importers - order from most ideal to last resort 70 71 // (if competing) … … 74 75 _standardFileImporters.add(new pdfImporter()); 75 76 _standardFileImporters.add(new TextImporter()); 76 _standardFileImporters.add(new FilePathImporter()); // Filepath importer 77 // as last resort 77 _standardFileImporters.add(new FilePathImporter()); // Filepath importer as last resort 78 78 79 79 try { 80 _URIListDataflavorString = new DataFlavor( 81 "text/uri-list;class=java.lang.String"); 82 _URIListDataflavorCharArray = new DataFlavor( 83 "text/uri-list;class=\"[C\""); 84 } catch (ClassNotFoundException e) { // This would never happen, 85 // java.lang.String is always 86 // present 80 _URIListDataflavorString = new DataFlavor("text/uri-list;class=java.lang.String"); 81 _URIListDataflavorCharArray = new DataFlavor("text/uri-list;class=\"[C\""); 82 83 // This would never happen, java.lang.String is always present 84 } catch (ClassNotFoundException e) { 87 85 e.printStackTrace(); 88 86 _URIListDataflavorString = null; … … 104 102 * if importer is null. 105 103 */ 106 public void addCustomFileImporter(FileImporter importer) { 107 if (importer == null) 108 throw new NullPointerException("importer"); 109 if (!_customFileImporters.contains(importer)) 104 public void addCustomFileImporter(FileImporter importer) 105 { 106 if (importer == null) throw new NullPointerException("importer"); 107 108 if (!_customFileImporters.contains(importer)) { 110 109 _customFileImporters.add(importer); 110 } 111 111 112 112 } … … 121 121 * if importer is null. 122 122 */ 123 public void removeCustomFileImporter(FileImporter importer) { 124 if (importer == null) 125 throw new NullPointerException("importer"); 123 public void removeCustomFileImporter(FileImporter importer) 124 { 125 if (importer == null) throw new NullPointerException("importer"); 126 126 127 _customFileImporters.remove(importer); 127 128 } … … 135 136 136 137 // we only import Strings 137 if ( support.isDataFlavorSupported(DataFlavor.stringFlavor)138 || support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)139 || support.isDataFlavorSupported(_URIListDataflavorString)140 || support.isDataFlavorSupported(_URIListDataflavorCharArray)) {141 138 if ( support.isDataFlavorSupported(DataFlavor.stringFlavor) || 139 support.isDataFlavorSupported(DataFlavor.javaFileListFlavor) || 140 support.isDataFlavorSupported(_URIListDataflavorString) || 141 support.isDataFlavorSupported(_URIListDataflavorCharArray)) 142 { 142 143 // check if the source actions (a bitwise-OR of supported actions) 143 144 // contains the COPY action … … 154 155 155 156 @Override 156 public boolean importData(TransferSupport support) { 157 158 if (!canImport(support) || DisplayIO.getCurrentFrame() == null) 159 return false; 160 161 // Get the drop location of where to lot the import 157 public boolean importData(TransferSupport support) 158 { 159 if (!canImport(support) || DisplayIO.getCurrentFrame() == null) return false; 160 161 // Get the location of where to drop the import 162 162 DropLocation location = support.getDropLocation(); 163 163 164 // Co vert it into expeditee space165 Point expediteeDropPoint = location.getDropPoint();164 // Convert it into expeditee space 165 Point expediteeDropPoint = SwingConversions.fromSwingPoint(location.getDropPoint()); 166 166 167 167 try { … … 170 170 // keep trying until first 171 171 // data flavor recognized. 172 for (DataFlavor df : support.getTransferable() 173 .getTransferDataFlavors()) { 172 for (DataFlavor df : support.getTransferable().getTransferDataFlavors()) { 174 173 175 174 System.out.println(df); … … 177 176 if (df == DataFlavor.stringFlavor) { // import as text item 178 177 179 String str = (String) support.getTransferable() 180 .getTransferData(DataFlavor.stringFlavor); 178 String str = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor); 181 179 182 180 if (str != null && str.length() > 0) { … … 185 183 } 186 184 187 // Usually Windows and MAC enviroments 188 } else if (df == DataFlavor.javaFileListFlavor 189 || df.getSubType().equals("x-java-file-list")) { // Windows 190 // has 191 // other 192 // random 193 // types... 194 195 List<? extends File> files = (List<? extends File>) support 196 .getTransferable().getTransferData( 197 DataFlavor.javaFileListFlavor); 185 // Usually Windows and MAC enviroments 186 // Windows has other random types... 187 } else if (df == DataFlavor.javaFileListFlavor || df.getSubType().equals("x-java-file-list")) { 188 189 List<? extends File> files = (List<? extends File>) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); 198 190 199 191 importFileList(files, expediteeDropPoint); … … 201 193 return true; 202 194 203 195 // Usually GNOME and KDE enviroments 204 196 } else if (df.equals(_URIListDataflavorString)) { 205 197 206 String data = (String) support.getTransferable() 207 .getTransferData(_URIListDataflavorString); 198 String data = (String) support.getTransferable().getTransferData(_URIListDataflavorString); 208 199 209 200 List<File> files = textURIListToFileList(data); … … 215 206 } else if (df.equals(_URIListDataflavorCharArray)) { 216 207 217 char[] data = (char[]) support.getTransferable() 218 .getTransferData(_URIListDataflavorCharArray); 208 char[] data = (char[]) support.getTransferable().getTransferData(_URIListDataflavorCharArray); 219 209 220 210 String uriString = new String(data); … … 229 219 230 220 } catch (UnsupportedFlavorException e) { 231 MessageBay 232 .displayMessage("Drag and drop for that type of data is not supported"); 221 MessageBay.displayMessage("Drag and drop for that type of data is not supported"); 233 222 } catch (IOException e) { 234 223 e.printStackTrace(); … … 246 235 * 247 236 * @param expediteeDropPoint 248 * The location in the current e cpeditee frame of where to drop237 * The location in the current expeditee frame of where to drop 249 238 * the text item. 250 239 */ 251 public static Text importString(String text, Point expediteeDropPoint) {252 240 public static Text importString(String text, Point expediteeDropPoint) 241 { 253 242 assert (DisplayIO.getCurrentFrame() != null); 254 243 assert (text != null && text.length() > 0); 255 244 256 Text importedTextItem = new Text(DisplayIO.getCurrentFrame() 257 .getNextItemID(), text); 245 Text importedTextItem = new Text(DisplayIO.getCurrentFrame().getNextItemID(), text); 258 246 importedTextItem.setPosition(expediteeDropPoint); 259 247 … … 264 252 } 265 253 266 public void importFileList(List<? extends File> files, 267 Point expediteeDropPoint) throws IOException{268 269 Point currentPoint = expediteeDropPoint.getLocation(); 270 271 for (File fileToImport : files) { // import files one by one254 public void importFileList(List<? extends File> files, Point expediteeDropPoint) throws IOException 255 { 256 Point currentPoint = new Point(expediteeDropPoint); 257 258 // import files one by one 259 for (File fileToImport : files) { 272 260 273 261 Item lastItem = importFile(fileToImport, currentPoint); … … 296 284 * @throws IOException 297 285 */ 298 public Item importFile(File f, Point expediteeDropPoint) throws IOException { 286 public Item importFile(File f, Point expediteeDropPoint) throws IOException 287 { 299 288 assert (f != null); 300 289 … … 302 291 // importing routines... 303 292 Item lastCreatedItem; 304 if (null == (lastCreatedItem = performFileImport(_customFileImporters, 305 f, expediteeDropPoint))) { 306 293 if (null == (lastCreatedItem = performFileImport(_customFileImporters, f, expediteeDropPoint))) { 307 294 // Standard file importing 308 lastCreatedItem = performFileImport(_standardFileImporters, f, 309 expediteeDropPoint); 310 311 } 295 lastCreatedItem = performFileImport(_standardFileImporters, f, expediteeDropPoint); 296 } 297 312 298 return lastCreatedItem; 313 299 } 314 300 315 private Item performFileImport(List<FileImporter> importers, File f, 316 Point expediteeDropPoint) throws IOException { 317 301 private Item performFileImport(List<FileImporter> importers, File f, Point expediteeDropPoint) throws IOException 302 { 318 303 for (FileImporter fi : importers) { 319 304 Item lastCreated = fi.importFile(f, expediteeDropPoint); 320 if (lastCreated != null)321 305 306 if (lastCreated != null) return lastCreated; 322 307 } 323 308 … … 326 311 327 312 /** 313 * Converts a string formatted as a list of URIs into a list of Files. 314 * 328 315 * Code adopted from SUN - java BUG ID 4899516 workaround for KDE/GNOME 329 316 * Desktops … … 334 321 * @return The list of FILES in the uriListString. Never null. 335 322 */ 336 private List<File> textURIListToFileList(String uriListString) {337 323 private List<File> textURIListToFileList(String uriListString) 324 { 338 325 List<File> fileList = new LinkedList<File>(); 339 326 340 for (StringTokenizer st = new StringTokenizer(uriListString, "\r\n"); st 341 .hasMoreTokens();) { 327 for (StringTokenizer st = new StringTokenizer(uriListString, "\r\n"); st.hasMoreTokens();) { 342 328 343 329 String s = st.nextToken(); -
trunk/src/org/expeditee/importer/ImageImporter.java
r919 r1102 19 19 package org.expeditee.importer; 20 20 21 import java.awt.Color;22 import java.awt.Point;23 import java.awt.Rectangle;24 21 import java.io.File; 25 22 import java.io.IOException; … … 27 24 import java.util.HashSet; 28 25 29 import org.expeditee.gui.DisplayIO; 30 import org.expeditee.gui.FrameKeyboardActions; 31 import org.expeditee.gui.FrameMouseActions; 26 import org.expeditee.core.Colour; 27 import org.expeditee.core.Point; 28 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 29 import org.expeditee.gio.DragAndDropManager; 30 import org.expeditee.gio.gesture.StandardGestureActions; 31 import org.expeditee.gui.DisplayController; 32 32 import org.expeditee.gui.FrameUtils; 33 33 import org.expeditee.items.Item; … … 65 65 } 66 66 67 Colo r borderColor = null;67 Colour borderColor = null; 68 68 float thickness = 0; 69 69 String size = ""; … … 72 72 for (Item i : enclosure) { 73 73 if (i.isLineEnd() && i.isEnclosed()) { 74 Display IO.getCurrentFrame().removeAllItems(enclosure);75 Rectangle rect = i.getEnclosedRectangle();74 DisplayController.getCurrentFrame().removeAllItems(enclosure); 75 AxisAlignedBoxBounds rect = i.getEnclosedBox(); 76 76 size = " " + Math.round(rect.getWidth()); 77 location = new Point(rect. x, rect.y);77 location = new Point(rect.getMinX(), rect.getMinY()); 78 78 thickness = i.getThickness(); 79 79 borderColor = i.getColor(); … … 81 81 } 82 82 } 83 FrameMouseActions.deleteItems(enclosure, false);83 StandardGestureActions.deleteItems(enclosure, false); 84 84 } 85 85 86 Text source = FrameDNDTransferHandler.importString("@i: " + fullPath 87 + size, location); 86 Text source = DragAndDropManager.importString("@i: " + fullPath + size, location); 88 87 source.setThickness(thickness); 89 88 source.setBorderColor(borderColor); 90 89 91 FrameKeyboardActions.Refresh();90 StandardGestureActions.Refresh(); 92 91 Collection<? extends XRayable> pictures = source.getEnclosures(); 93 92 if (pictures.size() == 0) -
trunk/src/org/expeditee/importer/TextImporter.java
r919 r1102 19 19 package org.expeditee.importer; 20 20 21 import java.awt.Color;22 import java.awt.Point;23 21 import java.io.BufferedReader; 24 22 import java.io.File; … … 26 24 import java.io.IOException; 27 25 26 import org.expeditee.core.Colour; 27 import org.expeditee.core.Point; 28 import org.expeditee.gio.DragAndDropManager; 29 import org.expeditee.gui.DisplayController; 28 30 import org.expeditee.gui.FrameCreator; 29 31 import org.expeditee.gui.FrameGraphics; … … 44 46 final String fullPath = f.getAbsolutePath(); 45 47 46 final Text source = FrameDNDTransferHandler.importString(f.getPath(), 47 location); 48 final Text source = DragAndDropManager.importString(f.getPath(), location); 48 49 49 50 // Create a frameCreator to write the text … … 54 55 try { 55 56 // Open a file stream to the file 56 BufferedReader br = new BufferedReader(new FileReader( 57 fullPath)); 57 BufferedReader br = new BufferedReader(new FileReader(fullPath)); 58 58 59 59 MessageBay.displayMessage("Importing " + f.getName() + "..."); … … 67 67 frames.save(); 68 68 source.setLink(frames.getName()); 69 MessageBay.displayMessage(f.getName() + " import complete", Colo r.GREEN);70 FrameGraphics.requestRefresh(true);69 MessageBay.displayMessage(f.getName() + " import complete", Colour.GREEN); 70 DisplayController.requestRefresh(true); 71 71 } catch (Exception e) { 72 72 e.printStackTrace(); … … 75 75 } 76 76 }.start(); 77 FrameGraphics.refresh(true);77 DisplayController.requestRefresh(true); 78 78 return source; 79 79 } -
trunk/src/org/expeditee/importer/pdfImporter.java
r919 r1102 19 19 package org.expeditee.importer; 20 20 21 import java.awt.Color;22 import java.awt.Graphics;23 import java.awt.Image;24 import java.awt.Point;25 import java.awt.Rectangle;26 import java.awt.image.BufferedImage;27 21 import java.io.File; 28 22 import java.io.IOException; … … 31 25 import java.nio.channels.FileChannel; 32 26 33 import javax.imageio.ImageIO; 34 35 import org.expeditee.gui.Browser; 27 import org.expeditee.core.Colour; 28 import org.expeditee.core.Image; 29 import org.expeditee.core.Point; 30 import org.expeditee.gio.DragAndDropManager; 31 import org.expeditee.gio.EcosystemManager; 32 import org.expeditee.gio.GraphicsManager; 33 import org.expeditee.gui.DisplayController; 36 34 import org.expeditee.gui.Frame; 37 35 import org.expeditee.gui.FrameCreator; … … 54 52 final int x = 0; 55 53 final int y = 60; 56 final int width = Browser._theBrowser.getSize().width;54 final int width = EcosystemManager.getGraphicsManager().getWindowSize().width; 57 55 System.out.println(width); 58 56 … … 65 63 } 66 64 67 final Text link = FrameDNDTransferHandler.importString(name, location);65 final Text link = DragAndDropManager.importString(name, location); 68 66 link.setLink(name+"1"); 69 67 … … 97 95 Frame _currentFrame=null; 98 96 Text nextButton=null, prevButton=null; 99 final float spacing=((Text)FrameCreator.createButton("Next", null, null, 10F, 10F)).getBoundsWidth() + 30F;97 final int spacing=((Text)FrameCreator.createButton("Next", null, null, 10, 10)).getBoundsWidth() + 30; 100 98 101 99 //make images from the pdf pages, write frames with those images … … 128 126 } 129 127 //generate the image 130 Image img = page.getImage(w, h, //width & height 131 new Rectangle(0, 0, (int)page.getBBox().getWidth(), (int)page.getBBox().getHeight()), //clip rect 132 null, //null for the ImageObserver 133 true, //fill background with white 134 true //block until drawing is done 135 ); 128 Image img = Image.createImage(w, h, page); 136 129 //Create a buffered image to store the image in 137 BufferedImage bimg = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);138 Graphics g = bimg.createGraphics();130 Image bimg = Image.createImage(img.getWidth(), img.getHeight(), false); 131 GraphicsManager g = EcosystemManager.getGraphicsManager(); 139 132 //Paint the image onto the buffered image 140 g.drawImage(img, 0, 0, null); 141 g.dispose(); 133 g.pushDrawingSurface(bimg); 134 g.drawImage(img, new Point(0, 0)); 135 g.popDrawingSurface(); 142 136 //save it as a file 143 137 File out = new File(framesetPath+i+".png"); 144 ImageIO.write(bimg,"png", out);138 bimg.writeToDisk("png", out); 145 139 //generate a frame with that image 146 140 System.out.println(width); … … 150 144 { 151 145 //put a next button on the previous frame (points to current frame) 152 nextButton=(Text)FrameCreator.createButton("Next", null, null, 10 F, 10F);146 nextButton=(Text)FrameCreator.createButton("Next", null, null, 10, 10); 153 147 nextButton.setID(_currentFrame.getNextItemID()); 154 148 nextButton.addAction("next"); 155 149 _currentFrame.addItem(nextButton); 156 150 //put a previous button on the current frame (points to previous frame) 157 prevButton=(Text)FrameCreator.createButton("Prev", null, null, (i<pages)?spacing:10 F, 10F);151 prevButton=(Text)FrameCreator.createButton("Prev", null, null, (i<pages)?spacing:10, 10); 158 152 prevButton.setID(currentFrame.getNextItemID()); 159 153 prevButton.addAction("previous"); … … 162 156 else 163 157 { 164 prevButton=(Text)FrameCreator.createButton("Home", null, null, (i<pages)?spacing:10 F, 10F);158 prevButton=(Text)FrameCreator.createButton("Home", null, null, (i<pages)?spacing:10, 10); 165 159 prevButton.setID(currentFrame.getNextItemID()); 166 160 prevButton.addAction("GotoHome"); … … 171 165 if(i<pages) currentFrame = FrameIO.CreateFrame(frameset.getFramesetName(), name, null); 172 166 } 173 prevButton=(Text)FrameCreator.createButton("Home", null, null, spacing, 10 F);167 prevButton=(Text)FrameCreator.createButton("Home", null, null, spacing, 10); 174 168 prevButton.setID(currentFrame.getNextItemID()); 175 169 prevButton.addAction("gotohome"); 176 170 currentFrame.addItem(prevButton); 177 171 FrameIO.SaveFrame(currentFrame,true); 178 MessageBay.displayMessage(f.getName() + " import complete", Colo r.GREEN);179 FrameGraphics.requestRefresh(true);172 MessageBay.displayMessage(f.getName() + " import complete", Colour.GREEN); 173 DisplayController.requestRefresh(true); 180 174 } catch (Exception e) { 181 175 e.printStackTrace(); … … 184 178 } 185 179 }.start(); 186 FrameGraphics.refresh(true);180 DisplayController.requestRefresh(true); 187 181 //return source; 188 182 return link; -
trunk/src/org/expeditee/io/AbstractHTMLWriter.java
r919 r1102 19 19 package org.expeditee.io; 20 20 21 import java.awt.Color;22 import java.awt.Font;23 21 import java.io.File; 24 22 import java.io.IOException; … … 26 24 import java.util.List; 27 25 26 import org.expeditee.core.Colour; 27 import org.expeditee.core.Font; 28 28 import org.expeditee.gui.Frame; 29 29 import org.expeditee.gui.FrameIO; … … 88 88 return; 89 89 90 writer.write(styleName + " { font-family: " 91 + Conversion.getCssFontFamily(font.getFamily())); 90 writer.write(styleName + " { font-family: " + Conversion.getCssFontFamily(font.getFamilyName())); 92 91 93 92 // writer.write("; font-size: " + Math.round(style.getSize()) + "px"); … … 104 103 writer.write("; font-style: normal"); 105 104 } 106 Colo r c = style.getBackgroundColor();105 Colour c = style.getBackgroundColor(); 107 106 if (c != null) { 108 107 writer.write("; background-color: " + Conversion.getCssColor(c)); -
trunk/src/org/expeditee/io/Conversion.java
r919 r1102 19 19 package org.expeditee.io; 20 20 21 import java.awt.Color;22 import java.awt.Font;23 import java.awt.Point;24 21 import java.lang.reflect.Field; 25 22 import java.lang.reflect.Method; … … 29 26 30 27 import org.expeditee.actions.Actions; 28 import org.expeditee.core.Colour; 29 import org.expeditee.core.Font; 30 import org.expeditee.core.Point; 31 31 import org.expeditee.items.Item; 32 32 import org.expeditee.items.Text; … … 43 43 public class Conversion { 44 44 45 public static final int RGB_MAX = 255;46 47 private static final float RGB_CONVERSION_FACTOR = 2.55F;45 public static final short RGB_MAX = Colour.COMPONENT_MAX_VALUE; 46 47 private static final float RGB_CONVERSION_FACTOR = RGB_MAX / 100.0f; 48 48 49 49 /** … … 56 56 * @return The Color object corresponding to the given code 57 57 */ 58 public static Colo r getColor(String colorCode, Color current) {58 public static Colour getColor(String colorCode, Colour current) { 59 59 if (colorCode == null) { 60 60 return null; … … 66 66 67 67 // check if its a normal rgb code ie. 100 0 40 68 Colo r rgb = getRGBColor(colorCode, current);68 Colour rgb = getRGBColor(colorCode, current); 69 69 if (rgb != null) 70 70 return rgb; … … 104 104 return null; 105 105 106 return new Colo r(color[0], color[1], color[2]);107 } 108 109 private static Colo r getRGBColor(String colorCode, Color current) {106 return new Colour(color[0], color[1], color[2]); 107 } 108 109 private static Colour getRGBColor(String colorCode, Colour current) { 110 110 int color[] = new int[4]; 111 111 // Assert.assertTrue(color.length == 3); … … 135 135 color[i] = toRGB(color[i]); 136 136 } 137 return new Colo r(color[0], color[1], color[2], color[3]);137 return new Colour(color[0], color[1], color[2], color[3]); 138 138 } catch (Exception e) { 139 139 return null; … … 175 175 * is black. 176 176 */ 177 public static String getExpediteeColorCode(Colo r color) {177 public static String getExpediteeColorCode(Colour color) { 178 178 if (color == null) 179 179 return null; … … 195 195 */ 196 196 public static String getExpediteeFontCode(Font font) { 197 String fontName = font.getFamily ();198 String code = font.getFamily () + '_';197 String fontName = font.getFamilyName(); 198 String code = font.getFamilyName() + '_'; 199 199 200 200 for (int i = 0; i < Text.FONT_WHEEL.length; i++) { … … 206 206 207 207 switch (font.getStyle()) { 208 case Font.BOLD:208 case BOLD: 209 209 code += "b"; 210 210 break; 211 case Font.PLAIN:211 case PLAIN: 212 212 code += "r"; 213 213 break; 214 case Font.ITALIC:214 case ITALIC: 215 215 code += "i"; 216 216 break; … … 237 237 238 238 int separator = fontCode.indexOf('_'); 239 String code = Text.FONT_WHEEL[0];239 String familyName = Text.FONT_WHEEL[0]; 240 240 if (separator > 0) { 241 code = Actions.getCapitalizedFontName(fontCode.substring(0, 242 separator)) + '-'; 241 familyName = Actions.getCapitalizedFontName(fontCode.substring(0, separator)); 243 242 fontCode = fontCode.substring(separator); 244 243 } else { … … 246 245 for (int i = 0; i < Text.FONT_CHARS.length; i++) { 247 246 if (c == Text.FONT_CHARS[i]) { 248 code = Text.FONT_WHEEL[i] + '-';247 familyName = Text.FONT_WHEEL[i]; 249 248 break; 250 249 } 251 250 } 252 251 } 252 253 Font font = new Font(familyName); 253 254 254 255 switch (fontCode.charAt(1)) { 255 256 case 'r': 256 code += "Plain";257 font.setStyle(Font.Style.PLAIN); 257 258 break; 258 259 case 'b': 259 code += "Bold";260 font.setStyle(Font.Style.BOLD); 260 261 break; 261 262 case 'i': 262 code += "Italic";263 font.setStyle(Font.Style.ITALIC); 263 264 break; 264 265 case 'p': 265 code += "BoldItalic";266 font.setStyle(Font.Style.BOLD_ITALIC); 266 267 break; 267 268 } 268 269 code += "-";270 271 Font font = null;272 269 273 270 try { 274 271 int size = Integer.parseInt(fontCode.substring(2)); 275 // double dsize = size * FONT_SCALE; 276 // if (dsize - ((int) dsize) > FONT_ROUNDING) 277 // dsize = Math.ceil(dsize); 278 279 // code += (int) dsize; 280 code += size; 281 282 font = Font.decode(code); 272 273 font.setSize(size); 283 274 } catch (NumberFormatException nfe) { 284 font = Font.decode(fontCode);275 // Just keep going 285 276 } 286 277 … … 362 353 } 363 354 364 if (type.equals(Colo r.class)) {355 if (type.equals(Colour.class)) { 365 356 if (value.length() == 0) 366 357 return null; … … 368 359 try { 369 360 // Try to decode the string as a hex or octal color code 370 return Colo r.decode(value);361 return Colour.decode(value); 371 362 } catch (NumberFormatException nfe) { 372 363 try { 373 // Try to find the field in the Colo r class with the same name as the given string374 Field[] fields = java.awt.Color.class.getFields();364 // Try to find the field in the Colour class with the same name as the given string 365 Field[] fields = Colour.class.getFields(); 375 366 Field field = null; 376 367 for (int i = 0; i < fields.length; i++) { … … 380 371 } 381 372 } 382 return (Colo r) field.get(null);373 return (Colour) field.get(null); 383 374 } catch (Exception e) { 384 return getColor(value, (Colo r) orig);375 return getColor(value, (Colour) orig); 385 376 } 386 377 } … … 388 379 389 380 if (type.equals(int.class)) { 390 if (orig instanceof Integer 391 && (value.startsWith("+") || value.startsWith("-"))) { 381 if (orig instanceof Integer && (value.startsWith("+") || value.startsWith("-"))) { 392 382 value = value.replace("+", ""); 393 383 … … 395 385 } 396 386 397 if (value.length() == 0 || value.equals("null")) 398 return Item.DEFAULT_INTEGER; 387 if (value.length() == 0 || value.equals("null")) return Item.DEFAULT_INTEGER; 399 388 400 389 return Integer.decode(value); … … 427 416 428 417 if (type.equals(Integer.class)) { 429 if (orig instanceof Integer 430 && (value.startsWith("+") || value.startsWith("-"))) { 418 if (orig instanceof Integer && (value.startsWith("+") || value.startsWith("-"))) { 431 419 value = value.replace("+", ""); 432 420 433 Integer newValue = ((Integer) orig) + Integer. parseInt(value);421 Integer newValue = ((Integer) orig) + Integer.valueOf((int) Double.parseDouble(value)); 434 422 if (newValue <= 0) 435 423 return null; … … 440 428 return null; 441 429 442 return Integer. parseInt(value);430 return Integer.valueOf((int) Double.parseDouble(value)); 443 431 } 444 432 … … 700 688 701 689 // convert colors 702 if (output instanceof Colo r)703 return getExpediteeColorCode((Colo r) output);690 if (output instanceof Colour) 691 return getExpediteeColorCode((Colour) output); 704 692 705 693 // covert points … … 737 725 } 738 726 739 public static String getCssColor(Colo r c) {727 public static String getCssColor(Colour c) { 740 728 assert (c != null); 741 return "rgb(" + c.getRed () + "," + c.getGreen() + "," + c.getBlue()729 return "rgb(" + c.getRed255() + "," + c.getGreen255() + "," + c.getBlue255() 742 730 + ")"; 743 731 } -
trunk/src/org/expeditee/io/DefaultFrameReader.java
r919 r1102 19 19 package org.expeditee.io; 20 20 21 import java.awt.Color;22 import java.awt.Font;23 import java.awt.Point;24 21 import java.io.BufferedReader; 25 22 import java.io.FileInputStream; … … 32 29 import java.util.LinkedList; 33 30 31 import org.expeditee.core.Colour; 32 import org.expeditee.core.Font; 33 import org.expeditee.core.Point; 34 34 import org.expeditee.gui.Frame; 35 35 import org.expeditee.items.Constraint; 36 import org.expeditee.items.Dot; 36 37 import org.expeditee.items.DotType; 37 38 import org.expeditee.items.Item; … … 42 43 43 44 public abstract class DefaultFrameReader implements FrameReader { 45 44 46 protected static LinkedHashMap<Character, Method> _ItemTags = null; 45 47 … … 53 55 protected static Class[] pFloat = { float.class }; 54 56 protected static Class[] pFloatO = { Float.class }; 55 protected static Class[] pColor = { Color.class }; 57 protected static Class[] pDouble = { double.class }; 58 protected static Class[] pColor = { Colour.class }; 56 59 protected static Class[] pBool = { boolean.class }; 57 60 protected static Class[] pFont = { Font.class }; … … 63 66 protected static Class[] pJustification = { Justification.class }; 64 67 protected static Class[] pPermission = { PermissionPair.class }; 68 protected static Class[] pDotType = { DotType.class }; 65 69 66 70 public DefaultFrameReader(){ … … 100 104 pColor)); 101 105 102 _ItemTags.put('R', Item.class.getMethod("setAnchorLeft", p FloatO));103 _ItemTags.put('H', Item.class.getMethod("setAnchorRight", p FloatO));104 _ItemTags.put('N', Item.class.getMethod("setAnchorTop", p FloatO));105 _ItemTags.put('I', Item.class.getMethod("setAnchorBottom", p FloatO));106 _ItemTags.put('R', Item.class.getMethod("setAnchorLeft", pIntO)); 107 _ItemTags.put('H', Item.class.getMethod("setAnchorRight", pIntO)); 108 _ItemTags.put('N', Item.class.getMethod("setAnchorTop", pIntO)); 109 _ItemTags.put('I', Item.class.getMethod("setAnchorBottom", pIntO)); 106 110 107 111 _ItemTags.put('P', Item.class.getMethod("setPosition", pPoint)); … … 123 127 _ItemTags.put('e', Item.class.getMethod("setFillColor", pColor)); 124 128 _ItemTags.put('E', Item.class.getMethod("setGradientColor", pColor)); 125 _ItemTags.put('Q', Item.class.getMethod("setGradientAngle", p Int));129 _ItemTags.put('Q', Item.class.getMethod("setGradientAngle", pDouble)); 126 130 127 131 _ItemTags.put('i', Item.class.getMethod("setFillPattern", pString)); … … 136 140 _ItemTags.put('j', Item.class.getMethod("setArrow", pArrow)); 137 141 138 _ItemTags.put('v', Item.class.getMethod("setDotType", new Class[]{DotType.class}));139 _ItemTags.put('z', Item.class.getMethod("setFilled", pBool));142 _ItemTags.put('v', Dot.class.getMethod("setDotType", pDotType)); 143 _ItemTags.put('z', Dot.class.getMethod("setFilled", pBool)); 140 144 141 145 _ItemTags.put('f', Text.class.getMethod("setFont", pFont)); -
trunk/src/org/expeditee/io/DefaultFrameWriter.java
r919 r1102 19 19 package org.expeditee.io; 20 20 21 import java.awt.Desktop;22 21 import java.io.BufferedOutputStream; 23 22 import java.io.File; … … 33 32 34 33 import org.expeditee.agents.WriteTree; 34 import org.expeditee.gio.EcosystemManager; 35 35 import org.expeditee.gui.Browser; 36 36 import org.expeditee.gui.Frame; … … 258 258 _writer.close(); 259 259 } 260 try { 261 if (Browser._theBrowser.isMinimumVersion6()) { 262 if (Desktop.isDesktopSupported()) { 263 Desktop.getDesktop().open(new File(_output)); 264 } 265 } 266 } catch (Exception e) { 267 e.printStackTrace(); 268 } 260 String errorMessage = EcosystemManager.getMiscManager().open(_output); 261 if (errorMessage != null) System.err.println(errorMessage); 269 262 return " exported to " + _output; 270 263 } -
trunk/src/org/expeditee/io/ExaReader.java
r919 r1102 173 173 // refresh the last item loaded 174 174 if(item != null) { 175 item. updatePolygon();175 item.invalidateBounds(); 176 176 item.invalidateAll(); 177 177 } … … 200 200 // refresh the last item loaded 201 201 if(item != null) { 202 item. updatePolygon();202 item.invalidateBounds(); 203 203 item.invalidateAll(); 204 204 } -
trunk/src/org/expeditee/io/ExaWriter.java
r919 r1102 29 29 30 30 import org.expeditee.gui.AttributeUtils; 31 import org.expeditee.gui.AttributeUtils.Attribute;32 31 import org.expeditee.gui.Frame; 33 32 import org.expeditee.items.Constraint; -
trunk/src/org/expeditee/io/ExpClipReader.java
r919 r1102 25 25 import java.util.List; 26 26 27 import org.expeditee.gui.DisplayIO; 27 import org.expeditee.core.Point; 28 import org.expeditee.gui.DisplayController; 28 29 import org.expeditee.gui.Frame; 29 30 import org.expeditee.gui.FrameGraphics; … … 37 38 import org.expeditee.items.Line; 38 39 import org.expeditee.items.Text; 39 import org.expeditee.items.widgets. InteractiveWidget;40 import org.expeditee.items.widgets.Widget; 40 41 41 42 /** … … 52 53 private int dX, dY; 53 54 55 public ExpClipReader(Point p) 56 { 57 this(p.x, p.y); 58 } 59 54 60 public ExpClipReader(int dX, int dY) { 55 61 super(""); … … 63 69 */ 64 70 public static void updateItems(List<Item> items) { 65 if( FrameGraphics.isXRayMode()) {71 if(DisplayController.isXRayMode()) { 66 72 return; 67 73 } … … 72 78 continue; 73 79 } 74 if (ItemUtils.startsWithTag(item, 75 ItemUtils.TAG_IMAGE, true)) { 80 if (ItemUtils.startsWithTag(item, ItemUtils.TAG_IMAGE, true)) { 76 81 if (!item.hasEnclosures()) { 77 items.add(ItemUtils.CreatePicture((Text) item , DisplayIO.getCurrentFrame()));82 items.add(ItemUtils.CreatePicture((Text) item)); 78 83 } 79 84 // check for frame images … … 83 88 && !item.getAbsoluteLink() 84 89 .equalsIgnoreCase( 85 Display IO.getCurrentFrame().getName())) {90 DisplayController.getCurrentFrame().getName())) { 86 91 if (item.hasEnclosures()) { 87 92 // item.setHidden(true); … … 90 95 // image.refresh(); 91 96 } else { 92 items.add(new FrameImage((Text) item, DisplayIO.getCurrentFrame(),null));97 items.add(new FrameImage((Text) item, null)); 93 98 } 94 99 } else if (ItemUtils.startsWithTag(item, … … 97 102 && !item.getAbsoluteLink() 98 103 .equalsIgnoreCase( 99 Display IO.getCurrentFrame().getName())) {104 DisplayController.getCurrentFrame().getName())) { 100 105 if (item.hasEnclosures()) { 101 106 // image = … … 107 112 // frame which already has a bitmap dont 108 113 // recreate the bitmap 109 items.add(new FrameBitmap((Text) item, DisplayIO.getCurrentFrame(),null));114 items.add(new FrameBitmap((Text) item, null)); 110 115 } 111 116 } else if (ItemUtils.startsWithTag(item, "@c")) { … … 116 121 } 117 122 // Check for interactive widgets 118 } else if (ItemUtils.startsWithTag(item, 119 ItemUtils.TAG_IWIDGET)) { 123 } else if (ItemUtils.startsWithTag(item, ItemUtils.TAG_IWIDGET)) { 120 124 items.remove(item); 121 item.setParent(Display IO.getCurrentFrame());125 item.setParent(DisplayController.getCurrentFrame()); 122 126 try { 123 items.addAll( InteractiveWidget.createWidget((Text) item).getItems());127 items.addAll(Widget.createWidget((Text) item).getItems()); 124 128 } catch (Exception e) { 125 129 System.err.println("Failed to create widget"); … … 176 180 while(index < lines.length && !(lines[++index].equals("Z"))) { 177 181 if (isValidLine(lines[index])) { 178 java.awt.Point idtype = separateValues(lines[index].substring(2));182 Point idtype = separateValues(lines[index].substring(2)); 179 183 // The next line must be the endpoints 180 184 if (index >= lines.length) 181 185 throw new Exception("Unexpected end of file"); 182 186 ++index; 183 java.awt.Point startend = separateValues(lines[index].substring(2));187 Point startend = separateValues(lines[index].substring(2)); 184 188 int start = startend.x; 185 189 int end = startend.y; … … 199 203 while(index < lines.length && !(lines[++index].equals("Z"))) { 200 204 if (isValidLine(lines[index])) { 201 java.awt.Point idtype = separateValues(lines[index].substring(2));205 Point idtype = separateValues(lines[index].substring(2)); 202 206 // The next line must be the endpoints 203 207 if (index >= lines.length) 204 208 throw new Exception("Unexpected end of file"); 205 209 ++index; 206 java.awt.Point startend = separateValues(lines[index].substring(2));210 Point startend = separateValues(lines[index].substring(2)); 207 211 208 212 Item a = _linePoints.get(startend.x); -
trunk/src/org/expeditee/io/ExpClipWriter.java
r919 r1102 23 23 import java.util.List; 24 24 25 import org.expeditee.core.Point; 25 26 import org.expeditee.gui.Frame; 26 27 import org.expeditee.items.Item; 27 28 import org.expeditee.items.Line; 28 29 import org.expeditee.items.XRayable; 29 import org.expeditee.items.widgets. InteractiveWidget;30 import org.expeditee.items.widgets.Widget; 30 31 import org.expeditee.items.widgets.WidgetCorner; 31 32 import org.expeditee.items.widgets.WidgetEdge; … … 41 42 private int dX, dY; 42 43 44 public ExpClipWriter(Point p) 45 { 46 this(p.x, p.y); 47 } 48 43 49 public ExpClipWriter(int dX, int dY) { 44 50 super(); … … 60 66 public void output(List<Item> items) throws IOException { 61 67 // switch to savable items 62 LinkedList< InteractiveWidget> widgets = new LinkedList<InteractiveWidget>();68 LinkedList<Widget> widgets = new LinkedList<Widget>(); 63 69 // make an array to iterate over instead of the list so we don't get stuck when we remove items from the list 64 70 Item[] tmpitems = items.toArray(new Item[0]); … … 72 78 } 73 79 } else if (i instanceof WidgetCorner) { 74 InteractiveWidget iw = ((WidgetCorner)i).getWidgetSource();80 Widget iw = ((WidgetCorner)i).getWidgetSource(); 75 81 if(!widgets.contains(iw)) { 76 82 widgets.add(iw); … … 78 84 items.remove(i); 79 85 } else if (i instanceof WidgetEdge) { 80 InteractiveWidget iw = ((WidgetEdge)i).getWidgetSource();86 Widget iw = ((WidgetEdge)i).getWidgetSource(); 81 87 if(!widgets.contains(iw)) { 82 88 widgets.add(iw); … … 90 96 } 91 97 } 92 for ( InteractiveWidget iw : widgets) {98 for (Widget iw : widgets) { 93 99 items.add(iw.getSource()); 94 100 } -
trunk/src/org/expeditee/io/ExpReader.java
r919 r1102 27 27 import java.util.List; 28 28 29 import org.expeditee.core.Point; 29 30 import org.expeditee.gui.Frame; 30 31 import org.expeditee.items.Constraint; … … 130 131 while (_reader.ready() && !(next = _reader.readLine()).equals("Z")) { 131 132 if (isValidLine(next)) { 132 java.awt.Point idtype = separateValues(next.substring(2));133 Point idtype = separateValues(next.substring(2)); 133 134 // The next line must be the endpoints 134 135 if (!_reader.ready()) 135 136 throw new Exception("Unexpected end of file"); 136 137 next = _reader.readLine(); 137 java.awt.Point startend = separateValues(next.substring(2));138 Point startend = separateValues(next.substring(2)); 138 139 int start = startend.x; 139 140 int end = startend.y; … … 153 154 while (_reader.ready() && !(next = _reader.readLine()).equals("Z")) { 154 155 if (isValidLine(next)) { 155 java.awt.Point idtype = separateValues(next.substring(2));156 Point idtype = separateValues(next.substring(2)); 156 157 // The next line must be the endpoints 157 158 if (!_reader.ready()) 158 159 throw new Exception("Unexpected end of file"); 159 160 next = _reader.readLine(); 160 java.awt.Point startend = separateValues(next.substring(2));161 Point startend = separateValues(next.substring(2)); 161 162 162 163 Item a = _linePoints.get(startend.x); … … 233 234 234 235 Method toRun = _ItemTags.get(tag); 235 if (toRun == null) 236 System.out.println("Error accessing tag method: " + tag); 236 if (toRun == null) System.out.println("Error accessing tag method: " + tag); 237 237 Object[] vals = Conversion.Convert(toRun, value); 238 238 239 239 try { 240 if (vals != null) 241 toRun.invoke(item, vals); 240 if (vals != null) toRun.invoke(item, vals); 242 241 } catch (Exception e) { 243 242 System.out.println("Error running tag method: " + tag); … … 297 296 298 297 // Returns a point from a String containing two ints separated by a space 299 protected java.awt.Point separateValues(String line) {298 protected Point separateValues(String line) { 300 299 int x = Integer.parseInt(line.substring(0, line.indexOf(" "))); 301 300 int y = Integer.parseInt(line.substring(line.indexOf(" ") + 1)); 302 301 303 return new java.awt.Point(x, y);302 return new Point(x, y); 304 303 } 305 304 -
trunk/src/org/expeditee/io/HTMLWriter.java
r919 r1102 19 19 package org.expeditee.io; 20 20 21 import java.awt.Image;22 import java.awt.image.BufferedImage;23 21 import java.io.IOException; 24 22 import java.util.List; 25 23 26 24 import org.expeditee.actions.Misc; 25 import org.expeditee.core.Dimension; 26 import org.expeditee.core.Image; 27 import org.expeditee.core.Point; 28 import org.expeditee.gio.EcosystemManager; 29 import org.expeditee.gio.GraphicsManager; 30 import org.expeditee.gio.swing.SwingMiscManager; 27 31 import org.expeditee.gui.FrameIO; 28 32 import org.expeditee.items.FramePicture; … … 65 69 image = pic.getImage(); 66 70 // Crop the image 67 BufferedImage bufferedImage = new BufferedImage(pic 68 .getUnscaledWidth(), pic.getUnscaledHeight(), 69 BufferedImage.TYPE_INT_ARGB); 70 bufferedImage.getGraphics().drawImage(image, 0, 0, 71 pic.getUnscaledWidth(), pic.getUnscaledHeight(), 72 pic.getStart().x, pic.getStart().y, pic.getEnd().x, 73 pic.getEnd().y, null); 71 Image bufferedImage = Image.createImage(pic.getUnscaledWidth(), pic.getUnscaledHeight()); 72 GraphicsManager g = EcosystemManager.getGraphicsManager(); 73 g.pushDrawingSurface(bufferedImage); 74 g.drawImage(image, 75 new Point(0, 0), 76 new Dimension(pic.getUnscaledWidth(), pic.getUnscaledHeight()), 77 0.0, 78 pic.getStart(), 79 new Dimension(pic.getEnd().x - pic.getStart().x, pic.getEnd().y - pic.getStart().y)); 80 g.popDrawingSurface(); 74 81 image = bufferedImage; 75 82 } else { … … 81 88 // If its a bufferedImage then just write it out to the files directory 82 89 // This means it is probably a FrameImage 83 if ( image instanceof BufferedImage) {90 if (!image.isStoredOnDisk()) { 84 91 String link = pic.getAbsoluteLink(); 85 // Account for the possib litly of an unlinked buffered image92 // Account for the possibility of an unlinked buffered image 86 93 fileName = link == null ? ("Image" + pic.getID()) : link; 87 fileName = Misc.SaveImage((BufferedImage) image, "PNG", 88 FrameIO.EXPORTS_DIR + filesFolder, fileName); 94 fileName = Misc.SaveImage(image, "PNG", FrameIO.EXPORTS_DIR + filesFolder, fileName); 89 95 } else {// It is a normal Image stored somewhere 90 96 fileName = pic.getName(); -
trunk/src/org/expeditee/io/ItemSelection.java
r964 r1102 19 19 package org.expeditee.io; 20 20 21 22 import java.awt.Image;23 import java.awt.Toolkit;24 import java.awt.datatransfer.Clipboard;25 import java.awt.datatransfer.DataFlavor;26 import java.awt.datatransfer.Transferable;27 import java.awt.datatransfer.UnsupportedFlavorException;28 import java.awt.image.BufferedImage;29 21 import java.io.File; 30 22 import java.io.IOException; 31 23 import java.io.Serializable; 32 24 import java.util.ArrayList; 33 import java.util.Arrays;34 25 import java.util.List; 35 26 36 import javax.imageio.ImageIO; 37 38 import org.expeditee.gui.DisplayIO; 27 import org.expeditee.core.Image; 28 import org.expeditee.gio.ClipboardManager.ClipboardData; 29 import org.expeditee.gio.EcosystemManager; 30 import org.expeditee.gio.gesture.StandardGestureActions; 31 import org.expeditee.gui.DisplayController; 39 32 import org.expeditee.gui.FrameGraphics; 40 33 import org.expeditee.gui.FrameIO; 41 import org.expeditee.gui.FrameMouseActions;42 34 import org.expeditee.gui.FreeItems; 43 35 import org.expeditee.gui.MessageBay; … … 53 45 * @author jts21 54 46 */ 55 public class ItemSelection implements Transferable{56 47 public class ItemSelection { 48 // TODO : Tidy commented code once tested. cts16 57 49 /** 58 50 * Class used for storing data which can be used to reconstruct expeditee objects from the clipboard … … 68 60 // exp save data 69 61 public String items; 70 } 71 72 public static final DataFlavor expDataFlavor = new DataFlavor(ExpDataHandler.class, "expDataHandler"); 73 74 private static final int STRING = 0; 75 private static final int IMAGE = 1; 76 private static final int EXP_DATA = 2; 77 78 private static final DataFlavor[] flavors = { 79 DataFlavor.stringFlavor, 80 DataFlavor.imageFlavor, 81 expDataFlavor 82 }; 83 84 private String data; 85 private Image image; 86 private ExpDataHandler expData; 87 88 public ItemSelection(String data, Image image, ExpDataHandler expData) { 89 this.data = data; 90 this.image = image; 91 this.expData = expData; 92 } 93 94 @Override 95 public DataFlavor[] getTransferDataFlavors() { 96 return (DataFlavor[])flavors.clone(); 97 } 98 99 @Override 100 public boolean isDataFlavorSupported(DataFlavor flavor) { 101 for (int i = 0; i < flavors.length; i++) { 102 if (flavor.equals(flavors[i])) { 103 return true; 104 } 105 } 106 return false; 107 } 108 109 @Override 110 public Object getTransferData(DataFlavor flavor) 111 throws UnsupportedFlavorException, IOException { 112 if (flavor.equals(flavors[STRING])) { 113 return (Object)data; 114 } else if (flavor.equals(flavors[IMAGE])) { 115 return (Object)image; 116 } else if (flavor.equals(flavors[EXP_DATA])) { 117 return (Object)expData; 118 } else { 119 throw new UnsupportedFlavorException(flavor); 120 } 121 } 122 62 public Image image; 63 public String text; 64 } 65 123 66 private static List<Item> getAllToCopy() { 124 67 List<Item> tmp = new ArrayList<Item>(FreeItems.getInstance()); … … 128 71 if(! toCopy.contains(c)) { 129 72 toCopy.add(c); 130 FrameMouseActions.pickup(c);73 StandardGestureActions.pickup(c); 131 74 } 132 75 } … … 142 85 143 86 // remove the items attached to the cursor 144 Display IO.getCurrentFrame().removeAllItems(toCopy);87 DisplayController.getCurrentFrame().removeAllItems(toCopy); 145 88 FreeItems.getInstance().clear(); 146 89 147 FrameGraphics.refresh(false);90 DisplayController.requestRefresh(false); 148 91 } 149 92 … … 161 104 return; 162 105 } 163 106 164 107 StringBuilder clipboardText = new StringBuilder(); 165 108 ExpDataHandler expData = new ExpDataHandler(); … … 179 122 180 123 // get expeditee item data 181 ExpClipWriter ecw = new ExpClipWriter( FrameMouseActions.getX(), FrameMouseActions.getY());124 ExpClipWriter ecw = new ExpClipWriter(EcosystemManager.getInputManager().getCursorPosition()); 182 125 try { 183 126 ecw.output(items); … … 186 129 } 187 130 expData.items = ecw.getFileContents(); 131 expData.image = image; 132 expData.text = clipboardText.toString(); 133 134 // Format the data for the clipboard 135 ClipboardData clipboardData = new ClipboardData(expData, expData.image, expData.text); 136 188 137 // System.out.println(expData.items); 189 138 190 139 // write out to clipboard 191 ItemSelection selection = new ItemSelection(clipboardText.toString(), image, expData); 192 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, null); 140 //ItemSelection selection = new ItemSelection(clipboardText.toString(), image, expData); 141 //Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, null); 142 EcosystemManager.getClipboardManager().set(clipboardData); 193 143 } 194 144 … … 196 146 * Generates items from the clipboard data 197 147 * TODO: Enable pasting raw image data (would require saving the data as an image file and generating a Text item pointing to it) 148 * TODO: Above TODO seems to be done? cts16 198 149 */ 199 150 public static void paste() { 200 if(FreeItems. itemsAttachedToCursor()) {151 if(FreeItems.hasItemsAttachedToCursor()) { 201 152 MessageBay.displayMessage("Drop any items being carried on the cursor, then try pasting again"); 202 153 return; … … 204 155 String type = ""; 205 156 FreeItems f = FreeItems.getInstance(); 206 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); 207 Transferable content = c.getContents(null); 157 //Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); 158 //Transferable content = c.getContents(null); 159 ClipboardData content = EcosystemManager.getClipboardManager().get(); 160 208 161 try { 209 if (content.isDataFlavorSupported(ItemSelection.expDataFlavor)) { // Expeditee data162 if (content.data instanceof ExpDataHandler) { // Expeditee data 210 163 type = "Expeditee "; 211 ExpDataHandler expData = (ExpDataHandler) content.getTransferData(ItemSelection.expDataFlavor);164 ExpDataHandler expData = (ExpDataHandler) content.data; 212 165 if(expData != null) { 213 List<Item> items = new ExpClipReader( FrameMouseActions.getX(), FrameMouseActions.getY()).read(expData.items);166 List<Item> items = new ExpClipReader(EcosystemManager.getInputManager().getCursorPosition()).read(expData.items); 214 167 // generate new IDs and pickup 215 FrameMouseActions.pickup(ItemUtils.CopyItems(items));168 StandardGestureActions.pickup(ItemUtils.CopyItems(items)); 216 169 } 217 } else if (content.isDataFlavorSupported(DataFlavor.imageFlavor)) { // Image data170 } else if (content.imageRepresentation != null) { // Image data 218 171 // System.out.println("IZ PIKTUR"); 219 172 type = "Image "; 220 BufferedImage img = (BufferedImage)content.getTransferData(DataFlavor.imageFlavor); 221 int hashcode = Arrays.hashCode(img.getData().getPixels(0, 0, img.getWidth(), img.getHeight(), (int[])null)); 173 Image img = content.imageRepresentation; 174 //int hashcode = Arrays.hashCode(img.getData().getPixels(0, 0, img.getWidth(), img.getHeight(), (int[])null)); 175 int hashcode = img.hashCode(); 222 176 File out = new File(FrameIO.IMAGES_PATH + Integer.toHexString(hashcode) + ".png"); 223 177 out.mkdirs(); 224 ImageIO.write(img,"png", out);225 Text item = Display IO.getCurrentFrame().createNewText("@i: " + out.getPath());178 img.writeToDisk("png", out); 179 Text item = DisplayController.getCurrentFrame().createNewText("@i: " + out.getPath()); 226 180 f.add(item); 227 181 ExpClipReader.updateItems(f); 228 } else if (content.isDataFlavorSupported(DataFlavor.stringFlavor)) { // Plain text182 } else if (content.stringRepresentation != null) { // Plain text 229 183 type = "Plain Text "; 230 String clip = ((String) content.getTransferData(DataFlavor.stringFlavor));184 String clip = content.stringRepresentation; 231 185 // Covert the line separator char when pasting in 232 186 // windows (\r\n) or max (\r) … … 235 189 String[] items = clip.split("\n\n"); 236 190 Item item, prevItem = null; 237 final int x = Display IO.getMouseX();238 final int y = Display IO.getMouseY();239 final Text template = Display IO.getCurrentFrame().getItemTemplate();191 final int x = DisplayController.getMouseX(); 192 final int y = DisplayController.getMouseY(); 193 final Text template = DisplayController.getCurrentFrame().getItemTemplate(); 240 194 for(int i = 0; i < items.length; i++) { 241 195 // System.out.println(items[i]); -
trunk/src/org/expeditee/io/ItemWriter.java
r919 r1102 28 28 import org.expeditee.items.Picture; 29 29 import org.expeditee.items.Text; 30 import org.expeditee.items.widgets. InteractiveWidget;30 import org.expeditee.items.widgets.Widget; 31 31 import org.expeditee.items.widgets.WidgetEdge; 32 32 … … 115 115 } 116 116 117 protected void writeWidget( InteractiveWidget toWrite) throws IOException {117 protected void writeWidget(Widget toWrite) throws IOException { 118 118 } 119 119 -
trunk/src/org/expeditee/io/JavaWriter.java
r919 r1102 19 19 package org.expeditee.io; 20 20 21 import java.awt.Desktop;22 import java.awt.Point;23 import java.awt.Polygon;24 import java.awt.Rectangle;25 import java.awt.geom.Area;26 import java.io.File;27 21 import java.io.IOException; 28 22 import java.io.Writer; 29 import java.lang.reflect.Array;30 import java.util.ArrayList;31 import java.util.Collection;32 import java.util.Collections;33 import java.util.Comparator;34 23 import java.util.List; 35 24 36 import org.expeditee.gui.Browser;37 25 import org.expeditee.gui.Frame; 38 import org.expeditee.gui.FrameUtils;39 import org.expeditee.io.flowlayout.AreaPolygon;40 import org.expeditee.io.flowlayout.DimensionExtent;41 26 import org.expeditee.io.flowlayout.XGroupItem; 42 import org.expeditee.io.flowlayout.XItem;43 import org.expeditee.io.flowlayout.XOrderedLine;44 import org.expeditee.io.flowlayout.XRawItem;45 import org.expeditee.io.flowlayout.YOverlappingItemsShadow;46 import org.expeditee.io.flowlayout.YOverlappingItemsSpan;47 import org.expeditee.io.flowlayout.YOverlappingItemsTopEdge;48 27 import org.expeditee.items.Item; 49 import org.expeditee.items.ItemUtils;50 28 import org.expeditee.items.Text; 51 29 -
trunk/src/org/expeditee/io/KMSReader.java
r1049 r1102 29 29 import java.util.LinkedHashMap; 30 30 31 import org.expeditee.core.Point; 31 32 import org.expeditee.gui.Frame; 32 33 import org.expeditee.gui.MessageBay; 33 34 import org.expeditee.items.Constraint; 34 35 import org.expeditee.items.Dot; 35 import org.expeditee.items.DotType;36 36 import org.expeditee.items.Item; 37 37 import org.expeditee.items.Line; … … 107 107 _ItemTags.put("e", Item.class.getMethod("setFillColor", pColor)); 108 108 _ItemTags.put("E", Item.class.getMethod("setGradientColor", pColor)); 109 _ItemTags.put("Q", Item.class.getMethod("setGradientAngle", p Int));109 _ItemTags.put("Q", Item.class.getMethod("setGradientAngle", pDouble)); 110 110 111 111 _ItemTags.put("i", Item.class.getMethod("setFillPattern", pString)); … … 267 267 268 268 // get the line ID and type 269 java.awt.Point idtype = separateValues(s);269 Point idtype = separateValues(s); 270 270 271 271 // get the end points … … 273 273 _data.remove("s"); 274 274 275 java.awt.Point startend = separateValues(s);275 Point startend = separateValues(s); 276 276 277 277 int start = startend.x; … … 299 299 */ 300 300 private void createConstraint() { 301 java.awt.Point idtype = separateValues(_data.get("C"));302 java.awt.Point startend = separateValues(_data.get("s"));301 Point idtype = separateValues(_data.get("C")); 302 Point startend = separateValues(_data.get("s")); 303 303 304 304 Item a = _linePoints.get(startend.x); … … 398 398 399 399 // returns two ints separated by a space from the given String 400 private java.awt.Point separateValues(String line) {400 private Point separateValues(String line) { 401 401 int x = Integer.parseInt(line.substring(0, line.indexOf(" "))); 402 402 int y = Integer.parseInt(line.substring(line.indexOf(" ") + 1)); 403 403 404 return new java.awt.Point(x, y);404 return new Point(x, y); 405 405 } 406 406 -
trunk/src/org/expeditee/io/PDF2Writer.java
r919 r1102 19 19 package org.expeditee.io; 20 20 21 import java.awt.Color;22 import java.awt.Dimension;23 import java.awt.Image;24 import java.awt.Polygon;25 import java.awt.geom.AffineTransform;26 21 import java.io.FileOutputStream; 27 22 import java.io.IOException; … … 34 29 import java.util.Set; 35 30 31 import org.expeditee.core.Colour; 32 import org.expeditee.core.Dimension; 33 import org.expeditee.core.Image; 34 import org.expeditee.core.bounds.PolygonBounds; 35 import org.expeditee.gio.swing.SwingConversions; 36 import org.expeditee.gio.swing.SwingMiscManager; 37 import org.expeditee.gui.DisplayController; 36 38 import org.expeditee.gui.Frame; 37 39 import org.expeditee.gui.FrameGraphics; … … 145 147 146 148 public PDF2Writer() { 147 _pageSize = FrameGraphics.getMaxSize();149 _pageSize = DisplayController.getFramePaintArea().getSize(); 148 150 _pdfDocument = new Document(new Rectangle(_pageSize.width, _pageSize.height)); 149 151 } … … 233 235 // set bg color 234 236 PdfContentByte cb = _pdfWriter.getDirectContent(); 235 cb.setColorFill( starting.getPaintBackgroundColor());237 cb.setColorFill(SwingConversions.toSwingColor(starting.getPaintBackgroundColor())); 236 238 cb.rectangle(0, 0, _pageSize.width, _pageSize.height); 237 239 cb.fill(); … … 239 241 } 240 242 241 private void drawPolygon(PdfContentByte cb, Polygon poly, Color fill, Color line, float lineThickness) {243 private void drawPolygon(PdfContentByte cb, PolygonBounds poly, Colour fill, Colour line, float lineThickness) { 242 244 if(poly != null) { 243 cb.moveTo(poly. xpoints[0], _height - poly.ypoints[0]);244 for(int i = 1; i < poly. npoints; i++) {245 cb.lineTo(poly. xpoints[i], _height - poly.ypoints[i]);245 cb.moveTo(poly.toArray()[0].x, _height - poly.toArray()[0].y); 246 for(int i = 1; i < poly.toArray().length; i++) { 247 cb.lineTo(poly.toArray()[i].x, _height - poly.toArray()[i].y); 246 248 } 247 249 cb.closePath(); 248 250 if(fill != null) { 249 cb.setColorFill( fill);251 cb.setColorFill(SwingConversions.toSwingColor(fill)); 250 252 if(lineThickness > 0) { 251 253 cb.setLineWidth(lineThickness); 252 cb.setColorStroke( line);254 cb.setColorStroke(SwingConversions.toSwingColor(line)); 253 255 cb.fillStroke(); 254 256 } else { … … 257 259 } else { 258 260 cb.setLineWidth(lineThickness); 259 cb.setColorStroke( line);261 cb.setColorStroke(SwingConversions.toSwingColor(line)); 260 262 cb.stroke(); 261 263 } … … 269 271 if (hasLink) { 270 272 271 Color lineColor = Color.BLACK, fillColor = null; 272 Polygon poly = i.getLinkPoly(); 273 poly = new Polygon(poly.xpoints, poly.ypoints, poly.npoints); 273 Colour lineColor = Colour.BLACK, fillColor = null; 274 PolygonBounds poly = new PolygonBounds(i.getLinkBounds().getPolygon(16)); 274 275 poly.translate((int) (x - Item.LEFT_MARGIN), (int) (_height - y - i.getBoundsHeight() / 2)); 275 276 … … 298 299 protected void writeText(Text text) throws IOException { 299 300 PdfContentByte cb = _pdfWriter.getDirectContent(); 300 Font font = FontFactory.getFont( 301 Conversion.getPdfFont(text.getFamily()), text.getSize(), text 302 .getPaintFont().getStyle(), text.getPaintColor()); 301 Font font = FontFactory.getFont(Conversion.getPdfFont(text.getFamily()), 302 text.getSize(), 303 SwingConversions.toSwingFontStyle(text.getPaintFont().getStyle()), 304 SwingConversions.toSwingColor(text.getPaintColor())); 303 305 304 306 // we draw some text on a certain position … … 318 320 try { 319 321 PdfContentByte cb = _pdfWriter.getDirectContent(); 320 com.lowagie.text.Image iTextImage = com.lowagie.text.Image.getInstance( image, null);322 com.lowagie.text.Image iTextImage = com.lowagie.text.Image.getInstance(SwingMiscManager.getIfUsingSwingImageManager().getInternalImage(image), null); 321 323 float angle = (float) (pic.getRotate() * Math.PI / 180); 322 324 double sin = Math.sin(angle), cos = Math.cos(angle); … … 339 341 PdfContentByte cb = _pdfWriter.getDirectContent(); 340 342 cb.circle(circle.getCenter().getX(), _pdfWriter.getPageSize().getHeight() - circle.getCenter().getY(), (float) circle.getRadius()); 341 cb.setColorFill( circle.getFillColor());343 cb.setColorFill(SwingConversions.toSwingColor(circle.getFillColor())); 342 344 if(circle.getThickness() > 0) { 343 345 cb.setLineWidth(circle.getThickness()); 344 cb.setColorStroke( circle.getPaintColor());346 cb.setColorStroke(SwingConversions.toSwingColor(circle.getPaintColor())); 345 347 cb.fillStroke(); 346 348 } else { … … 377 379 } 378 380 cb.closePath(); 379 Colo r fill = currentItem.getFillColor();381 Colour fill = currentItem.getFillColor(); 380 382 if(fill != null) { 381 cb.setColorFill( fill);383 cb.setColorFill(SwingConversions.toSwingColor(fill)); 382 384 if(currentItem.getThickness() > 0) { 383 385 cb.setLineWidth(currentItem.getThickness()); 384 cb.setColorStroke( currentLine.getPaintColor());386 cb.setColorStroke(SwingConversions.toSwingColor(currentLine.getPaintColor())); 385 387 cb.fillStroke(); 386 388 } else { … … 389 391 } else if(currentItem.getThickness() > 0) { 390 392 cb.setLineWidth(currentItem.getThickness()); 391 cb.setColorStroke( currentLine.getPaintColor());393 cb.setColorStroke(SwingConversions.toSwingColor(currentLine.getPaintColor())); 392 394 cb.stroke(); 393 395 } … … 403 405 if(l.getThickness() >= 0) { 404 406 cb.setLineWidth(l.getThickness()); 405 cb.setColorStroke( l.getPaintColor());407 cb.setColorStroke(SwingConversions.toSwingColor(l.getPaintColor())); 406 408 cb.stroke(); 407 409 } -
trunk/src/org/expeditee/io/PDFWriter.java
r919 r1102 19 19 package org.expeditee.io; 20 20 21 import java.awt.Image;22 21 import java.io.FileOutputStream; 23 22 import java.io.IOException; … … 25 24 import java.util.List; 26 25 26 import org.expeditee.core.Image; 27 import org.expeditee.gio.swing.SwingConversions; 28 import org.expeditee.gio.swing.SwingMiscManager; 27 29 import org.expeditee.gui.Frame; 28 30 import org.expeditee.items.Item; … … 54 56 if (UserSettings.Style.get().size() > 0) { 55 57 Text text = UserSettings.Style.get().get(0); 56 _bodyFont = FontFactory.getFont(Conversion.getPdfFont(text 57 .getFamily()), text.getSize(), text.getPaintFont() 58 .getStyle(), text.getColor()); 58 _bodyFont = FontFactory.getFont(Conversion.getPdfFont(text.getFamily()), 59 text.getSize(), 60 SwingConversions.toSwingFontStyle(text.getPaintFont().getStyle()), 61 SwingConversions.toSwingColor(text.getColor())); 59 62 } 60 63 _pdfDocument = new Document(); … … 114 117 115 118 if (font == null) { 116 font = FontFactory.getFont(Conversion.getPdfFont(text 117 .getFamily()), text.getSize(), text.getPaintFont() 118 .getStyle(), text.getColor()); 119 font = FontFactory.getFont(Conversion.getPdfFont(text.getFamily()), 120 text.getSize(), 121 SwingConversions.toSwingFontStyle(text.getPaintFont().getStyle()), 122 SwingConversions.toSwingColor(text.getColor())); 119 123 } 120 124 … … 130 134 Image image = pic.getCroppedImage(); 131 135 try { 132 _pdfDocument.add(com.lowagie.text.Image.getInstance( image, null));136 _pdfDocument.add(com.lowagie.text.Image.getInstance(SwingMiscManager.getIfUsingSwingImageManager().getInternalImage(image), null)); 133 137 } catch (DocumentException e) { 134 138 // TODO Auto-generated catch block -
trunk/src/org/expeditee/io/PdfFramesetWriter.java
r919 r1102 19 19 package org.expeditee.io; 20 20 21 import java.awt.Dimension;22 21 import java.awt.Graphics2D; 23 import java.awt.Image;24 22 import java.io.FileOutputStream; 25 23 import java.io.IOException; … … 28 26 import java.util.List; 29 27 28 import org.expeditee.core.Dimension; 29 import org.expeditee.core.Image; 30 import org.expeditee.gio.EcosystemManager; 31 import org.expeditee.gio.GraphicsManager; 32 import org.expeditee.gio.swing.SwingConversions; 33 import org.expeditee.gio.swing.SwingMiscManager; 34 import org.expeditee.gui.DisplayController; 30 35 import org.expeditee.gui.Frame; 31 36 import org.expeditee.gui.FrameGraphics; … … 35 40 import org.expeditee.items.Picture; 36 41 import org.expeditee.items.Text; 37 import org.expeditee.items.widgets. InteractiveWidget;42 import org.expeditee.items.widgets.Widget; 38 43 import org.expeditee.settings.UserSettings; 39 44 … … 59 64 private boolean _showFrameNames; 60 65 61 public PdfFramesetWriter(long firstFrame, long maxFrame, 62 boolean showFrameNames){66 public PdfFramesetWriter(long firstFrame, long maxFrame, boolean showFrameNames) 67 { 63 68 super(firstFrame, maxFrame); 64 Dimension d = FrameGraphics.getMaxSize();69 Dimension d = DisplayController.getFramePaintArea().getSize(); 65 70 _pdfDocument = new Document(new Rectangle(d.width, d.height)); 66 71 _showFrameNames = showFrameNames; … … 130 135 // we tell the ContentByte we're ready to draw text 131 136 cb.beginText(); 132 Font font = FontFactory.getFont( 133 Conversion.getPdfFont(text.getFamily()), text.getSize(), text 134 .getPaintFont().getStyle(), text.getPaintColor()); 137 Font font = FontFactory.getFont(Conversion.getPdfFont(text.getFamily()), 138 text.getSize(), 139 SwingConversions.toSwingFontStyle(text.getPaintFont().getStyle()), 140 SwingConversions.toSwingColor(text.getPaintColor())); 135 141 cb.setFontAndSize(font.getBaseFont(), text.getSize()); 136 142 // cb.setColorStroke(text.getPaintColor()); 137 cb.setColorFill( text.getPaintColor());143 cb.setColorFill(SwingConversions.toSwingColor(text.getPaintColor())); 138 144 139 145 // we draw some text on a certain position … … 158 164 PdfContentByte cb = _pdfWriter.getDirectContent(); 159 165 com.lowagie.text.Image iTextImage = com.lowagie.text.Image 160 .getInstance( image, null);166 .getInstance(SwingMiscManager.getIfUsingSwingImageManager().getInternalImage(image), null); 161 167 iTextImage.setAbsolutePosition(pic.getX(), _pdfWriter.getPageSize() 162 168 .getHeight() … … 175 181 // cb.setColorFill(fill); 176 182 // } 177 Graphics2D g = cb.createGraphicsShapes(183 /* Graphics2D g = cb.createGraphicsShapes( 178 184 FrameGraphics.getMaxSize().width, 179 FrameGraphics.getMaxSize().height); 180 lineEnd.paint(g); 185 FrameGraphics.getMaxSize().height);*/ 186 GraphicsManager g = EcosystemManager.getGraphicsManager(); 187 Image temp = EcosystemManager.getImageManager().createImage(DisplayController.getFramePaintArea().getSize()); 188 lineEnd.paint(); 181 189 // if (fill != null) { 182 190 // g.setPaint(fill); … … 191 199 192 200 @Override 193 protected void writeCircle(Circle toWrite) throws IOException { 194 PdfContentByte cb = _pdfWriter.getDirectContent(); 195 Graphics2D g = cb.createGraphicsShapes( 196 FrameGraphics.getMaxSize().width, 197 FrameGraphics.getMaxSize().height); 198 toWrite.paint(g); 201 protected void writeCircle(Circle toWrite) throws IOException 202 { 203 PdfContentByte cb = _pdfWriter.getDirectContent(); 204 Graphics2D g = cb.createGraphicsShapes(DisplayController.getFramePaintArea().getWidth(), DisplayController.getFramePaintArea().getHeight()); 205 Image temp = EcosystemManager.getImageManager().createImage(DisplayController.getFramePaintArea().getSize()); 206 EcosystemManager.getGraphicsManager().pushDrawingSurface(temp); 207 toWrite.paint(); 208 EcosystemManager.getGraphicsManager().popDrawingSurface(); 209 g.drawImage(SwingMiscManager.getIfUsingSwingImageManager().getInternalImage(temp), 0, 0, null); 199 210 } 200 211 201 202 @Override 203 protected void writeWidget(InteractiveWidget toWrite) throws IOException { 204 PdfContentByte cb = _pdfWriter.getDirectContent(); 205 Graphics2D g = cb.createGraphicsShapes( 206 FrameGraphics.getMaxSize().width, 207 FrameGraphics.getMaxSize().height); 208 toWrite.paint(g); 212 @Override 213 protected void writeWidget(Widget toWrite) throws IOException 214 { 215 PdfContentByte cb = _pdfWriter.getDirectContent(); 216 Graphics2D g = cb.createGraphicsShapes(DisplayController.getFramePaintArea().getWidth(), DisplayController.getFramePaintArea().getHeight()); 217 Image temp = EcosystemManager.getImageManager().createImage(DisplayController.getFramePaintArea().getSize()); 218 EcosystemManager.getGraphicsManager().pushDrawingSurface(temp); 219 toWrite.paint(); 220 EcosystemManager.getGraphicsManager().popDrawingSurface(); 221 g.drawImage(SwingMiscManager.getIfUsingSwingImageManager().getInternalImage(temp), 0, 0, null); 209 222 } 210 223 } -
trunk/src/org/expeditee/io/ProxyAuth.java
r919 r1102 24 24 public class ProxyAuth extends Authenticator { 25 25 26 public static final int MAX_ATTEMPTS = 5; 27 26 28 private String httpUser = null, httpPass = null, httpsUser = null, httpsPass = null; 27 29 private int attempts = 0; … … 37 39 // stop it from breaking from a redirect loop 38 40 attempts++; 39 if(attempts > 5) {41 if(attempts > MAX_ATTEMPTS) { 40 42 return null; 41 43 } -
trunk/src/org/expeditee/io/ProxyWriter.java
r919 r1102 19 19 package org.expeditee.io; 20 20 21 import java.awt.Toolkit;22 import java.awt.datatransfer.StringSelection;23 21 import java.io.BufferedWriter; 24 22 import java.io.IOException; 25 23 import java.io.PipedWriter; 26 24 import java.io.Writer; 25 26 import org.expeditee.gio.ClipboardManager.ClipboardData; 27 import org.expeditee.gio.EcosystemManager; 27 28 28 29 public class ProxyWriter extends BufferedWriter { … … 55 56 public void flush() throws IOException { 56 57 if (_contents != null) { 57 StringSelection selection = new StringSelection(_contents 58 .toString()); 59 Toolkit.getDefaultToolkit().getSystemClipboard().setContents( 60 selection, null); 61 } else 58 EcosystemManager.getClipboardManager().set(ClipboardData.fromString(_contents.toString())); 59 } else { 62 60 super.flush(); 61 } 63 62 } 64 63 -
trunk/src/org/expeditee/io/StreamGobbler.java
r919 r1102 19 19 package org.expeditee.io; 20 20 21 22 import java.util.*;23 21 import java.io.*; 24 25 import javax.swing.SwingUtilities;26 22 27 23 import org.expeditee.gui.MessageBay; … … 82 78 // MessageBay is on the AWT event thread, so need to use 'invokeLater' to avoid thread deadlock 83 79 Runnable updateMessageBayTask = new UpdateMessageBay(type,line); 84 SwingUtilities.invokeLater(updateMessageBayTask);80 updateMessageBayTask.run(); 85 81 86 82 } -
trunk/src/org/expeditee/io/WebParser.java
r919 r1102 19 19 package org.expeditee.io; 20 20 21 import java.awt.Color;22 import java.awt.Font;23 import java.awt.image.BufferedImage;24 21 import java.io.File; 25 22 import java.io.IOException; … … 45 42 import javafx.beans.value.ObservableValue; 46 43 import javafx.concurrent.Worker.State; 47 import javafx.embed.swing.SwingFXUtils;48 44 import javafx.scene.SnapshotParameters; 49 45 import javafx.scene.image.WritableImage; … … 51 47 import javafx.scene.web.WebView; 52 48 53 import javax.imageio.ImageIO;54 55 49 import netscape.javascript.JSObject; 56 50 57 import org.expeditee.gui.DisplayIO; 51 import org.expeditee.core.Colour; 52 import org.expeditee.core.Font; 53 import org.expeditee.core.Image; 54 import org.expeditee.core.InOutReference; 55 import org.expeditee.gio.EcosystemManager; 56 import org.expeditee.gio.gesture.StandardGestureActions; 57 import org.expeditee.gio.swing.SwingMiscManager; 58 import org.expeditee.gui.DisplayController; 58 59 import org.expeditee.gui.Frame; 59 import org.expeditee.gui.FrameGraphics;60 60 import org.expeditee.gui.FrameIO; 61 import org.expeditee.gui.FrameMouseActions;62 61 import org.expeditee.gui.FrameUtils; 63 62 import org.expeditee.gui.MessageBay; … … 303 302 try { 304 303 305 final int verticalScrollPerPage = (int) ( FrameGraphics.getMaxFrameSize().getHeight() * 0.85);306 final int horizontalScrollPerPage = (int) ( FrameGraphics.getMaxFrameSize().getWidth() * 0.85);304 final int verticalScrollPerPage = (int) (DisplayController.getFramePaintArea().getHeight() * 0.85); 305 final int horizontalScrollPerPage = (int) (DisplayController.getFramePaintArea().getWidth() * 0.85); 307 306 308 307 Platform.runLater(new Runnable() { … … 320 319 final Object notifier = new Object(); 321 320 322 final MutableInt verticalCount = new MutableInt(0);323 final MutableInt horizontalCount = new MutableInt(0);321 final InOutReference<Integer> verticalCount = new InOutReference<Integer>(0); 322 final InOutReference<Integer> horizontalCount = new InOutReference<Integer>(0); 324 323 325 final MutableInt pagesVertical = new MutableInt(1);326 final MutableInt pagesHorizontal = new MutableInt(1);324 final InOutReference<Integer> pagesVertical = new InOutReference<Integer>(1); 325 final InOutReference<Integer> pagesHorizontal = new InOutReference<Integer>(1); 327 326 328 327 final String pageTitle; … … 341 340 frameset.getTitleItem().setSize(14); 342 341 343 WebParser.addButton("Return to original frame", frame.getName(), null, 200, frameset, null, 0 f, 10f, null);344 345 Text link = Display IO.getCurrentFrame().addText(FrameMouseActions.getX(), FrameMouseActions.getY(), pageTitle, null);342 WebParser.addButton("Return to original frame", frame.getName(), null, 200, frameset, null, 0, 10, null); 343 344 Text link = DisplayController.getCurrentFrame().addText(DisplayController.getMouseX(), DisplayController.getMouseY(), pageTitle, null); 346 345 link.setLink(frameset.getName()); 347 346 348 FrameMouseActions.pickup(link);347 StandardGestureActions.pickup(link); 349 348 350 349 // Timer that fires every time JFX is redrawn. After a few redraws, the handle method of this takes a screenshot of the page, … … 364 363 this.stop(); 365 364 366 verticalCount.set Value(verticalCount.getValue() + 1);365 verticalCount.set(verticalCount.get() + 1); 367 366 368 367 frameToAddTo = FrameIO.CreateFrame(frameToAddTo.getFramesetName(), pageTitle, null); … … 395 394 396 395 // Getting a BufferedImage from the JavaFX image 397 BufferedImage image = SwingFXUtils.fromFXImage(img, null); 396 //BufferedImage image = SwingFXUtils.fromFXImage(img, null); 397 Image image = SwingMiscManager.getImageForJavaFXImage(img); 398 398 399 399 try { 400 int hashcode = Arrays.hashCode(image.getData().getPixels(0, 0, image.getWidth(), image.getHeight(), (int[]) null)); 401 400 // TODO: tidy. cts16 401 //int hashcode = Arrays.hashCode(image.getData().getPixels(0, 0, image.getWidth(), image.getHeight(), (int[]) null)); 402 int hashcode = image.hashCode(); 403 402 404 File out = new File(FrameIO.IMAGES_PATH + "webpage-" + Integer.toHexString(hashcode) + ".png"); 403 405 out.mkdirs(); 404 ImageIO.write(image,"png", out);406 image.writeToDisk("png", out); 405 407 406 408 // Adding the image to the frame … … 408 410 409 411 // Adding thumbnail to the overview page 410 Text thumb = frameset.addText((int) (thumbWidth * 1.1 * horizontalCount.get Value()) + 10,411 (int) ((((float) thumbWidth / image.getWidth()) * image.getHeight()) * 1.1 * verticalCount.get Value()),412 Text thumb = frameset.addText((int) (thumbWidth * 1.1 * horizontalCount.get()) + 10, 413 (int) ((((float) thumbWidth / image.getWidth()) * image.getHeight()) * 1.1 * verticalCount.get()), 412 414 "@i: " + out.getName() + " " + thumbWidth, 413 415 null); 414 416 415 417 thumb.setLink(frameToAddTo.getName()); 416 thumb.setBorderColor(Colo r.lightGray);418 thumb.setBorderColor(Colour.LIGHT_GREY); 417 419 thumb.setThickness(1); 418 420 419 421 // Button to go to the next frame/page 420 WebParser.addButton("Next", null, "next", 70, frameToAddTo, null, 0 f, 10f, null);422 WebParser.addButton("Next", null, "next", 70, frameToAddTo, null, 0, 10, null); 421 423 422 424 // Button to go to the previous frame/page 423 if (verticalCount.get Value() > 1 || horizontalCount.getValue() > 0) {424 WebParser.addButton("Previous", null, "previous", 70, frameToAddTo, null, 85 f, 10f, null);425 if (verticalCount.get() > 1 || horizontalCount.get() > 0) { 426 WebParser.addButton("Previous", null, "previous", 70, frameToAddTo, null, 85, 10, null); 425 427 } 426 428 427 429 // Button to return to the index/overview page 428 WebParser.addButton("Index", frameset.getName(), null, 70, frameToAddTo, null, null, 10 f, 5f);430 WebParser.addButton("Index", frameset.getName(), null, 70, frameToAddTo, null, null, 10, 5); 429 431 430 432 FrameIO.SaveFrame(frameToAddTo); … … 435 437 } 436 438 437 image. flush();439 image.releaseImage(); 438 440 439 441 synchronized (notifier) { … … 468 470 // but if the webpage fits in a single converted page, there's no need for any overlap, so just use 1 as the number of pages 469 471 if((Boolean) webEngine.executeScript("document.documentElement.scrollHeight > window.innerHeight")) { 470 pagesVertical.set Value((int) Math.ceil((Integer) webEngine.executeScript("document.documentElement.scrollHeight") / (float) verticalScrollPerPage));472 pagesVertical.set((int) Math.ceil((Integer) webEngine.executeScript("document.documentElement.scrollHeight") / (float) verticalScrollPerPage)); 471 473 } 472 474 473 475 if((Boolean) webEngine.executeScript("document.documentElement.scrollWidth > window.innerWidth")) { 474 pagesHorizontal.set Value((int) Math.ceil((Integer) webEngine.executeScript("document.documentElement.scrollWidth") / (float) horizontalScrollPerPage));476 pagesHorizontal.set((int) Math.ceil((Integer) webEngine.executeScript("document.documentElement.scrollWidth") / (float) horizontalScrollPerPage)); 475 477 } 476 478 477 479 System.out.println(webEngine.executeScript("document.documentElement.scrollWidth") + "/" + horizontalScrollPerPage); 478 System.out.println(pagesVertical.get Value() + "x" + pagesHorizontal.getValue());480 System.out.println(pagesVertical.get() + "x" + pagesHorizontal.get()); 479 481 480 482 // Setting up the element that contains the CSS to hide all text. Also hiding readability mode buttons. … … 628 630 629 631 // Loop that scrolls the page horizontally 630 for(int i = 0; i < pagesHorizontal.get Value() && browserWidget.isParserRunning(); i++) {632 for(int i = 0; i < pagesHorizontal.get() && browserWidget.isParserRunning(); i++) { 631 633 632 634 Platform.runLater(new Runnable() { … … 647 649 648 650 // Loop that scrolls the page vertically (for each horizontal scroll position) 649 for(int j = 0; j < pagesVertical.get Value() && browserWidget.isParserRunning(); j++) {651 for(int j = 0; j < pagesVertical.get() && browserWidget.isParserRunning(); j++) { 650 652 651 653 try { 652 progressBar.set((int) (50 + ((float)(j+1)/(pagesVertical.get Value() * pagesHorizontal.getValue()) + ((float)(i) / pagesHorizontal.getValue())) * 50));654 progressBar.set((int) (50 + ((float)(j+1)/(pagesVertical.get() * pagesHorizontal.get()) + ((float)(i) / pagesHorizontal.get())) * 50)); 653 655 } catch (Exception e) { 654 656 e.printStackTrace(); … … 698 700 } 699 701 700 horizontalCount.set Value(horizontalCount.getValue() + 1);701 verticalCount.set Value(0);702 horizontalCount.set(horizontalCount.get() + 1); 703 verticalCount.set(0); 702 704 } 703 705 … … 742 744 * @return A Color object that should match the rgb string passed int. Returns null if alpha is 0 743 745 */ 744 private static Colo r rgbStringToColor(String rgbString) {746 private static Colour rgbStringToColor(String rgbString) { 745 747 746 748 if (rgbString == null) { … … 764 766 765 767 if (components[3] > 0) { 766 return new Color(components[0], components[1], components[2], components[3]);768 return Colour.FromRGBA255(components[0], components[1], components[2], components[3]); 767 769 } else { 768 770 return null; … … 854 856 855 857 Boolean fontFound = false; 856 Font font = n ew Font(null);858 Font font = null; 857 859 858 860 // Looping through all font-families listed in the element's CSS until one that is installed is … … 869 871 870 872 // Regex will remove any inverted commas surrounding multi-word typeface names 871 font = new Font(typefaces[j].replaceAll("^'|'$", ""), Font.PLAIN, 12); 872 873 // If the font isn't found, Java just uses Font.DIALOG, so this check checks whether the font was found 874 if (!(font.getFamily().toLowerCase().equals(Font.DIALOG.toLowerCase()))) { 873 String familyName = typefaces[j].replaceAll("^'|'$", ""); 874 font = new Font(familyName); 875 font.setStyle(Font.Style.PLAIN); 876 font.setSize(12); 877 878 // Check whether the font was found 879 if (EcosystemManager.getFontManager().getActualFont(font).getFamilyName().toLowerCase().equals(familyName.toLowerCase())) { 875 880 fontFound = true; 876 881 } 877 882 } 878 883 879 if (font.getFamily().toLowerCase().equals(Font.DIALOG.toLowerCase())) { 880 font = new Font("Times New Roman", Font.PLAIN, 12); 884 if (!fontFound) { 885 font = new Font("Times New Roman"); 886 font.setStyle(Font.Style.PLAIN); 887 font.setSize(12); 881 888 } 882 889 … … 975 982 String bgColorString = (String) style.call("getPropertyValue", new Object[] { "background-color" }); 976 983 977 Colo r bgColor = rgbStringToColor(bgColorString);984 Colour bgColor = rgbStringToColor(bgColorString); 978 985 979 986 // If the element has a background color then add it (to Expeditee) as a rectangle with that background color … … 1077 1084 HttpURLConnection connection = (HttpURLConnection) (imgUrl.openConnection()); 1078 1085 1079 // Spoofing a widely accepted User Agent, since some sites refuse to serve non-webbrowser clients 1080 connection.setRequestProperty("User-Agent", "Mozilla/5.0"); 1081 1082 BufferedImage img = ImageIO.read(connection.getInputStream()); 1083 1084 int hashcode = Arrays.hashCode(img.getData().getPixels(0, 0, img.getWidth(), img.getHeight(), (int[]) null)); 1086 Image img = Image.getImage(connection); 1087 1088 int hashcode = img.hashCode(); 1089 1085 1090 File out = new File(FrameIO.IMAGES_PATH + Integer.toHexString(hashcode) + ".png"); 1086 1091 out.mkdirs(); 1087 ImageIO.write(img,"png", out);1092 img.writeToDisk("png", out); 1088 1093 1089 1094 if (repeat == null && cropEndX == null && cropStartX == null && cropEndY == null && cropStartY == null) { … … 1153 1158 text.setPosition(x, y); 1154 1159 1155 Picture pic = ItemUtils.CreatePicture(text , frame);1160 Picture pic = ItemUtils.CreatePicture(text); 1156 1161 1157 1162 float invScale = 1 / pic.getScale(); … … 1324 1329 1325 1330 Boolean fontFound = false; 1326 Font font = n ew Font(null);1331 Font font = null; 1327 1332 1328 1333 // Looping through all font-families listed in the element's CSS until one that is installed is … … 1342 1347 1343 1348 // Regex will remove any inverted commas surrounding multi-word typeface names 1344 font = new Font(typefaces[j].replaceAll("^'|'$", ""), Font.PLAIN, 12); 1349 String familyName = typefaces[j].replaceAll("^'|'$", ""); 1350 font = new Font(familyName); 1351 font.setStyle(Font.Style.PLAIN); 1352 font.setSize(12); 1345 1353 1346 1354 // If the font isn't found, Java just uses Font.DIALOG, so this check checks whether the font was found 1347 if ( !(font.getFamily().toLowerCase().equals(Font.DIALOG.toLowerCase()))) {1355 if (EcosystemManager.getFontManager().getActualFont(font).getFamilyName().toLowerCase().equals(familyName.toLowerCase())) { 1348 1356 fontFound = true; 1349 1357 } 1350 1358 } 1351 1359 1352 if (font.getFamily().toLowerCase().equals(Font.DIALOG.toLowerCase())) { 1353 font = new Font("Times New Roman", Font.PLAIN, 12); 1360 if (!fontFound) { 1361 font = new Font("Times New Roman"); 1362 font.setStyle(Font.Style.PLAIN); 1363 font.setSize(12); 1354 1364 } 1355 1365 … … 1464 1474 * @param anchorLeft 1465 1475 */ 1466 private static void addButton(String text, String link, String action, int width, Frame toAddTo, Float anchorTop, Float anchorRight, Float anchorBottom, FloatanchorLeft) {1476 private static void addButton(String text, String link, String action, int width, Frame toAddTo, Integer anchorTop, Integer anchorRight, Integer anchorBottom, Integer anchorLeft) { 1467 1477 // Button to go to the next frame/page 1468 1478 Text button = new Text(text); … … 1470 1480 button.setLink(link); 1471 1481 button.addAction(action); 1472 button.setBorderColor(new Colo r(0.7f, 0.7f, 0.7f));1473 button.setBackgroundColor(new Colo r(0.9f, 0.9f, 0.9f));1482 button.setBorderColor(new Colour(0.7f, 0.7f, 0.7f)); 1483 button.setBackgroundColor(new Colour(0.9f, 0.9f, 0.9f)); 1474 1484 button.setThickness(1); 1475 1485 button.setLinkMark(false); … … 1499 1509 1500 1510 } 1501 1502 1503 private static class MutableBool {1504 private boolean value;1505 1506 public MutableBool(boolean value) {1507 this.value = value;1508 }1509 1510 public boolean getValue() {1511 return value;1512 }1513 1514 public void setValue(boolean value) {1515 this.value = value;1516 }1517 }1518 1519 private static class MutableInt {1520 private int value;1521 1522 public MutableInt(int value) {1523 this.value = value;1524 }1525 1526 public int getValue() {1527 return value;1528 }1529 1530 public void setValue(int value) {1531 this.value = value;1532 }1533 }1534 1511 } -
trunk/src/org/expeditee/io/flowlayout/DimensionExtent.java
r919 r1102 19 19 package org.expeditee.io.flowlayout; 20 20 21 import java.awt.Polygon;22 import java.awt.Rectangle;23 import java.awt.geom.Area;24 21 import java.util.List; 25 22 23 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 24 import org.expeditee.core.bounds.PolygonBounds; 26 25 import org.expeditee.items.Item; 27 26 … … 44 43 45 44 for (Item item : items) { 46 Area area = item.getArea(); 47 Rectangle rect = area.getBounds(); 48 int xl = rect.x; 49 int xr = xl + rect.width-1; 45 AxisAlignedBoxBounds bounds = item.getBoundingBox(); 46 int xl = bounds.getMinX(); 47 int xr = xl + bounds.getWidth()-1; 50 48 51 49 min_x = Math.min(min_x, xl); … … 66 64 67 65 for (Item item : items) { 68 Area area = item.getArea(); 69 Rectangle rect = area.getBounds(); 70 int yt = rect.y; 71 int yb = yt + rect.height-1; 66 AxisAlignedBoxBounds bounds = item.getBoundingBox(); 67 int yt = bounds.getMinY(); 68 int yb = yt + bounds.getHeight()-1; 72 69 73 70 min_y = Math.min(min_y, yt); … … 82 79 83 80 84 public static DimensionExtent calcMinMaxXExtent(Polygon polygon)81 public static DimensionExtent calcMinMaxXExtent(PolygonBounds polygon) 85 82 { 86 83 87 int min_x = Integer.MAX_VALUE; 88 int max_x = Integer.MIN_VALUE; 89 90 int npoints = polygon.npoints; 91 92 for (int i=0; i<npoints; i++) { 93 94 int x = polygon.xpoints[i]; 95 96 min_x = Math.min(min_x, x); 97 max_x = Math.max(max_x, x); 98 } 99 100 DimensionExtent extent = new DimensionExtent(min_x,max_x); 84 DimensionExtent extent = new DimensionExtent(polygon.getMinX(), polygon.getMaxX()); 101 85 102 86 return extent; 103 87 } 104 88 105 public static DimensionExtent calcMinMaxYExtent(Polygon polygon)89 public static DimensionExtent calcMinMaxYExtent(PolygonBounds polygon) 106 90 { 107 91 108 int min_y = Integer.MAX_VALUE; 109 int max_y = Integer.MIN_VALUE; 110 111 int npoints = polygon.npoints; 112 113 for (int i=0; i<npoints; i++) { 114 115 int y = polygon.ypoints[i]; 116 117 min_y = Math.min(min_y, y); 118 max_y = Math.max(max_y, y); 119 } 120 121 DimensionExtent extent = new DimensionExtent(min_y,max_y); 92 DimensionExtent extent = new DimensionExtent(polygon.getMinY(), polygon.getMaxY()); 122 93 123 94 return extent; 124 95 } 125 96 126 public static Polygon boundingBoxPolygon(List<Item> items)97 public static PolygonBounds boundingBoxPolygon(List<Item> items) 127 98 { 128 DimensionExtent xextent = DimensionExtent.calcMinMaxXExtent(items); 129 DimensionExtent yextent = DimensionExtent.calcMinMaxYExtent(items); 130 131 int xl=xextent.min; 132 int xr=xextent.max; 133 int yt=yextent.min; 134 int yb=yextent.max; 99 AxisAlignedBoxBounds box = null; 135 100 136 int[] xpoints = new int[]{xl,xr,xr,xl}; 137 int[] ypoints = new int[]{yt,yt,yb,yb}; 101 for (Item i : items) { 102 if (box == null) { 103 box = i.getBoundingBox(); 104 } else { 105 box.combineWith(i.getBoundingBox()); 106 } 107 } 138 108 139 140 Polygon polygon = new Polygon(xpoints,ypoints,4); 141 142 return polygon; 109 return new PolygonBounds(box.getBorderLines()); 143 110 } 144 111 } -
trunk/src/org/expeditee/io/flowlayout/XGroupItem.java
r976 r1102 19 19 package org.expeditee.io.flowlayout; 20 20 21 import java.awt.Point;22 import java.awt.Polygon;23 import java.awt.Rectangle;24 21 import java.util.ArrayList; 25 22 import java.util.Collection; … … 31 28 import java.util.List; 32 29 30 import org.expeditee.core.Point; 31 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 32 import org.expeditee.core.bounds.PolygonBounds; 33 33 import org.expeditee.gui.Frame; 34 34 import org.expeditee.gui.FrameUtils; … … 110 110 } 111 111 112 public XGroupItem(Frame frame, List<Item> y_ordered_items, 113 Polygon enclosing_polygon) { 112 public XGroupItem(Frame frame, List<Item> y_ordered_items, PolygonBounds enclosing_polygon) { 114 113 this.frame = frame; 115 114 this.out_of_flow = FlowType.in_flow; … … 124 123 } 125 124 126 Rectangle enclosing_bounding_rect = enclosing_polygon.getBounds();125 AxisAlignedBoxBounds enclosing_bounding_rect = AxisAlignedBoxBounds.getEnclosing(enclosing_polygon); 127 126 initSpanArray(enclosing_bounding_rect); 128 127 … … 134 133 remaining_item_list = new ArrayList<Item>(); 135 134 136 separateYOverlappingItems(frame, y_ordered_items, enclosing_polygon, 137 raw_text_item_list, grouped_item_list, remaining_item_list); 135 separateYOverlappingItems(frame, y_ordered_items, enclosing_polygon, raw_text_item_list, grouped_item_list, remaining_item_list); 138 136 139 137 // Step 2: Add in the raw-text items … … 161 159 } 162 160 163 protected XGroupItem(XGroupItem imprint, Rectangle copy_to_bounding_rect) { 161 protected XGroupItem(XGroupItem imprint, AxisAlignedBoxBounds copy_to_bounding_rect) 162 { 164 163 super(); 165 164 … … 192 191 // straight away? 193 192 194 this.bounding_rect = new Rectangle(copy_to_bounding_rect); // deep copy193 this.bounding_rect = new AxisAlignedBoxBounds(copy_to_bounding_rect); // deep copy 195 194 // to be on 196 195 // the safe … … 198 197 } 199 198 200 protected void initSpanArray( Rectanglebounding_rect) {199 protected void initSpanArray(AxisAlignedBoxBounds bounding_rect) { 201 200 this.bounding_rect = bounding_rect; 202 201 … … 533 532 // to make it appear where the start of the arrow is 534 533 535 Rectangle start_rect = start_item.getArea() 536 .getBounds(); 534 AxisAlignedBoxBounds start_rect = start_item.getBoundingBox(); 537 535 538 536 XGroupItem xgroup_item_shallow_copy = new XGroupItem( … … 630 628 * @return 631 629 */ 632 public Collection<Item> getItemsInNestedEnclosure(Item given_item, 633 AreaPolygon outer_polygon){630 public Collection<Item> getItemsInNestedEnclosure(Item given_item, PolygonBounds outer_polygon) 631 { 634 632 Collection<Item> sameEnclosure = null; 635 633 Collection<Item> seen = new HashSet<Item>(); … … 649 647 seen.addAll(i_enclosing_dots); 650 648 651 Polygon i_polygon = new Polygon();649 PolygonBounds i_polygon = new PolygonBounds(); 652 650 for (int di = 0; di < i_enclosing_dots.size(); di++) { 653 651 Item d = i_enclosing_dots.get(di); … … 684 682 685 683 public void separateYOverlappingItems(Frame frame, List<Item> item_list, 686 Polygon enclosing_polygon, List<Text> raw_text_item_list,684 PolygonBounds enclosing_polygon, List<Text> raw_text_item_list, 687 685 List<XGroupItem> grouped_item_list, List<Item> remaining_item_list) { 688 686 final List<Item> origonal_item_list = new ArrayList<Item>(item_list); … … 692 690 // of lines/polylines/polygons 693 691 694 AreaPolygon area_enclosing_polygon = new AreaPolygon(enclosing_polygon);695 696 List< AreaPolygon> area_enclosed_polygon_list = new ArrayList<AreaPolygon>();692 PolygonBounds area_enclosing_polygon = new PolygonBounds(enclosing_polygon); 693 694 List<PolygonBounds> area_enclosed_polygon_list = new ArrayList<PolygonBounds>(); 697 695 698 696 while (item_list.size() > 0) { … … 724 722 .remove(0); // shift 725 723 726 Polygon enclosed_polygon = enclosure_item 727 .getEnclosedShape(); 724 PolygonBounds enclosed_polygon = enclosure_item.getEnclosedShape(); 728 725 729 726 if (enclosed_polygon != null) { … … 739 736 // group) 740 737 741 AreaPolygon area_enclosed_polygon = new AreaPolygon( 742 enclosed_polygon); 743 area_enclosed_polygon_list 744 .add(area_enclosed_polygon); 738 PolygonBounds area_enclosed_polygon = new PolygonBounds(enclosed_polygon); 739 area_enclosed_polygon_list.add(area_enclosed_polygon); 745 740 746 741 item_list.remove(enclosure_item); … … 763 758 while (item_iterator.hasNext()) { 764 759 Item item_to_check = item_iterator.next(); 765 Point pt_to_check = new Point( 766 item_to_check.getX(), 767 item_to_check.getY()); 768 769 if (area_enclosed_polygon 770 .isPerimeterPoint(pt_to_check)) { 760 Point pt_to_check = new Point(item_to_check.getX(), item_to_check.getY()); 761 762 if (area_enclosed_polygon.isVertex(pt_to_check)) { 771 763 items_on_perimeter.add(item_to_check); 772 764 } … … 801 793 // Sort areas, smallest to largest 802 794 Collections.sort(area_enclosed_polygon_list, 803 new Comparator< AreaPolygon>() {804 805 public int compare( AreaPolygon ap1, AreaPolygonap2) {795 new Comparator<PolygonBounds>() { 796 797 public int compare(PolygonBounds ap1, PolygonBounds ap2) { 806 798 Double ap1_area = ap1.getArea(); 807 799 Double ap2_area = ap2.getArea(); … … 817 809 // ri = remove index pos 818 810 819 AreaPolygonrpoly = area_enclosed_polygon_list.get(ri);811 PolygonBounds rpoly = area_enclosed_polygon_list.get(ri); 820 812 821 813 for (int ci = ri + 1; ci < area_enclosed_polygon_list.size(); ci++) { 822 814 // ci = check index pos 823 AreaPolygoncpoly = area_enclosed_polygon_list.get(ci);815 PolygonBounds cpoly = area_enclosed_polygon_list.get(ci); 824 816 if (rpoly.completelyContains(cpoly)) { 825 817 area_enclosed_polygon_list.remove(ci); … … 837 829 // recursive call below 838 830 839 for (AreaPolygon area_polygon : area_enclosed_polygon_list) { 840 841 Collection<Item> enclosed_items = FrameUtils.getItemsEnclosedBy( 842 frame, area_polygon); 831 for (PolygonBounds area_polygon : area_enclosed_polygon_list) { 832 833 Collection<Item> enclosed_items = FrameUtils.getItemsEnclosedBy(frame, area_polygon); 843 834 List<Item> enclosed_item_list = new ArrayList<Item>(enclosed_items); 844 835 … … 849 840 // Filter out enclosed-items points that are part of the 850 841 // polygon's perimeter 851 if (area_polygon.is PerimeterPoint(enclosed_item.getPosition())) {842 if (area_polygon.isVertex(enclosed_item.getPosition())) { 852 843 enclosed_item_list.remove(i); 853 844 // Don't include items the user hasn't asked us to. … … 863 854 // Recursively work on the identified sub-group 864 855 865 XGroupItem xgroup_item = new XGroupItem(frame, enclosed_item_list, 866 area_polygon); 856 XGroupItem xgroup_item = new XGroupItem(frame, enclosed_item_list, area_polygon); 867 857 868 858 grouped_item_list.add(xgroup_item); -
trunk/src/org/expeditee/io/flowlayout/XItem.java
r919 r1102 19 19 package org.expeditee.io.flowlayout; 20 20 21 import java.awt.Point;22 import java.awt.Rectangle;23 21 22 import org.expeditee.core.Point; 23 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 24 24 import org.expeditee.items.Item; 25 25 26 26 public abstract class XItem 27 27 { 28 protected Rectanglebounding_rect;28 protected AxisAlignedBoxBounds bounding_rect; 29 29 30 30 protected XItem() … … 33 33 } 34 34 35 protected XItem( Rectangleimprint_bounding_rect)35 protected XItem(AxisAlignedBoxBounds imprint_bounding_rect) 36 36 { 37 37 this.bounding_rect = imprint_bounding_rect; … … 40 40 public int getX() 41 41 { 42 return bounding_rect. x;42 return bounding_rect.getMinX(); 43 43 } 44 44 … … 46 46 { 47 47 // name alias for getX() 48 return bounding_rect. x;48 return bounding_rect.getMinX(); 49 49 } 50 50 51 51 public int getY() 52 52 { 53 return bounding_rect. y;53 return bounding_rect.getMinY(); 54 54 } 55 55 … … 57 57 { 58 58 // name alias for getY() 59 return bounding_rect. y;59 return bounding_rect.getMinY(); 60 60 } 61 61 62 62 public int getBoundingYBot() 63 63 { 64 return bounding_rect. y + bounding_rect.height -1;64 return bounding_rect.getMaxY(); 65 65 } 66 66 67 67 public int getBoundingXRight() 68 68 { 69 return bounding_rect. x + bounding_rect.width -1;69 return bounding_rect.getMaxX(); 70 70 } 71 71 72 72 public int getBoundingWidth() 73 73 { 74 return bounding_rect. width;74 return bounding_rect.getWidth(); 75 75 } 76 76 77 77 public int getBoundingHeight() 78 78 { 79 return bounding_rect. height;79 return bounding_rect.getHeight(); 80 80 } 81 81 82 public RectanglegetBoundingRect()82 public AxisAlignedBoxBounds getBoundingRect() 83 83 { 84 84 return bounding_rect; 85 85 } 86 86 87 public Rectangle setBoundingRect(Rectanglerect)87 public AxisAlignedBoxBounds setBoundingRect(AxisAlignedBoxBounds rect) 88 88 { 89 89 return bounding_rect = rect; -
trunk/src/org/expeditee/io/flowlayout/XOrderedLine.java
r919 r1102 19 19 package org.expeditee.io.flowlayout; 20 20 21 import java.awt.Rectangle;22 21 import java.util.ArrayList; 23 22 import java.util.List; 23 24 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 24 25 25 26 public class XOrderedLine … … 83 84 { 84 85 // Simple case => want to insert based on the new_item's xl position 85 Rectanglerect = new_item.getBoundingRect();86 int xl = rect. x;86 AxisAlignedBoxBounds rect = new_item.getBoundingRect(); 87 int xl = rect.getMinX(); 87 88 orderedMergeItem(xl,new_item); 88 89 } -
trunk/src/org/expeditee/io/flowlayout/XRawItem.java
r972 r1102 41 41 else { 42 42 // Just in case it isn't a text item 43 bounding_rect = item.get Area().getBounds();43 bounding_rect = item.getBoundingBox(); 44 44 } 45 45 -
trunk/src/org/expeditee/items/Circle.java
r919 r1102 19 19 package org.expeditee.items; 20 20 21 import java.awt.Color;22 import java.awt.Graphics2D;23 import java.awt.Polygon;24 import java.awt.Rectangle;25 import java.awt.geom.Point2D;26 21 import java.util.Collection; 27 22 import java.util.LinkedList; 23 24 import org.expeditee.core.Colour; 25 import org.expeditee.core.Dimension; 26 import org.expeditee.core.Fill; 27 import org.expeditee.core.Point; 28 import org.expeditee.core.Stroke; 29 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 30 import org.expeditee.core.bounds.CombinationBoxBounds; 31 import org.expeditee.core.bounds.EllipticalBounds; 32 import org.expeditee.core.bounds.PolygonBounds; 33 import org.expeditee.gio.EcosystemManager; 28 34 29 35 /** … … 42 48 * @param _source 43 49 */ 44 public Circle(Text source) { 50 public Circle(Text source) 51 { 45 52 super(source); 46 53 // Collection<Item> connected = source.getAllConnected(); … … 50 57 _center.addEnclosure(this); 51 58 _line.setHidden(true); 52 updatePolygon();59 invalidateBounds(); 53 60 } 54 61 … … 87 94 88 95 @Override 89 public Polygon getEnclosedShape() {96 public PolygonBounds getEnclosedShape() { 90 97 // assert(_poly != null); 91 98 // Ensure that vector items will gradient fill are painted OK!! 92 if (_poly == null) { 93 updatePolygon(); 94 } 95 return _poly; 99 return ((EllipticalBounds) updateBounds()).getPolygon(16); 96 100 } 97 101 … … 138 142 newCircle._line.setVisible(_line.isVisible()); 139 143 newCircle._source.setVisible(_source.isVisible()); 140 newCircle. updatePolygon();144 newCircle.invalidateBounds(); 141 145 return newCircle; 142 146 } … … 152 156 153 157 @Override 154 public boolean contains( int x, int y) {158 public boolean contains(Point p) { 155 159 double radius = getRadius(); 156 160 157 double distance = Math.sqrt(Math.pow(Math.abs(_center.getX() - x), 2)158 + Math.pow(Math.abs(_center.getY() - y), 2));161 double distance = Math.sqrt(Math.pow(Math.abs(_center.getX() - p.x), 2) 162 + Math.pow(Math.abs(_center.getY() - p.y), 2)); 159 163 160 164 return Math.abs(distance - radius) < getGravity() * 2; … … 167 171 */ 168 172 @Override 169 public void paint( Graphics2D g) {173 public void paint() { 170 174 int radius = (int) Math.round(getRadius()); 171 int diameter = radius * 2; 172 Color fillColor = getFillColor(); 173 if (fillColor != null) { 174 setFillPaint(g); 175 g.fillOval(_center.getX() - radius, _center.getY() - radius, 176 diameter, diameter); 175 Point centre = new Point(_center.getX(), _center.getY()); 176 Dimension diameters = new Dimension(radius * 2, radius * 2); 177 Fill fill = new Fill(getFillColor()); 178 Colour lineColour = null; 179 Stroke lineStroke = null; 180 if (isHighlighted()) { 181 lineColour = getHighlightColor(); 182 lineStroke = HIGHLIGHT_STROKE; 183 } else if (getThickness() > 0 || getFillColor() == null) { 184 lineColour = getPaintColor(); 185 lineStroke = _line.getStroke(); 177 186 } 178 if (getThickness() > 0 || fillColor == null) { 179 Color lineColor = getPaintColor(); 180 g.setColor(lineColor); 181 g.setStroke(_line.getStroke()); 182 g.drawOval(_center.getX() - radius, _center.getY() - radius, 183 diameter, diameter); 187 188 EcosystemManager.getGraphicsManager().drawOval(centre, diameters, 0.0f, fill, lineColour, lineStroke); 189 190 if (isHighlighted()) { 191 _center.paint(); 184 192 } 185 // Arc version, same result but allows for portions of the circle to be 186 // drawn 187 // g.drawArc(end.getX() - (distance / 2), end.getY() - (distance / 2), 188 // distance, distance, 0, 360); 189 190 if (isHighlighted()) { 191 // Flag the background color of the circle so that the item will be 192 // drawn with alternate color if the background is the same as 193 // the highlight} 194 _center.paint(g); 195 Color highlightColor = getHighlightColor(); 196 g.setColor(highlightColor); 197 g.setStroke(HIGHLIGHT_STROKE); 198 g.drawOval(_center.getX() - radius, _center.getY() - radius, 199 diameter, diameter); 200 } 201 } 202 203 @Override 204 public void setHighlightMode(HighlightMode mode, Color color) { 205 _center.setHighlightMode(mode, color); 206 super.setHighlightMode(mode, color); 207 } 208 209 @Override 210 public int setHighlightColor(Color c) { 193 } 194 195 @Override 196 public void setHighlightModeAndColour(HighlightMode mode, Colour color) { 197 _center.setHighlightModeAndColour(mode, color); 198 super.setHighlightModeAndColour(mode, color); 199 } 200 201 @Override 202 public void setHighlightColor(Colour c) { 211 203 _center.setHighlightColor(c); 212 returnsuper.setHighlightColor(c);213 } 214 215 @Override 216 public void setFillColor(Colo r c) {204 /*return*/ super.setHighlightColor(c); 205 } 206 207 @Override 208 public void setFillColor(Colour c) { 217 209 super.setFillColor(c); 218 210 _center.setColor(c); … … 221 213 222 214 @Override 223 public void setGradientColor(Colo r c) {215 public void setGradientColor(Colour c) { 224 216 super.setGradientColor(c); 225 217 invalidateCommonTrait(ItemAppearence.GradientColor); … … 255 247 */ 256 248 @Override 257 public void updatePolygon() { 258 double radius = getRadius(); 259 // Approximation of circle for mouse interaction 260 int points = 20; 261 262 double radians = 0.0; 263 int xPoints[] = new int[points]; 264 int yPoints[] = new int[xPoints.length]; 265 266 for (int i = 0; i < xPoints.length; i++) { 267 xPoints[i] = (int) Math.round(radius * Math.cos(radians)); 268 yPoints[i] = (int) Math.round(radius * Math.sin(radians)); 269 radians += (2.0 * Math.PI) / xPoints.length; 270 } 271 272 _poly = new Polygon(xPoints, yPoints, xPoints.length); 273 _poly.translate(_center.getX(), _center.getY()); 274 return; 249 public EllipticalBounds updateBounds() 250 { 251 return new EllipticalBounds(_center.getPosition(), (int) (getRadius() * 2)); 275 252 } 276 253 … … 280 257 } 281 258 282 /** 283 * Resizes the circle from the center. 284 */ 285 @Override 286 public void setSize(float size) { 259 /** Resizes the circle from the center. */ 260 @Override 261 public void setSize(float size) 262 { 287 263 double ratio = size / getRadius(); 288 264 … … 290 266 _source.translate(_center.getPosition(), ratio); 291 267 292 updatePolygon();268 invalidateBounds(); 293 269 } 294 270 … … 303 279 } 304 280 305 @Override 306 public void translate(Point2D origin, double ratio) { 307 updatePolygon(); 281 // TODO: Why is this commented out? cts16 282 @Override 283 public void translate(Point origin, double ratio) 284 { 285 invalidateBounds(); 308 286 // _center.translate(origin, ratio); 309 287 // super.translate(origin, ratio); … … 311 289 312 290 @Override 313 public Rectangle[]getDrawingArea() {291 public AxisAlignedBoxBounds getDrawingArea() { 314 292 315 293 float thickness = getThickness(); … … 318 296 int size = (int) ((2 * radius) + 3.0 + thickness); 319 297 320 return new Rectangle[] { new Rectangle((int) (_center.getX() - radius298 return new AxisAlignedBoxBounds((int) (_center.getX() - radius 321 299 - 0.5 - (thickness / 2.0)), (int) (_center.getY() - radius 322 - 0.5 - (thickness / 2.0)), size, size) };300 - 0.5 - (thickness / 2.0)), size, size); 323 301 } 324 302 -
trunk/src/org/expeditee/items/Constraint.java
r919 r1102 28 28 */ 29 29 public class Constraint { 30 30 31 public static final int VERTICAL = 2; 31 32 -
trunk/src/org/expeditee/items/Dot.java
r919 r1102 19 19 package org.expeditee.items; 20 20 21 import java.awt.Color;22 import java.awt.Graphics2D;23 import java.awt.Polygon;24 import java.awt.Rectangle;25 21 import java.util.ArrayList; 26 22 import java.util.LinkedList; 27 23 import java.util.List; 28 24 29 import org.expeditee.gui.DisplayIO; 25 import org.expeditee.core.Colour; 26 import org.expeditee.core.Dimension; 27 import org.expeditee.core.Fill; 28 import org.expeditee.core.Point; 29 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 30 import org.expeditee.core.bounds.Bounds; 31 import org.expeditee.core.bounds.PolygonBounds; 32 import org.expeditee.gio.EcosystemManager; 33 import org.expeditee.gio.GraphicsManager; 34 import org.expeditee.gui.DisplayController; 30 35 import org.expeditee.gui.Frame; 31 36 import org.expeditee.gui.FrameGraphics; 32 import org.expeditee.gui.FrameKeyboardActions;33 37 34 38 /** … … 70 74 71 75 @Override 72 public void setColor(Colo r c) {76 public void setColor(Colour c) { 73 77 super.setColor(c); 74 78 … … 79 83 80 84 @Override 81 public void setAnchorLeft( Floatanchor) {85 public void setAnchorLeft(Integer anchor) { 82 86 if (!isLineEnd()) { 83 87 super.setAnchorLeft(anchor); … … 88 92 invalidateCommonTrait(ItemAppearence.PreMoved); 89 93 90 this._anchorLeft = anchor; 91 this._anchorRight = null; 94 this._anchoring.setLeftAnchor(anchor); 92 95 93 96 int oldX = getX(); … … 102 105 103 106 @Override 104 public void setAnchorRight( Floatanchor) {107 public void setAnchorRight(Integer anchor) { 105 108 if (!isLineEnd()) { 106 109 super.setAnchorRight(anchor); … … 110 113 invalidateCommonTrait(ItemAppearence.PreMoved); 111 114 112 this._anchorRight = anchor; 113 this._anchorLeft = null; 115 this._anchoring.setRightAnchor(anchor); 114 116 115 117 int oldX = getX(); 116 118 if (anchor != null) { 117 float deltaX = FrameGraphics.getMaxFrameSize().width - anchor 118 - getBoundsWidth() - oldX; 119 float deltaX = DisplayController.getFramePaintArea().getWidth() - anchor - getBoundsWidth() - oldX; 119 120 120 121 anchorConnected(AnchorEdgeType.Right, deltaX); … … 126 127 127 128 @Override 128 public void setAnchorTop( Floatanchor) {129 public void setAnchorTop(Integer anchor) { 129 130 if (!isLineEnd()) { 130 131 super.setAnchorTop(anchor); … … 134 135 invalidateCommonTrait(ItemAppearence.PreMoved); 135 136 136 this._anchorTop = anchor; 137 this._anchorBottom = null; 137 this._anchoring.setTopAnchor(anchor); 138 138 139 139 int oldY = getY(); … … 148 148 149 149 @Override 150 public void setAnchorBottom( Floatanchor) {150 public void setAnchorBottom(Integer anchor) { 151 151 if (!isLineEnd()) { 152 152 super.setAnchorBottom(anchor); … … 156 156 invalidateCommonTrait(ItemAppearence.PreMoved); 157 157 158 this._anchorBottom = anchor; 159 this._anchorTop = null; 158 this._anchoring.setBottomAnchor(anchor); 160 159 161 160 int oldY = getY(); 162 161 if (anchor != null) { 163 float deltaY = FrameGraphics.getMaxFrameSize().height - anchor 164 - getBoundsHeight() - oldY; 162 float deltaY = DisplayController.getFramePaintArea().getHeight() - anchor - getBoundsHeight() - oldY; 165 163 anchorConnected(AnchorEdgeType.Bottom, deltaY); 166 164 } … … 173 171 174 172 @Override 175 public void paint(Graphics2D g) { 173 public void paint() { 174 GraphicsManager g = EcosystemManager.getGraphicsManager(); 176 175 if (isHighlighted() /* && !FreeItems.getInstance().contains(this) */) { 177 Color highlightColor = getHighlightColor(); 178 g.setColor(highlightColor); 179 g.setStroke(DOT_STROKE); 176 Colour highlightColor = getHighlightColor(); 177 Fill fill = new Fill(highlightColor); 180 178 // g.setStroke() 181 179 // Draw the highlighting rectangle surrounding the dot 182 180 // this is drawn even if its part of a rectangle 183 181 184 if (isVectorItem()) 185 updatePolygon(); 186 187 Rectangle rect = getPolygon().getBounds(); 188 if (_mode == HighlightMode.Enclosed || 189 // Make sure single dots are highlighted filled 190 this.getConnected().size() <= 1) 191 g.fillRect(rect.x, rect.y, rect.width, rect.height); 192 else if (_mode == HighlightMode.Connected){ 193 g.setStroke(HIGHLIGHT_STROKE); 194 g.drawRect(rect.x, rect.y, rect.width, rect.height); 195 }else if (_mode == HighlightMode.Normal) { 196 g.fillOval(rect.x, rect.y, rect.width, rect.height); 182 if (isVectorItem()) invalidateBounds(); 183 184 AxisAlignedBoxBounds bounds = getBoundingBox(); 185 if (_highlightMode == HighlightMode.Enclosed || this.getConnected().size() <= 1) { // Make sure single dots are highlighted filled 186 g.drawRectangle(bounds.getTopLeft(), bounds.getSize(), 0.0f, fill, highlightColor, DOT_STROKE, null); 187 } else if (_highlightMode == HighlightMode.Connected) { 188 g.drawRectangle(bounds.getTopLeft(), bounds.getSize(), 0.0f, null, highlightColor, HIGHLIGHT_STROKE, null); 189 } else if (_highlightMode == HighlightMode.Normal) { 190 g.drawOval(bounds.getCentre(), bounds.getSize(), 0.0f, fill, highlightColor, DOT_STROKE); 197 191 } 198 192 // System.out.println(_mode.toString()); … … 200 194 201 195 // dots on lines are hidden 202 if (getLines().size() > 0) 203 return; 204 205 g.setColor(getPaintColor()); 196 if (getLines().size() > 0) return; 206 197 207 198 int thick = (int) getThickness(); 208 if (thick < MINIMUM_DOT_SIZE) 209 thick = MINIMUM_DOT_SIZE;210 211 int width = thick / 2; 212 199 if (thick < MINIMUM_DOT_SIZE) thick = MINIMUM_DOT_SIZE; 200 201 Fill fill = _filled ? new Fill(getPaintColor()) : null; 202 203 // TODO: On testing, this code doesn't seem to work (can't change to any type except square). cts16 213 204 switch (_type) { 214 case circle: 215 if (_filled) 216 g.fillOval(getX() - width, getY() - width, thick, thick); 217 else { 218 g.drawOval(getX() - width, getY() - width, thick, thick); 219 } 220 break; 221 case diamond: 222 int[] x = new int[4]; 223 int[] y = new int[4]; 224 225 x[0] = x[2] = getX(); 226 x[1] = getX() - width; 227 x[3] = getX() + width; 228 229 y[1] = y[3] = getY(); 230 y[0] = getY() - width; 231 y[2] = getY() + width; 232 233 if (_filled) 234 g.fillPolygon(x, y, 4); 235 else { 236 g.drawPolygon(x, y, 4); 237 } 238 break; 239 case triangle: 240 x = new int[3]; 241 y = new int[3]; 242 243 x[0] = getX(); 244 x[1] = getX() - width; 245 x[2] = getX() + width; 246 247 y[0] = getY() - width; 248 y[1] = y[2] = getY() + width; 249 250 if (_filled) 251 g.fillPolygon(x, y, 3); 252 else { 253 g.drawPolygon(x, y, 3); 254 } 255 break; 256 case roundSquare: 257 int arc = thick / 2; 258 if (_filled) 259 g.fillRoundRect(getX() - width, getY() - width, thick, thick, 260 arc, arc); 261 else { 262 g.drawRoundRect(getX() - width, getY() - width, thick, thick, 263 arc, arc); 264 } 265 break; 266 default: 267 if (_filled) 268 g.fillRect(getX() - width, getY() - width, thick, thick); 269 else { 270 g.drawRect(getX() - width, getY() - width, thick, thick); 271 } 272 205 case circle: 206 g.drawOval( 207 new Point(getX(), getY()), 208 new Dimension(thick, thick), 209 0.0, 210 fill, 211 getPaintColor(), 212 null 213 ); 214 break; 215 case diamond: 216 PolygonBounds diamond = PolygonBounds.getDiamond(thick, thick).translate(getX(), getY()).close(); 217 g.drawPolygon(diamond, null, null, 0.0, fill, getPaintColor(), null); 218 break; 219 case triangle: 220 PolygonBounds triangle = PolygonBounds.getTriangle(thick, thick).translate(getX(), getY()).close(); 221 g.drawPolygon(triangle, null, null, 0.0, fill, getPaintColor(), null); 222 break; 223 case roundSquare: 224 int arc = thick / 4; 225 g.drawRectangle( 226 new Point(getX(), getY()), 227 new Dimension(thick, thick), 228 0.0, 229 fill, 230 getPaintColor(), 231 null, 232 new Dimension(arc, arc) 233 ); 234 break; 235 default: 236 g.drawRectangle( 237 new Point(getX(), getY()), 238 new Dimension(thick, thick), 239 0.0, 240 fill, 241 getPaintColor(), 242 null, 243 null 244 ); 273 245 } 274 246 … … 276 248 277 249 /** 278 * Updates the points of the polygon surrounding this Dot 250 * Updates the bounds surrounding this Dot. 251 * TODO: Standardise Dot minimum size. cts16 279 252 */ 280 public void updatePolygon() { 253 public Bounds updateBounds() 254 { 281 255 int thick = Math.round(getThickness()); 256 282 257 // Sets a minimum size for the dot 283 258 thick = Math.max(thick, getGravity() * 2); 259 260 // Include the gravity in the thickness 261 thick += 2 * getGravity(); 262 284 263 285 264 int x = getX() - thick / 2; 286 265 int y = getY() - thick / 2; 287 288 _poly = new Polygon(); 289 _poly.addPoint(x - getGravity(), y - getGravity()); 290 _poly.addPoint(x + thick + getGravity(), y - getGravity()); 291 _poly.addPoint(x + thick + getGravity(), y + thick + getGravity()); 292 _poly.addPoint(x - getGravity(), y + thick + getGravity()); 266 267 return new AxisAlignedBoxBounds(x, y, thick, thick); 293 268 } 294 269 … … 303 278 304 279 @Override 305 public int setHighlightColor() {306 super.setHighlightColor ();307 308 return Item.DEFAULT_CURSOR;280 public void setHighlightColorToDefault() { 281 super.setHighlightColorToDefault(); 282 283 //return Item.DEFAULT_CURSOR; 309 284 } 310 285 311 286 @Override 312 287 public void setAnnotation(boolean val) { 313 Display IO.setCursorPosition(this.getPosition());314 FrameKeyboardActions.replaceDot(this, '@');288 DisplayController.setCursorPosition(this.getPosition()); 289 Item.replaceDot(this, '@'); 315 290 } 316 291 … … 406 381 if (parent != null && parent != current) { 407 382 this.setParent(parent); 408 if (Display IO.getCurrentSide() == 0)409 this.setX(this.getX() - Display IO.getMiddle());383 if (DisplayController.getCurrentSide() == DisplayController.TwinFramesSide.LEFT) 384 this.setX(this.getX() - DisplayController.getTwinFramesSeparatorX()); 410 385 else 411 this.setX(this.getX() + Display IO.getMiddle());386 this.setX(this.getX() + DisplayController.getTwinFramesSeparatorX()); 412 387 } 413 388 break; … … 420 395 if (line.getID() < 0 && !current.getItems().contains(line)) { 421 396 line.setID(current.getNextItemID()); 422 line.setHighlightColor ();397 line.setHighlightColorToDefault(); 423 398 // Mike: Why was this line here? 424 399 // anchor(line); … … 436 411 437 412 @Override 438 public void lineColorChanged(Colo r c) {413 public void lineColorChanged(Colour c) { 439 414 if (getColor() != c) { 440 415 setColor(c); … … 450 425 return super.dontSave(); 451 426 } 427 428 @Override 429 public float getSize() 430 { 431 return getThickness(); 432 } 452 433 } -
trunk/src/org/expeditee/items/FrameBitmap.java
r919 r1102 19 19 package org.expeditee.items; 20 20 21 import java.awt.Color;22 import java.awt.Image;23 import java.awt.image.BufferedImage;24 import java.awt.image.ImageObserver;25 21 import java.util.List; 26 22 23 import org.expeditee.core.Colour; 24 import org.expeditee.core.Image; 27 25 import org.expeditee.gui.Frame; 28 26 import org.expeditee.gui.FrameIO; … … 31 29 32 30 public class FrameBitmap extends FramePicture { 33 public FrameBitmap(Text source, Image Observer observer, Imageimage){34 super(source, observer,image);31 public FrameBitmap(Text source, Image image){ 32 super(source, image); 35 33 } 36 34 … … 59 57 return false; 60 58 61 BufferedImage bi = new BufferedImage(width, height, 62 BufferedImage.TYPE_INT_ARGB); 59 Image bi = Image.createImage(width, height); 63 60 // now set the bits on the image 64 final int transparent = (new Colo r(0F, 0F, 0F, 0F)).getRGB();65 final int main = _source.getPaintColor().get RGB();66 final Colo r c = _source.getPaintColor();61 final int transparent = (new Colour(0F, 0F, 0F, 0F)).getARGB32BitPacked(); 62 final int main = _source.getPaintColor().getARGB32BitPacked(); 63 final Colour c = _source.getPaintColor(); 67 64 int currentColor = main; 68 65 int row = 0; … … 74 71 // Space is transparent as is 0 75 72 if (Character.isDigit(currentPixel)) { 76 int alpha = Math.round((currentPixel - '0') * 25.5F);77 currentColor = new Colo r(c.getRed(), c.getGreen(), c78 .getBlue(), alpha).get RGB();73 int alpha = Math.round((currentPixel - '0') * (Colour.COMPONENT_MAX_VALUE / 10.0f)); 74 currentColor = new Colour(c.getRed(), c.getGreen(), c 75 .getBlue(), alpha).getARGB32BitPacked(); 79 76 }else if (currentPixel != ' ') { 80 77 currentColor = main; 81 78 } 82 79 } 83 bi.set RGB(i, row, currentColor);80 bi.setPixel(i, row, Colour.fromARGB32BitPacked(currentColor)); 84 81 } 85 82 row++; … … 92 89 @Override 93 90 protected Picture createPicture() { 94 return new FrameBitmap((Text) _source.copy(), 95 _imageObserver, _image); 91 return new FrameBitmap((Text) _source.copy(), _image); 96 92 } 97 93 -
trunk/src/org/expeditee/items/FrameImage.java
r919 r1102 19 19 package org.expeditee.items; 20 20 21 import java.awt.Image; 22 import java.awt.image.ImageObserver; 23 21 import org.expeditee.core.Image; 24 22 import org.expeditee.gui.Frame; 25 23 import org.expeditee.gui.FrameGraphics; … … 41 39 * screen. 42 40 */ 43 public FrameImage(Text source, Image Observer observer, Imageimage) {44 super(source, observer,image);41 public FrameImage(Text source, Image image) { 42 super(source, image); 45 43 } 46 44 47 45 @Override 48 46 protected Picture createPicture() { 49 return new FrameImage(_source.copy(), _image Observer, _image);47 return new FrameImage(_source.copy(), _image); 50 48 } 51 49 … … 59 57 return false; 60 58 61 frame.setBuffer(null); 62 FrameGraphics.UpdateBuffer(frame, false, false); 59 frame.setBuffer(FrameGraphics.getFrameImage(frame, null, null, false, false)); 63 60 _image = frame.getBuffer(); 64 61 … … 66 63 // been created to begin with 67 64 parseSize(); 68 updatePolygon();65 invalidateBounds(); 69 66 return true; 70 67 } -
trunk/src/org/expeditee/items/FramePicture.java
r919 r1102 19 19 package org.expeditee.items; 20 20 21 import java.awt.Color; 22 import java.awt.Image; 23 import java.awt.image.ImageObserver; 24 21 import org.expeditee.core.Colour; 22 import org.expeditee.core.Image; 25 23 import org.expeditee.gui.AttributeValuePair; 26 24 import org.expeditee.gui.Frame; 27 25 28 26 public abstract class FramePicture extends Picture { 29 protected FramePicture(Text source, Image Observer observer, Imageimage) {30 super(source, observer,image);27 protected FramePicture(Text source, Image image) { 28 super(source, image); 31 29 } 32 30 33 31 @Override 34 public void setColor(Colo r c) {32 public void setColor(Colour c) { 35 33 super.setColor(c); 36 34 refresh(); … … 55 53 } 56 54 } 57 updatePolygon();55 invalidateBounds(); 58 56 } 59 57 -
trunk/src/org/expeditee/items/Item.java
r977 r1102 19 19 package org.expeditee.items; 20 20 21 import java.awt.BasicStroke;22 import java.awt.Color;23 import java.awt.Cursor;24 import java.awt.GradientPaint;25 import java.awt.Graphics2D;26 import java.awt.Point;27 import java.awt.Polygon;28 import java.awt.Rectangle;29 import java.awt.Shape;30 import java.awt.Stroke;31 import java.awt.geom.AffineTransform;32 import java.awt.geom.Area;33 import java.awt.geom.Point2D;34 import java.awt.geom.Rectangle2D;35 21 import java.util.ArrayList; 36 22 import java.util.Collection; … … 46 32 import org.expeditee.actions.Misc; 47 33 import org.expeditee.actions.Simple; 34 import org.expeditee.core.Anchoring; 35 import org.expeditee.core.Colour; 36 import org.expeditee.core.Cursor; 37 import org.expeditee.core.Dimension; 38 import org.expeditee.core.Fill; 39 import org.expeditee.core.GradientFill; 40 import org.expeditee.core.Point; 41 import org.expeditee.core.Stroke; 42 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 43 import org.expeditee.core.bounds.Bounds; 44 import org.expeditee.core.bounds.EllipticalBounds; 45 import org.expeditee.core.bounds.PolygonBounds; 46 import org.expeditee.gio.EcosystemManager; 47 import org.expeditee.gio.GraphicsManager; 48 import org.expeditee.gio.gesture.StandardGestureActions; 48 49 import org.expeditee.gui.AttributeValuePair; 49 import org.expeditee.gui.Display IO;50 import org.expeditee.gui.DisplayController; 50 51 import org.expeditee.gui.Frame; 51 52 import org.expeditee.gui.FrameGraphics; 52 53 import org.expeditee.gui.FrameIO; 53 import org.expeditee.gui.FrameKeyboardActions;54 import org.expeditee.gui.FrameMouseActions;55 54 import org.expeditee.gui.FrameUtils; 56 55 import org.expeditee.gui.FreeItems; … … 75 74 public abstract class Item implements Comparable<Item>, Runnable { 76 75 77 public static final Float DEFAULT_THICKNESS = 2f; 78 79 public static final Float MINIMUM_THICKNESS = 0f; 80 81 public static final Float MINIMUM_PAINT_THICKNESS = 1f; 82 83 protected final int JOIN = BasicStroke.JOIN_ROUND; 84 85 protected final int CAP = BasicStroke.CAP_BUTT; 86 87 protected final Stroke DOT_STROKE = new BasicStroke(DEFAULT_THICKNESS, 88 CAP, JOIN, 4.0F); 89 90 protected final Stroke HIGHLIGHT_STROKE = new BasicStroke( 91 MINIMUM_THICKNESS, CAP, JOIN, 4.0F); 92 93 // contains all dots (including this one) that form an enclosure 94 // if this dot is part of an enclosing shape 95 private Collection<Item> _enclosure = null; 96 97 public static final int LEFT_MARGIN = 13; 98 99 // indicates which end the arrowhead should be drawn at 100 protected Polygon _poly = null; 101 102 protected boolean _connectedToAnnotation = false; 103 104 protected boolean _save = true; 105 106 private int _gradientAngle = 0; 107 108 public static final int NEAR_DISTANCE = 15; 109 110 /** 111 * The default Color to draw highlighting in 112 */ 113 public static final int DEFAULT_HIGHLIGHT_THICKNESS = 2; 114 115 public static final Color DEFAULT_HIGHLIGHT = Color.RED; 116 117 public static final Color DEPRESSED_HIGHLIGHT = Color.GREEN; 118 119 public static final Color ALTERNATE_HIGHLIGHT = Color.BLUE; 120 121 public static final Color LINK_COLOR = Color.BLACK; 122 123 public static final Color ACTION_COLOR = Color.BLACK; 124 125 public static final Color LINK_ACTION_COLOR = Color.RED; 126 127 public static final Color DEFAULT_FOREGROUND = Color.BLACK; 128 129 public static final Color DEFAULT_BACKGROUND = Color.white; 130 131 public static final Color TRANSPARENT = new Color(0, 0, 0, 0); 132 133 /** 134 * The number of pixels highlighting should extend around Items. 135 */ 136 public static final int XGRAVITY = 3; 137 138 public static final int MARGIN_RIGHT = 2; 139 140 public static final int MARGIN_LEFT = 15; 141 142 protected static final double DEFAULT_ARROWHEAD_RATIO = 0.3; // used to be 0.5 143 144 public static final double DEFAULT_ARROWHEAD_NIB_PERC = 0.75; 145 146 public static final Color GREEN = Color.GREEN.darker(); 147 148 public static final int UNCHANGED_CURSOR = -100; 149 150 public static final int DEFAULT_CURSOR = Cursor.DEFAULT_CURSOR; 151 152 public static final int HIDDEN_CURSOR = Cursor.CUSTOM_CURSOR; 153 154 public static final int TEXT_CURSOR = Cursor.TEXT_CURSOR; 155 156 public static final int CROP_CURSOR = Cursor.CROSSHAIR_CURSOR; 157 158 // The default value for integer attributes 159 public static final int DEFAULT_INTEGER = -1; 160 161 protected DotType _type = DotType.square; 162 163 protected boolean _filled = true; 164 165 private Tooltip _tooltip = new Tooltip(); 166 76 public enum HighlightMode { 77 None, // The item has no highlighting 78 Enclosed, // The item is part of the current enclosure 79 Connected, // The item is connected to the current item 80 Disconnect, // The item is a free item 81 Normal // The item is the current item 82 } 83 84 /** Which edge of the window things are anchored to. */ 167 85 public enum AnchorEdgeType { 168 86 None, Left, Right, Top, Bottom 169 87 } 170 171 public static void DuplicateItem(Item source, Item dest) { 172 dest.setX(source.getX()); 173 dest.setY(source.getY()); 174 175 dest.setActions(source.getAction()); 176 dest.setActionCursorEnter(source.getActionCursorEnter()); 177 dest.setActionCursorLeave(source.getActionCursorLeave()); 178 dest.setActionEnterFrame(source.getActionEnterFrame()); 179 dest.setActionLeaveFrame(source.getActionLeaveFrame()); 180 dest.setActionMark(source.getActionMark()); 181 182 dest.setBackgroundColor(source.getBackgroundColor()); 183 dest.setBottomShadowColor(source.getBottomShadowColor()); 184 dest.setColor(source.getColor()); 185 dest.setBorderColor(source.getBorderColor()); 186 187 dest.setTooltips(source.getTooltip()); 188 dest.setData(source.getData()); 189 dest.setTag(source.getTag()); 190 dest.setFillColor(source.getFillColor()); 191 dest.setGradientColor(source.getGradientColor()); 192 dest.setGradientAngle(source.getGradientAngle()); 193 dest.setFillPattern(source.getFillPattern()); 194 195 dest.setHighlight(source.getHighlight()); 196 dest.setLink(source.getLink()); 197 dest.setLinkFrameset(source.getLinkFrameset()); 198 dest.setLinkMark(source.getLinkMark()); 199 dest.setLinkTemplate(source.getLinkTemplate()); 200 201 // dest.setMaxWidth(source.getMaxWidth()); 202 203 dest.setOffset(source.getOffset()); 204 // dest.setOwner(source.getOwner()); 205 dest.setThickness(source.getThickness()); 206 dest.setSize(source.getSize()); 207 dest.setTopShadowColor(source.getTopShadowColor()); 208 dest.setLinePattern(source.getLinePattern()); 209 210 dest.setFloating(source.isFloating()); 211 dest.setArrow(source.getArrowheadLength(), source.getArrowheadRatio(), source.getArrowheadNibPerc()); 212 213 dest.setDotType(source.getDotType()); 214 dest.setFilled(source.getFilled()); 88 89 public static final float SIZE_NOT_APPLICABLE = Float.NaN; 90 91 public static final Float DEFAULT_THICKNESS = 2f; 92 93 public static final Float MINIMUM_THICKNESS = 0f; 94 95 public static final Float MINIMUM_PAINT_THICKNESS = 1f; 96 97 protected static final Stroke.JOIN DEFAULT_JOIN = Stroke.JOIN.ROUND; 98 99 protected static final Stroke.CAP DEFAULT_CAP = Stroke.CAP.BUTT; 100 101 protected static final Stroke DOT_STROKE = new Stroke(DEFAULT_THICKNESS, DEFAULT_CAP, DEFAULT_JOIN); 102 103 protected static final Stroke HIGHLIGHT_STROKE = new Stroke(MINIMUM_THICKNESS, DEFAULT_CAP, DEFAULT_JOIN); 104 105 public static final int LEFT_MARGIN = 13; 106 107 public static final int NEAR_DISTANCE = 15; 108 109 public static final int DEFAULT_HIGHLIGHT_THICKNESS = 2; 110 111 /** The default colour to draw highlighting in */ 112 public static final Colour DEFAULT_HIGHLIGHT = Colour.RED; 113 114 public static final Colour DEPRESSED_HIGHLIGHT = Colour.GREEN; 115 116 public static final Colour ALTERNATE_HIGHLIGHT = Colour.BLUE; 117 118 public static final Colour LINK_COLOR = Colour.BLACK; 119 120 public static final Colour ACTION_COLOR = Colour.BLACK; 121 122 public static final Colour LINK_ACTION_COLOR = Colour.RED; 123 124 public static final Colour DEFAULT_FOREGROUND = Colour.BLACK; 125 126 public static final Colour DEFAULT_BACKGROUND = Colour.WHITE; 127 128 public static final Colour TRANSPARENT = new Colour(0, 0, 0, 0); 129 130 /** The number of pixels highlighting should extend around Items. */ 131 public static final int XGRAVITY = 3; 132 133 public static final int MARGIN_RIGHT = 2; 134 135 public static final int MARGIN_LEFT = 15; 136 137 protected static final double DEFAULT_ARROWHEAD_RATIO = 0.3; // used to be 0.5 138 139 public static final double DEFAULT_ARROWHEAD_NIB_PERC = 0.75; 140 141 public static final Colour GREEN = Colour.GREEN.darker(); 142 143 //public static final int UNCHANGED_CURSOR = -100; 144 145 public static final Cursor.CursorType DEFAULT_CURSOR = Cursor.CursorType.DEFAULT; 146 147 public static final Cursor.CursorType HIDDEN_CURSOR = Cursor.CursorType.CUSTOM; 148 149 public static final Cursor.CursorType TEXT_CURSOR = Cursor.CursorType.TEXT; 150 151 public static final Cursor.CursorType CROP_CURSOR = Cursor.CursorType.CROSSHAIR; 152 153 /** The default value for integer attributes */ 154 public static final int DEFAULT_INTEGER = -1; 155 156 private static final int BRIGHTNESS = 185; 157 158 /** Contains all dots (including this one) that form an enclosure if this dot is part of an enclosing shape. */ 159 private Collection<Item> _enclosure = null; 160 161 /** The area which this item covers (including its gravity). */ 162 private Bounds _bounds = null; 163 164 /** The area this item covered before it was invalidated. */ 165 private Bounds _oldBounds = null; 166 167 protected boolean _connectedToAnnotation = false; 168 169 protected boolean _save = true; 170 171 /** The angle of change for gradient colour fills (in radians). */ 172 private double _gradientAngle = 0.0; 173 174 private Tooltip _tooltip = new Tooltip(); 175 176 protected Anchoring _anchoring = new Anchoring(); 177 178 /** The highlight mode for this item. */ 179 protected HighlightMode _highlightMode = HighlightMode.None; 180 181 private Point _offset = new Point(0, 0); 182 183 protected float _x; 184 protected float _y; 185 186 private int _id; 187 188 private Item _editTarget = this; 189 190 private String _creationDate = null; 191 192 /** Whether or not this item should display a mark indicating it has a link. */ 193 private boolean _linkMark = true; 194 195 /** Whether or not this item should display a mark indicating it has an action. */ 196 private boolean _actionMark = true; 197 198 /** TODO: Appears unused? cts16 */ 199 private boolean _highlight = true; 200 201 // private int _maxWidth = -1; 202 203 private String _owner = null; 204 205 private String _link = null; 206 207 private boolean _linkHistory = true; 208 209 private StringBuffer _tag = new StringBuffer(); 210 211 private List<String> _actionCursorEnter = null; 212 213 private List<String> _actionCursorLeave = null; 214 215 private List<String> _actionEnterFrame = null; 216 217 private List<String> _actionLeaveFrame = null; 218 219 private PermissionPair _permissionPair = null; 220 221 private UserAppliedPermission _overlayPermission = null; 222 223 /** The primary fill colour of this item. A fill colour of null represents transparent. */ 224 private Colour _fillColour = null; 225 226 /** The secondary fill colour if this item has a gradient fill. Null represents no gradient. */ 227 private Colour _gradientColour = null; 228 229 /** The primary draw colour of this item. Null represents the default colour. */ 230 private Colour _foregroundColour = null; 231 232 /** The colour to draw highlights on this item. */ 233 protected Colour _highlightColour = DEFAULT_HIGHLIGHT; 234 235 /** The background colour for this item. */ 236 private Colour _backgroundColour = null; 237 238 private Colour _colorBorder = null; 239 240 private Colour _colorTopShadow = null; 241 242 private Colour _colorBottomShadow = null; 243 244 /** The shape representing the circle drawn next to link/action items. */ 245 private static EllipticalBounds _linkCircle = null; 246 247 /** The shape representing the cross drawn next to invalid links. */ 248 private static PolygonBounds _linkCircleCross = null; 249 250 private Frame _parent = null; 251 private Frame _oldParent = null; 252 253 protected int _highlightThickness = 2; 254 255 protected int _vectorHighlightThickness = 1; 256 257 // arrowhead parameters 258 private float _arrowheadLength = 0; 259 private double _arrowheadRatio = DEFAULT_ARROWHEAD_RATIO; 260 private double _arrowheadNibPerc = DEFAULT_ARROWHEAD_NIB_PERC; 261 262 private PolygonBounds _arrowhead = null; 263 264 // the list of lines that this point is part of. 265 private List<Line> _lines = new ArrayList<Line>(); 266 267 private int[] _linePattern = null; 268 269 private boolean _floating = false; 270 271 // list of points constrained with this point 272 private List<Constraint> _constraints = new ArrayList<Constraint>(); 273 274 private List<String> _actions = null; 275 276 private List<String> _data = null; 277 278 private String _formula = null; 279 280 private String _link_frameset = null; 281 282 private String _link_template = null; 283 284 private String _fillPattern = null; 285 286 private boolean _visible = true; 287 288 private float _thickness = -1.0F; 289 290 protected Collection<XRayable> _enclosures = new HashSet<XRayable>(); 291 292 private boolean _deleted = false; 293 294 private Overlay _overlay = null; 295 296 protected AttributeValuePair _attributeValuePair = null; 297 298 private Float _autoStamp = null; 299 300 private Item _magnetizedItemLeft = null; 301 302 private Item _magnetizedItemRight = null; 303 304 private Item _magnetizedItemTop = null; 305 306 private Item _magnetizedItemBottom = null; 307 308 protected DotType _type = DotType.square; 309 310 protected boolean _filled = true; 311 312 /** Just calls source.duplicateOnto(dest). */ 313 public static void DuplicateItem(Item source, Item dest) 314 { 315 if (source == null) return; 316 317 source.duplicateOnto(dest); 318 } 319 320 /** Sets the properties of dest so that they match this item's properties. */ 321 public void duplicateOnto(Item dest) 322 { 323 if (dest == null) return; 324 325 dest.setX(this.getX()); 326 dest.setY(this.getY()); 327 328 dest.setActions(this.getAction()); 329 dest.setActionCursorEnter(this.getActionCursorEnter()); 330 dest.setActionCursorLeave(this.getActionCursorLeave()); 331 dest.setActionEnterFrame(this.getActionEnterFrame()); 332 dest.setActionLeaveFrame(this.getActionLeaveFrame()); 333 dest.setActionMark(this.getActionMark()); 334 335 dest.setBackgroundColor(this.getBackgroundColor()); 336 dest.setBottomShadowColor(this.getBottomShadowColor()); 337 dest.setColor(this.getColor()); 338 dest.setBorderColor(this.getBorderColor()); 339 340 dest.setTooltips(this.getTooltip()); 341 dest.setData(this.getData()); 342 dest.setTag(this.getTag()); 343 dest.setFillColor(this.getFillColor()); 344 dest.setGradientColor(this.getGradientColor()); 345 dest.setGradientAngle(this.getGradientAngle()); 346 dest.setFillPattern(this.getFillPattern()); 347 348 dest.setHighlight(this.getHighlight()); 349 dest.setLink(this.getLink()); 350 dest.setLinkFrameset(this.getLinkFrameset()); 351 dest.setLinkMark(this.getLinkMark()); 352 dest.setLinkTemplate(this.getLinkTemplate()); 353 354 // dest.setMaxWidth(this.getMaxWidth()); 355 356 dest.setOffset(this.getOffset()); 357 // dest.setOwner(this.getOwner()); 358 dest.setThickness(this.getThickness()); 359 dest.setSize(this.getSize()); 360 dest.setTopShadowColor(this.getTopShadowColor()); 361 dest.setLinePattern(this.getLinePattern()); 362 363 dest.setFloating(this.isFloating()); 364 dest.setArrow(this.getArrowheadLength(), this.getArrowheadRatio(), this.getArrowheadNibPerc()); 365 dest.setDotType(this.getDotType()); 366 dest.setFilled(this.getFilled()); 215 367 /* 216 368 * Calling the methods will move the item... This messes things up when 217 369 * the user uses backspace to delete a text line end 218 370 */ 219 // dest._anchorLeft = source._anchorLeft; 220 // dest._anchorRight = source._anchorRight; 221 // dest._anchorTop = source._anchorTop; 222 // dest._anchorBottom = source._anchorBottom; 223 dest.setFormula(source.getFormula()); 224 dest._overlay = source._overlay; 225 dest._mode = source._mode;// SelectedMode.None; 226 // dest._highlightColor = source._highlightColor; 227 // dest.setHighlight(source.getHighlight()); 228 229 dest._visible = source._visible; 230 231 Frame parent = DisplayIO.getCurrentFrame(); 232 if (parent == null) 233 parent = source.getParentOrCurrentFrame(); 371 // dest._anchorLeft = this._anchorLeft; 372 // dest._anchorRight = this._anchorRight; 373 // dest._anchorTop = this._anchorTop; 374 // dest._anchorBottom = this._anchorBottom; 375 dest.setFormula(this.getFormula()); 376 dest._overlay = this._overlay; 377 dest._highlightMode = this._highlightMode;// SelectedMode.None; 378 // dest._highlightColor = this._highlightColor; 379 // dest.setHighlight(this.getHighlight()); 380 381 dest._visible = this._visible; 382 383 Frame parent = DisplayController.getCurrentFrame(); 384 if (parent == null) parent = this.getParentOrCurrentFrame(); 234 385 dest.setParent(parent); 235 386 … … 246 397 } 247 398 } 248 249 public void setGradientAngle(int gradientAngle) { 399 400 public void setDotType(DotType type) { 401 invalidateAll(); 402 _type = type; 403 invalidateAll(); 404 } 405 406 public DotType getDotType() { 407 return _type; 408 } 409 410 411 public void setFilled(boolean filled) 412 { 413 invalidateAll(); 414 _filled = filled; 415 invalidateAll(); 416 } 417 418 public boolean getFilled() { 419 return _filled; 420 } 421 422 /** 423 * Sets the angle of colour change for gradient colour fills. 424 * 425 * @param gradientAngle The new angle of colour change. 426 */ 427 public void setGradientAngle(double gradientAngle) 428 { 250 429 _gradientAngle = gradientAngle; 251 430 252 431 for (Line line : _lines) { 253 432 Item other = line.getOppositeEnd(this); 254 if (other.getGradientAngle() != gradientAngle) 255 other.setGradientAngle(gradientAngle); 433 if (other.getGradientAngle() != gradientAngle) other.setGradientAngle(gradientAngle); 256 434 } 257 435 … … 260 438 } 261 439 262 public int getGradientAngle() { 440 /** 441 * Gets the angle of colour change for gradient fills. 442 * 443 * @return The angle of colour change. 444 */ 445 public double getGradientAngle() { 263 446 return _gradientAngle; 264 447 } 265 448 266 public int getGravity() { 267 if (isVectorItem()) { 268 return 2; 269 } 449 /** 450 * Gets the gravity for this item. Gravity is the distance from the item at which mouse interaction 451 * applies to the item (like a small buffer zone so you don't need to click exactly on the item). 452 * 453 * @return The gravity distance for this item. 454 */ 455 public int getGravity() 456 { 457 if (isVectorItem()) return 2; 458 270 459 return UserSettings.Gravity.get(); 271 460 } 272 461 273 public static boolean showLineHighlight() { 462 /** 463 * Whether or not line highlights should be shown. 464 * TODO: Not really an item method is it? Goes straight to user settings. Refactor. cts16 465 * 466 * @return <code>true</code> if line highlighting should be shown, <code>false</code> otherwise. 467 */ 468 public static boolean shouldShowLineHighlight() 469 { 274 470 return UserSettings.LineHighlight.get(); 275 471 } 276 472 277 public enum HighlightMode { 278 None, Enclosed, Connected, Disconnect, Normal 279 } 280 281 public void setHighlightMode(HighlightMode mode) { 282 setHighlightMode(mode, DEFAULT_HIGHLIGHT); 283 } 284 285 protected Float _anchorLeft = null; 286 protected Float _anchorRight = null; 287 288 protected Float _anchorTop = null; 289 protected Float _anchorBottom = null; 290 291 protected HighlightMode _mode = HighlightMode.None; 292 293 private Point _offset = new Point(0, 0); 294 295 protected float _x; 296 protected float _y; 297 298 private int _id; 299 300 private Item _editTarget = this; 301 302 private String _creationDate = null; 303 304 private boolean _linkMark = true; 305 306 private boolean _actionMark = true; 307 308 private boolean _highlight = true; 309 310 // private int _maxWidth = -1; 311 312 private String _owner = null; 313 314 private String _link = null; 315 316 private boolean _linkHistory = true; 317 318 private StringBuffer _tag = new StringBuffer(); 319 320 private List<String> _actionCursorEnter = null; 321 322 private List<String> _actionCursorLeave = null; 323 324 private List<String> _actionEnterFrame = null; 325 326 private List<String> _actionLeaveFrame = null; 327 328 private PermissionPair _permissionPair = null; 329 330 private UserAppliedPermission _overlayPermission = null; 331 332 public void setOverlayPermission(UserAppliedPermission overlayPermission) { 473 /** 474 * Sets the highlight mode for this item. 475 * 476 * @param mode The new highlight mode. 477 */ 478 public void setHighlightMode(HighlightMode mode) 479 { 480 if (hasPermission(UserAppliedPermission.followLinks) || getEditTarget().hasPermission(UserAppliedPermission.followLinks)) { 481 if (_highlightMode != mode) { 482 _highlightMode = mode; 483 this.invalidateCommonTrait(ItemAppearence.HighlightModeChanged); 484 } 485 } 486 } 487 488 public void setOverlayPermission(UserAppliedPermission overlayPermission) 489 { 333 490 _overlayPermission = overlayPermission; 334 491 } 335 492 336 public void setPermission(PermissionPair permissionPair) { 493 public void setPermission(PermissionPair permissionPair) 494 { 337 495 _permissionPair = permissionPair; 338 496 } … … 354 512 } 355 513 356 // A fill color of null represents transparent357 private Color _colorFill = null;358 359 // A gradient color of null represents NO gradient360 private Color _colorGradient = null;361 362 // A fore color of null represents the default color363 private Color _color = null;364 365 protected Color _highlightColor = DEFAULT_HIGHLIGHT;366 367 private Color _colorBackground = null;368 369 private Color _colorBorder = null;370 371 private Color _colorTopShadow = null;372 373 private Color _colorBottomShadow = null;374 375 // the link\action circle376 private Polygon _circle = null;377 378 // the invalid link cross379 private Polygon _circleCross = null;380 381 private Frame _parent = null;382 private Frame _oldParent = null;383 384 protected int _highlightThickness = 2;385 386 protected int _vectorHighlightThickness = 1;387 388 // arrowhead parameters389 private float _arrowheadLength = 0;390 private double _arrowheadRatio = DEFAULT_ARROWHEAD_RATIO;391 private double _arrowheadNibPerc = DEFAULT_ARROWHEAD_NIB_PERC;392 393 private Polygon _arrowhead = null;394 395 // the list of lines that this point is part of.396 private List<Line> _lines = new ArrayList<Line>();397 398 private int[] _linePattern = null;399 400 private boolean _floating = false;401 402 // list of points constrained with this point403 private List<Constraint> _constraints = new ArrayList<Constraint>();404 405 private List<String> _actions = null;406 407 private List<String> _data = null;408 409 private String _formula = null;410 411 private String _link_frameset = null;412 413 private String _link_template = null;414 415 private String _fillPattern = null;416 417 private boolean _visible = true;418 419 private float _thickness = -1.0F;420 421 514 protected Item() { 422 515 _creationDate = Formatter.getLongDateTime(); … … 427 520 * 428 521 * @param action 429 * The action to add to this Item 430 */ 431 public void addAction(String action) { 432 if (action == null || action.equals("")) { 433 return; 434 } 522 * The name of the action to add to this Item. 523 */ 524 public void addAction(String action) 525 { 526 if (action == null || action.equals("")) return; 435 527 436 528 if (_actions == null) { 437 529 _actions = new LinkedList<String>(); 438 530 } 531 439 532 _actions.add(action); 533 440 534 if (_actions.size() == 1) { 441 _poly = null;535 invalidateBounds(); 442 536 invalidateCommonTrait(ItemAppearence.LinkChanged); 443 537 } 444 538 } 445 539 446 public void addAllConnected(Collection<Item> connected) {447 if (!connected.contains(this))448 540 public void addAllConnected(Collection<Item> connected) 541 { 542 if (!connected.contains(this)) connected.add(this); 449 543 450 544 for (Item item : getConnected()) { 451 if (!connected.contains(item)) 545 if (!connected.contains(item)) { 452 546 item.addAllConnected(connected); 547 } 453 548 } 454 549 } … … 460 555 * The Constraint to set this Dot as a member of. 461 556 */ 462 public void addConstraint(Constraint c) { 557 public void addConstraint(Constraint c) 558 { 463 559 // do not add duplicate constraint 464 560 if (_constraints.contains(c)) … … 474 570 * The Line that this Point is an end of. 475 571 */ 476 public void addLine(Line line) { 572 public void addLine(Line line) 573 { 477 574 if (_lines.contains(line)) { 478 575 return; … … 490 587 * less than, equal to, or greater than the specified object. 491 588 */ 492 public int compareTo(Item i) { 589 public int compareTo(Item i) 590 { 493 591 return getY() - i.getY(); 494 592 } … … 499 597 * the area and false otherwise. 500 598 * 501 * @param x 502 * The x coordinate to check 503 * @param y 504 * The y coordinate to check 599 * @param p 600 * The coordinate to check 505 601 * @return True if the Shape around this Item contains the given x,y pair, 506 602 * false otherwise. 507 603 */ 508 public boolean contains(int x, int y) { 509 return getPolygon().contains(x, y); 604 public boolean contains(Point p) 605 { 606 return getBounds().contains(p); 510 607 } 511 608 … … 518 615 public abstract Item copy(); 519 616 520 public void delete() { 617 public void delete() 618 { 521 619 _deleted = true; 522 620 } 523 621 524 622 @Override 525 public boolean equals(Object o) { 623 public boolean equals(Object o) 624 { 526 625 if (o == null) 527 626 return false; … … 542 641 * has been assigned. 543 642 */ 544 public List<String> getAction() { 643 public List<String> getAction() 644 { 545 645 return _actions; 546 646 } 547 647 548 public List<String> getData() { 648 public List<String> getData() 649 { 549 650 return _data; 550 651 } 551 652 552 public List<String> getActionCursorEnter() { 653 public List<String> getActionCursorEnter() 654 { 553 655 return _actionCursorEnter; 554 656 } 555 657 556 public List<String> getActionCursorLeave() { 658 public List<String> getActionCursorLeave() 659 { 557 660 return _actionCursorLeave; 558 661 } 559 662 560 public List<String> getActionEnterFrame() { 663 public List<String> getActionEnterFrame() 664 { 561 665 return _actionEnterFrame; 562 666 } 563 667 564 public List<String> getActionLeaveFrame() { 668 public List<String> getActionLeaveFrame() 669 { 565 670 return _actionLeaveFrame; 566 671 }; 567 672 568 public boolean getActionMark() { 673 public boolean getActionMark() 674 { 569 675 return _actionMark; 570 676 } … … 576 682 * @return 577 683 */ 578 public Collection<Item> getAllConnected() { 684 public Collection<Item> getAllConnected() 685 { 579 686 Collection<Item> list = new LinkedHashSet<Item>(); 580 687 addAllConnected(list); … … 582 689 } 583 690 584 public Area getArea() {691 /* public Area getArea() { 585 692 return new Area(getPolygon()); 586 } 587 588 public String getArrow() { 693 }*/ 694 695 public String getArrow() 696 { 589 697 if (!hasVisibleArrow()) 590 698 return null; … … 597 705 } 598 706 599 public Polygon getArrowhead() { 707 public PolygonBounds getArrowhead() 708 { 600 709 return _arrowhead; 601 710 } 602 711 603 public float getArrowheadLength() { 712 public float getArrowheadLength() 713 { 604 714 return _arrowheadLength; 605 715 } 606 716 607 public double getArrowheadRatio() { 717 public double getArrowheadRatio() 718 { 608 719 return _arrowheadRatio; 609 720 } 610 721 611 public double getArrowheadNibPerc() { 722 public double getArrowheadNibPerc() 723 { 612 724 return _arrowheadNibPerc; 613 725 } 614 726 615 public Color getBackgroundColor() { 616 return _colorBackground; 617 } 618 619 public Color getBorderColor() { 727 public Colour getBackgroundColor() 728 { 729 return _backgroundColour; 730 } 731 732 public Colour getBorderColor() 733 { 620 734 return _colorBorder; 621 735 } … … 628 742 * border. 629 743 */ 630 public Color getBottomShadowColor() { 744 public Colour getBottomShadowColor() 745 { 631 746 return _colorBottomShadow; 632 747 } … … 638 753 * returned by getArea(). 639 754 */ 640 public int getBoundsHeight() { 641 return getPolygon().getBounds().height; 755 public int getBoundsHeight() 756 { 757 return AxisAlignedBoxBounds.getEnclosing(getBounds()).getHeight(); 642 758 } 643 759 … … 648 764 * by getArea(). 649 765 */ 650 public int getBoundsWidth() { 651 return getPolygon().getBounds().width; 652 } 653 654 // TODO draw the link with a circle rather than a polygon!! 655 public Polygon getLinkPoly() { 656 if (_circle == null) { 657 int points = 16; 658 659 double radians = 0.0; 660 int xPoints[] = new int[points]; 661 int yPoints[] = new int[xPoints.length]; 662 663 for (int i = 0; i < xPoints.length; i++) { 664 // circle looks best if these values are not related to gravity 665 xPoints[i] = (int) (3.5 * Math.cos(radians)) + 6;// (2 * 666 // GRAVITY); 667 yPoints[i] = (int) (3.5 * Math.sin(radians)) + 3;// GRAVITY; 668 radians += (2.0 * Math.PI) / xPoints.length; 669 } 670 671 _circle = new Polygon(xPoints, yPoints, xPoints.length); 672 } 673 674 return _circle; 675 } 676 677 protected Polygon getCircleCross() { 678 679 if (_circleCross == null) { 680 _circleCross = new Polygon(); 681 682 Rectangle bounds = getLinkPoly().getBounds(); 683 int x1 = (int) bounds.getMinX(); 684 int x2 = (int) bounds.getMaxX(); 685 int y1 = (int) bounds.getMinY(); 686 int y2 = (int) bounds.getMaxY(); 687 int midX = ((x2 - x1) / 2) + x1; 688 int midY = ((y2 - y1) / 2) + y1; 689 690 _circleCross.addPoint(x1, y1); 691 _circleCross.addPoint(x2, y2); 692 _circleCross.addPoint(midX, midY); 693 _circleCross.addPoint(x1, y2); 694 _circleCross.addPoint(x2, y1); 695 _circleCross.addPoint(midX, midY); 696 } 697 698 return _circleCross; 699 } 700 701 public Color getColor() { 702 return _color; 703 } 704 705 public Collection<Item> getConnected() { 766 public int getBoundsWidth() 767 { 768 return AxisAlignedBoxBounds.getEnclosing(getBounds()).getWidth(); 769 } 770 771 // TODO: Remove magic constants. cts16 772 public EllipticalBounds getLinkBounds() 773 { 774 if (_linkCircle == null) { 775 _linkCircle = new EllipticalBounds(new Point(6, 3), 7); 776 } 777 778 return _linkCircle; 779 } 780 781 protected PolygonBounds getCircleCross() 782 { 783 784 if (_linkCircleCross == null) { 785 _linkCircleCross = new PolygonBounds(); 786 787 EllipticalBounds poly = getLinkBounds(); 788 int x1 = poly.getMinX(); 789 int x2 = poly.getMaxX(); 790 int y1 = poly.getMinY(); 791 int y2 = poly.getMaxY(); 792 int midX = (x2 + x1) / 2; 793 int midY = (y2 + y1) / 2; 794 795 _linkCircleCross.addPoint(new Point(x1, y1)); 796 _linkCircleCross.addPoint(new Point(x2, y2)); 797 _linkCircleCross.addPoint(new Point(midX, midY)); 798 _linkCircleCross.addPoint(new Point(x1, y2)); 799 _linkCircleCross.addPoint(new Point(x2, y1)); 800 _linkCircleCross.addPoint(new Point(midX, midY)); 801 } 802 803 return _linkCircleCross; 804 } 805 806 public Colour getColor() 807 { 808 return _foregroundColour; 809 } 810 811 public Collection<Item> getConnected() 812 { 706 813 List<Item> conn = new LinkedList<Item>(); 707 814 conn.add(this); … … 711 818 } 712 819 713 public String getConstraintIDs() { 820 public String getConstraintIDs() 821 { 714 822 if (_constraints == null || _constraints.size() == 0) 715 823 return null; … … 732 840 * @return a List of Constraints that this Dot is a member of. 733 841 */ 734 public List<Constraint> getConstraints() { 842 public List<Constraint> getConstraints() 843 { 735 844 return _constraints; 736 845 } 737 846 738 public String getTag() { 847 public String getTag() 848 { 739 849 if (_tag != null && _tag.length() > 0) 740 850 return _tag.toString(); … … 742 852 } 743 853 744 public String getDateCreated() { 854 public String getDateCreated() 855 { 745 856 return _creationDate; 746 857 } 747 858 748 public Color getFillColor() { 749 return _colorFill; 750 } 751 752 public String getFillPattern() { 859 public Colour getFillColor() 860 { 861 return _fillColour; 862 } 863 864 public String getFillPattern() 865 { 753 866 return _fillPattern; 754 867 } 755 868 756 public String getFirstAction() { 869 public String getFirstAction() 870 { 757 871 if (_actions == null || _actions.size() == 0) 758 872 return null; … … 760 874 } 761 875 762 public boolean getHighlight() { 876 /** 877 * Gets the value of <code>_highlight</code> for this item. 878 * TODO: Appears unused? cts16. 879 * 880 * @return The value of <code>_highlight</code>. 881 */ 882 public boolean getHighlight() 883 { 763 884 return _highlight; 764 885 } 765 886 766 public Color getHighlightColor() { 767 if (_highlightColor.equals(getPaintColor())) 768 return getAlternateHighlightColor(); 887 public Colour getHighlightColor() 888 { 889 if (_highlightColour.equals(getPaintColor())) return getAlternateHighlightColor(); 890 769 891 return getDefaultHighlightColor(); 770 892 } … … 774 896 * 775 897 * @return The ID of this Item. 776 */ 777 public int getID() { 898 * 899 * TODO: What does it mean to have a negative ID# (as used in TDFC)? cts16 900 */ 901 public int getID() 902 { 778 903 return _id; 779 904 } … … 784 909 * @return The list of Line IDs that this point is part of. 785 910 */ 786 public String getLineIDs() { 911 public String getLineIDs() 912 { 787 913 String lineID = null; 788 914 … … 797 923 } 798 924 799 public int[] getLinePattern() { 925 public int[] getLinePattern() 926 { 800 927 return _linePattern; 801 928 } … … 807 934 * Lines have been added. 808 935 */ 809 public List<Line> getLines() { 936 public List<Line> getLines() 937 { 810 938 return _lines; 811 939 } … … 818 946 * this Item does not link to anything. 819 947 */ 820 public String getLink() { 948 public String getLink() 949 { 821 950 return _link; 822 951 } 823 952 824 public String getFormula() { 953 public String getFormula() 954 { 825 955 return _formula; 826 956 } 827 957 828 public boolean hasFormula() { 958 public boolean hasFormula() 959 { 829 960 return _formula != null; 830 961 } 831 962 832 public boolean hasAttributeValuePair() { 963 public boolean hasAttributeValuePair() 964 { 833 965 return _attributeValuePair != null && _attributeValuePair.hasPair(); 834 966 } 835 967 836 public void setFormula(String formula) { 968 public void setFormula(String formula) 969 { 837 970 _formula = formula; 838 971 } 839 972 840 public boolean calculate(String formula) { 973 public boolean calculate(String formula) 974 { 841 975 setFormula(formula); 842 976 return true; 843 977 } 844 978 845 public String getLinkFrameset() { 979 public String getLinkFrameset() 980 { 846 981 return _link_frameset; 847 982 } 848 983 849 public boolean getLinkMark() { 984 public boolean getLinkMark() 985 { 850 986 return _linkMark; 851 987 } 852 988 853 public String getLinkTemplate() { 989 public String getLinkTemplate() 990 { 854 991 return _link_template; 855 992 } 856 993 857 // public int getMaxWidth() { 994 // public int getMaxWidth() 995 // { 858 996 // return _maxWidth; 859 997 // } 860 998 861 public Point getOffset() { 999 public Point getOffset() 1000 { 862 1001 return _offset; 863 1002 } 864 1003 865 public String getOwner() { 1004 public String getOwner() 1005 { 866 1006 return _owner; 867 1007 } 868 1008 869 public Color getPaintBackgroundColor() { 870 Color colorBackground = getBackgroundColor(); 1009 public Colour getPaintBackgroundColor() 1010 { 1011 Colour colorBackground = getBackgroundColor(); 871 1012 if (colorBackground == null) { 872 1013 if (getParent() != null && getParent().getBackgroundColor() != null) … … 884 1025 * @return The Color of this item (foreground) 885 1026 */ 886 public final Color getPaintColor() { 1027 public final Colour getPaintColor() 1028 { 887 1029 // If color is null then get the paint foregroundColor for the frame the 888 1030 // item is on which is a color adjusted to suit the background 889 Colo r color = getColor();1031 Colour color = getColor(); 890 1032 891 1033 if (color == null) { … … 893 1035 return getParent().getPaintForegroundColor(); 894 1036 895 Frame current = Display IO.getCurrentFrame();1037 Frame current = DisplayController.getCurrentFrame(); 896 1038 if (current == null) { 897 1039 return DEFAULT_FOREGROUND; … … 903 1045 } 904 1046 905 public final Color getPaintBorderColor() { 1047 public final Colour getPaintBorderColor() 1048 { 906 1049 // If color is null then get the paint foregroundColor for the frame the 907 1050 // item is on which is a color adjusted to suit the background 908 Colo r color = getBorderColor();1051 Colour color = getBorderColor(); 909 1052 910 1053 if (color == null) { … … 912 1055 return getParent().getPaintForegroundColor(); 913 1056 914 Frame current = Display IO.getCurrentFrame();1057 Frame current = DisplayController.getCurrentFrame(); 915 1058 if (current == null) { 916 1059 return DEFAULT_FOREGROUND; … … 922 1065 } 923 1066 924 protected Color getPaintHighlightColor() { 925 Color highlightColor = getDefaultHighlightColor(); 1067 protected Colour getPaintHighlightColor() 1068 { 1069 Colour highlightColor = getDefaultHighlightColor(); 926 1070 if (hasVisibleBorder()) { 927 1071 if (getPaintBorderColor().equals(highlightColor)) { … … 931 1075 highlightColor = getDefaultHighlightColor(); 932 1076 } 933 if (getParent() != null934 && getParent().getPaintBackgroundColor().equals(highlightColor))1077 1078 if (getParent() != null && getParent().getPaintBackgroundColor().equals(highlightColor)) { 935 1079 highlightColor = getParent().getPaintForegroundColor(); 1080 } 936 1081 937 1082 if (hasVisibleBorder()) { 938 if (highlightColor.equals(getBorderColor()) 939 && getThickness() == getHighlightThickness()) { 940 highlightColor = new Color(highlightColor.getRed(), 941 highlightColor.getGreen(), highlightColor.getBlue(), 942 150); 1083 if (highlightColor.equals(getBorderColor()) && getThickness() == getHighlightThickness()) { 1084 highlightColor = highlightColor.clone(); 1085 highlightColor.setAlpha(Colour.FromComponent255(150)); 943 1086 } 944 1087 } … … 947 1090 } 948 1091 949 static final int BRIGHTNESS = 185; 950 951 protected Color getDefaultHighlightColor() { 952 if (isVectorItem() 953 && !this.contains(FrameMouseActions.getX(), FrameMouseActions 954 .getY())) { 955 return new Color(255, BRIGHTNESS, BRIGHTNESS); 956 } 957 return _highlightColor; 958 } 959 960 protected Color getAlternateHighlightColor() { 961 if (isVectorItem() 962 && !this.contains(FrameMouseActions.getX(), FrameMouseActions 963 .getY())) { 964 return new Color(BRIGHTNESS, BRIGHTNESS, 255); 1092 protected Colour getDefaultHighlightColor() 1093 { 1094 if (isVectorItem() && !this.contains(EcosystemManager.getInputManager().getCursorPosition())) { 1095 return Colour.FromRGB255(255, BRIGHTNESS, BRIGHTNESS); 1096 } 1097 return _highlightColour; 1098 } 1099 1100 protected Colour getAlternateHighlightColor() 1101 { 1102 if (isVectorItem() && !this.contains(EcosystemManager.getInputManager().getCursorPosition())) { 1103 return Colour.FromRGB255(BRIGHTNESS, BRIGHTNESS, 255); 965 1104 } 966 1105 return ALTERNATE_HIGHLIGHT; 967 1106 } 968 1107 969 protected int getHighlightThickness() { 970 if (isVectorItem()) 971 return _vectorHighlightThickness; 1108 protected int getHighlightThickness() 1109 { 1110 if (isVectorItem()) return _vectorHighlightThickness; 1111 972 1112 return _highlightThickness; 973 1113 } 974 1114 975 public final Frame getParent() { 1115 public final Frame getParent() 1116 { 976 1117 return _parent; 977 1118 } 978 1119 979 public final Point getPosition() { 1120 /** Gets the position of this item. */ 1121 public final Point getPosition() 1122 { 980 1123 return new Point(getX(), getY()); 981 1124 } … … 987 1130 * @return The size of this Item. 988 1131 */ 989 public float getSize() { 990 return -1.0F; 1132 public float getSize() 1133 { 1134 return SIZE_NOT_APPLICABLE; 991 1135 } 992 1136 … … 997 1141 * @return The Color displayed on the top\left half of this Item's border. 998 1142 */ 999 public Color getTopShadowColor() { 1143 public Colour getTopShadowColor() 1144 { 1000 1145 return _colorTopShadow; 1001 1146 } 1002 1147 1003 public String getTypeAndID() { 1148 public String getTypeAndID() 1149 { 1004 1150 return "T " + getID(); 1005 1151 } 1006 1152 1007 public Integer getWidthToSave() { 1153 public Integer getWidthToSave() 1154 { 1008 1155 return getWidth(); 1009 1156 } 1010 1157 1011 public Integer getWidth() { 1158 public Integer getWidth() 1159 { 1012 1160 return null; 1013 1161 } 1014 1162 1015 public int getHeight() { 1163 public int getHeight() 1164 { 1016 1165 return 0; 1017 1166 } … … 1022 1171 * @return The X coordinate of this Item on the screen 1023 1172 */ 1024 public int getX() { 1173 public int getX() 1174 { 1025 1175 return Math.round(_x); 1026 1176 } … … 1031 1181 * @return The Y coordinate of this Item on the screen 1032 1182 */ 1033 public int getY() { 1183 public int getY() 1184 { 1034 1185 return Math.round(_y); 1035 1186 } 1036 1187 1037 public boolean hasVisibleArrow() { 1188 public boolean hasVisibleArrow() 1189 { 1038 1190 return isLineEnd() && getArrowheadRatio() != 0 && getArrowheadLength() != 0; 1039 1191 } … … 1046 1198 * @return True if the two Shapes overlap, False otherwise. 1047 1199 */ 1048 public boolean intersects(Polygon p) {1049 if (p == null)1050 1051 1052 Area a = new Area(p);1053 Area thisArea = this.getArea();1200 public boolean intersects(PolygonBounds otherBounds) 1201 { 1202 if (otherBounds == null) return false; 1203 1204 Bounds thisBounds = getBounds(); 1205 1054 1206 // Need to do this check for circles 1055 if (a.equals(thisArea)) 1056 return true; 1057 1058 a.intersect(thisArea); 1207 if (otherBounds.equals(thisBounds)) return true; 1208 1209 return otherBounds.intersects(thisBounds); 1059 1210 1060 1211 // Need to check the second equality so that we dont pick up circles 1061 1212 // inside other circles 1062 return !a.isEmpty() && !a.equals(new Area(p));1213 //return !a.isEmpty() && !a.equals(new Area(p)); 1063 1214 } 1064 1215 … … 1069 1220 * @return True if this Item is an annotation, False otherwise. 1070 1221 */ 1071 public boolean isAnnotation() { 1222 public boolean isAnnotation() 1223 { 1072 1224 return false; 1073 1225 } 1074 1226 1075 public boolean isFloating() { 1227 public boolean isFloating() 1228 { 1076 1229 return _floating; 1077 1230 } 1078 1231 1079 public boolean isFrameName() { 1232 public boolean isFrameName() 1233 { 1080 1234 if (this.getParent() == null || this.getParent().getNameItem() != this) 1081 1235 return false; … … 1083 1237 } 1084 1238 1085 public boolean isFrameTitle() { 1239 public boolean isFrameTitle() 1240 { 1086 1241 if (this.getParent() == null || this.getParent().getTitleItem() != this) 1087 1242 return false; … … 1095 1250 * otherwise. 1096 1251 */ 1097 public boolean isHighlighted() { 1252 public boolean isHighlighted() 1253 { 1098 1254 if (isFloating()) 1099 1255 return false; 1100 return _ mode != HighlightMode.None;1256 return _highlightMode != HighlightMode.None; 1101 1257 } 1102 1258 … … 1109 1265 * @return True if the given framename is proper, false otherwise. 1110 1266 */ 1111 public boolean isLinkValid() { 1267 public boolean isLinkValid() 1268 { 1112 1269 if (FrameIO.isPositiveInteger(getLink())) 1113 1270 return true; … … 1118 1275 } 1119 1276 1120 public boolean isNear(int x, int y) { 1121 1122 int xLeft = getPolygon().getBounds().x; 1123 int yTop = getPolygon().getBounds().y; 1124 1125 return (x > xLeft - NEAR_DISTANCE && y > yTop - NEAR_DISTANCE 1126 && x < xLeft + getBoundsWidth() + NEAR_DISTANCE && y < yTop 1127 + getBoundsHeight() + NEAR_DISTANCE); 1128 } 1129 1130 public boolean isOldTag() { 1277 /** 1278 * Checks if the given point is 'near' to the item. Here 'near' means within a certain distance 1279 * of the axis-aligned box bounding the item's polygon. 1280 * 1281 * @param x 1282 * The x-coordinate of the point to check. 1283 * 1284 * @param y 1285 * The y-coordinate of the point to check. 1286 * 1287 * @return 1288 * True if the given point is 'near' to the item, false otherwise. 1289 */ 1290 public boolean isNear(int x, int y) 1291 { 1292 AxisAlignedBoxBounds box = ItemUtils.expandRectangle(getBoundingBox(), NEAR_DISTANCE * 2); 1293 1294 return box.contains(x, y); 1295 } 1296 1297 public boolean isOldTag() 1298 { 1131 1299 if (this instanceof Text) 1132 1300 if (((Text) this).getTextList().get(0).toLowerCase().equals("@old")) … … 1153 1321 * The Graphics to draw this Item on. 1154 1322 */ 1155 public abstract void paint(Graphics2D g); 1156 1157 public void setTooltips(final List<String> tooltips) { 1158 if(tooltips == null || tooltips.size() == 0) _tooltip = new Tooltip(); 1159 else for(final String content: tooltips) _tooltip.addTooltip(content, this); 1160 } 1161 1162 public void setTooltip(final String tooltip) { 1323 public abstract void paint(); 1324 1325 public void setTooltips(final List<String> tooltips) 1326 { 1327 if (tooltips == null || tooltips.size() == 0) { 1328 _tooltip = new Tooltip(); 1329 } else { 1330 for (final String content: tooltips) _tooltip.addTooltip(content, this); 1331 } 1332 } 1333 1334 public void setTooltip(final String tooltip) 1335 { 1163 1336 if(tooltip != null && tooltip.trim().length() > 0) { 1164 1337 _tooltip.addTooltip(tooltip, this); … … 1166 1339 } 1167 1340 1168 public List<String> getTooltip() { 1341 public List<String> getTooltip() 1342 { 1169 1343 return _tooltip.asStringList(); 1170 1344 } 1171 1345 1172 public Collection<Text> getTooltipItems() { 1346 public Collection<Text> getTooltipItems() 1347 { 1173 1348 return _tooltip.getTooltips(); 1174 1349 } 1175 1350 1176 public void clearTooltips() { 1351 public void clearTooltips() 1352 { 1177 1353 final Frame frame = this.getParent(); 1178 if(_tooltip != null) 1354 if(_tooltip != null) { 1179 1355 for(final Text tooltip: _tooltip.getTooltips()) frame.removeItem(tooltip); 1180 } 1181 1182 public void paintTooltip(final Graphics2D g) { 1183 final Rectangle bounds = this.getPolygon().getBounds(); 1184 int x = bounds.x + bounds.width; 1185 if(x + _tooltip.getWidth() > FrameGraphics.getMaxFrameSize().width) { 1186 x -= x + _tooltip.getWidth() - FrameGraphics.getMaxFrameSize().width; 1187 } 1188 int y = bounds.y + bounds.height; 1189 if(y + _tooltip.getCollectiveHeight() > FrameGraphics.getMaxFrameSize().height) { 1190 y = bounds.y + bounds.height / 2 - _tooltip.getCollectiveHeight(); 1191 } 1356 } 1357 } 1358 1359 public void paintTooltip() 1360 { 1361 final Bounds bounds = AxisAlignedBoxBounds.getEnclosing(this.getBoundingBox()); 1362 Dimension frameSize = DisplayController.getFramePaintArea().getSize(); 1363 1364 int x = bounds.getMaxX(); 1365 1366 // If the tooltip goes off the right side of the window, move it left so it's completely on 1367 if(x + _tooltip.getWidth() > frameSize.getWidth()) { 1368 x = frameSize.getWidth() - _tooltip.getWidth(); 1369 } 1370 1371 int y = bounds.getMaxY(); 1372 1373 if(y + _tooltip.getCollectiveHeight() > frameSize.getHeight()) { 1374 y = (bounds.getMinY() + bounds.getMaxY()) / 2 - _tooltip.getCollectiveHeight(); 1375 } 1376 1192 1377 for(final Text tooltip : _tooltip.getTooltips()) { 1193 1378 this.getParent().addItem(tooltip); 1194 1379 tooltip.setPosition(x, y); 1195 tooltip.paint( g);1380 tooltip.paint(); 1196 1381 y += tooltip.getHeight(); 1197 1382 } 1198 1383 } 1199 1384 1200 public void paintFill( Graphics2D g) {1201 Colo r fillColor = getFillColor();1385 public void paintFill() { 1386 Colour fillColor = getFillColor(); 1202 1387 if (fillColor != null && getEnclosingDots() != null) { 1203 setFillPaint(g); 1204 g.fillPolygon(getEnclosedShape()); 1205 } 1206 } 1207 1208 protected void setFillPaint(Graphics2D g) { 1209 Color fillColor = getFillColor(); 1388 Fill fill = getFill(); 1389 EcosystemManager.getGraphicsManager().drawPolygon(getEnclosedShape(), null, null, 0.0f, fill, null, null); 1390 } 1391 } 1392 1393 protected Fill getFill() { 1394 Fill fill; 1395 Colour fillColour = getFillColor(); 1210 1396 if (isFloating()) { 1211 1397 // TODO experiment with adding alpha when picking up filled 1212 1398 // items... Slows things down quite alot!! 1213 fillColor = new Color(fillColor.getRed(), fillColor.getGreen(), 1214 fillColor.getBlue(), fillColor.getAlpha()); 1215 } 1216 g.setColor(fillColor); 1217 Color gradientColor = getGradientColor(); 1218 if (gradientColor != null) { 1399 // TODO: Does nothing as it stands... cts16 1400 fillColour = new Colour(fillColour.getRed(), fillColour.getGreen(), 1401 fillColour.getBlue(), fillColour.getAlpha()); 1402 } 1403 Colour gradientColor = getGradientColor(); 1404 PolygonBounds poly = getEnclosedShape(); 1405 if (gradientColor != null && poly != null) { 1219 1406 /* 1220 1407 * It is slow when painting gradients... modify so this is only done 1221 1408 * once unless it is resized... 1222 1409 */ 1223 Shape s = getEnclosedShape(); 1224 if (s != null) { 1225 Rectangle b = s.getBounds(); 1226 double rads = getGradientAngle() * Math.PI / 180; 1227 double cos = Math.cos(rads); 1228 double sin = Math.sin(rads); 1229 1230 GradientPaint gp = new GradientPaint((int) (b.x + b.width 1231 * (0.2 * cos + 0.5)), (int) (b.y + b.height 1232 * (0.2 * sin + 0.5)), fillColor, (int) (b.x + b.width 1233 * (-0.8 * cos + 0.5)), (int) (b.y + b.height 1234 * (-0.8 * sin + 0.5)), gradientColor); 1235 g.setPaint(gp); 1236 } 1237 } 1410 AxisAlignedBoxBounds b = AxisAlignedBoxBounds.getEnclosing(poly); 1411 double rads = getGradientAngle(); 1412 double cos = Math.cos(rads); 1413 double sin = Math.sin(rads); 1414 1415 Point fromPoint = new Point((int) (b.getMinX() + b.getWidth() * (0.2 * cos + 0.5)), (int) (b.getMinY() + b.getHeight() * (0.2 * sin + 0.5))); 1416 Point toPoint = new Point((int) (b.getMinX() + b.getWidth() * (-0.8 * cos + 0.5)), (int) (b.getMinY() + b.getHeight() * (-0.8 * sin + 0.5))); 1417 1418 fill = new GradientFill(fillColour, fromPoint, gradientColor, toPoint); 1419 } else { 1420 fill = new Fill(fillColour); 1421 } 1422 1423 return fill; 1238 1424 } 1239 1425 1240 1426 /** 1241 1427 * This method performs all the actions in an items list. If it contains a 1242 * link as well the link is used as the source frame for all ac itons.1428 * link as well the link is used as the source frame for all actions. 1243 1429 */ 1244 1430 public void performActions() { … … 1268 1454 // For actions like format they rely on this being set to the 1269 1455 // current frame incase the item being activated is on an overlay 1270 sourceFrame = Display IO.getCurrentFrame();1456 sourceFrame = DisplayController.getCurrentFrame(); 1271 1457 } 1272 1458 … … 1388 1574 MessageBay.displayMessage("See SIMPLE doc for [" 1389 1575 + ise.getStatement() + "] statement", ise.getStatement() 1390 + "1", Colo r.CYAN.darker(), true, null);1576 + "1", Colour.CYAN.darker(), true, null); 1391 1577 } catch (Exception e) { 1392 1578 MessageBay.linkedErrorMessage(e.getMessage()); … … 1394 1580 Simple.ProgramFinished(); 1395 1581 // Need to repaint any highlights etc 1396 FrameGraphics.requestRefresh(true);1582 DisplayController.requestRefresh(true); 1397 1583 } 1398 1584 … … 1414 1600 1415 1601 if (_parent == null) 1416 framesetName = Display IO.getCurrentFrame().getFramesetName();1602 framesetName = DisplayController.getCurrentFrame().getFramesetName(); 1417 1603 else 1418 1604 framesetName = _parent.getFramesetName(); … … 1428 1614 * The lines of code to associate with this Item 1429 1615 */ 1430 public void setActions(List<String> actions) { 1616 public void setActions(List<String> actions) 1617 { 1431 1618 if (actions == null || actions.size() == 0) { 1432 1619 invalidateCommonTrait(ItemAppearence.LinkChanged); 1433 1620 _actions = null; 1434 } else 1621 } else { 1435 1622 _actions = new LinkedList<String>(actions); 1436 1437 // Want to resize the highlight box for text items if actions have been1438 // added1439 _poly = null;1623 } 1624 1625 // Want to resize the highlight box for text items if actions have been added 1626 invalidateBounds(); 1440 1627 invalidateCommonTrait(ItemAppearence.LinkChanged); 1441 1628 } … … 1481 1668 } 1482 1669 1483 public void setActionMark(boolean val) {1484 if (!val)1485 1486 _poly = null;1670 public void setActionMark(boolean val) 1671 { 1672 if (!val) invalidateCommonTrait(ItemAppearence.LinkChanged); 1673 invalidateBounds(); 1487 1674 _actionMark = val; 1488 if (val) 1489 invalidateCommonTrait(ItemAppearence.LinkChanged); 1675 if (val) invalidateCommonTrait(ItemAppearence.LinkChanged); 1490 1676 } 1491 1677 … … 1519 1705 } 1520 1706 1521 public void setArrowhead(Polygon arrow) {1707 public void setArrowhead(PolygonBounds arrow) { 1522 1708 _arrowhead = arrow; 1523 1709 } … … 1538 1724 } 1539 1725 1540 public void setBackgroundColor(Colo r c) {1541 if (c != _ colorBackground) {1542 _ colorBackground= c;1726 public void setBackgroundColor(Colour c) { 1727 if (c != _backgroundColour) { 1728 _backgroundColour = c; 1543 1729 invalidateCommonTrait(ItemAppearence.BackgroundColorChanged); 1544 1730 } 1545 1731 } 1546 1732 1547 public void setBorderColor(Colo r c) {1733 public void setBorderColor(Colour c) { 1548 1734 if (c != _colorBorder) { 1549 1735 _colorBorder = c; … … 1560 1746 * Item's border. 1561 1747 */ 1562 public void setBottomShadowColor(Colo r bottom) {1748 public void setBottomShadowColor(Colour bottom) { 1563 1749 _colorBottomShadow = bottom; 1564 1750 } … … 1569 1755 * @param c 1570 1756 */ 1571 public void setColor(Colo r c) {1572 if (c != _ color) {1573 _ color = c;1757 public void setColor(Colour c) { 1758 if (c != _foregroundColour) { 1759 _foregroundColour = c; 1574 1760 invalidateCommonTrait(ItemAppearence.ForegroundColorChanged); 1575 1761 if (hasVector()) { 1576 1762 // TODO make this more efficient so it only repaints the items 1577 1763 // for this vector 1578 FrameKeyboardActions.Refresh();1764 StandardGestureActions.Refresh(); 1579 1765 } 1580 1766 } … … 1605 1791 } 1606 1792 1607 public void setFillColor(Colo r c) {1608 1609 _ colorFill= c;1793 public void setFillColor(Colour c) { 1794 1795 _fillColour = c; 1610 1796 1611 1797 for (Line line : _lines) { … … 1620 1806 } 1621 1807 1622 public void setGradientColor(Color c) { 1623 _colorGradient = c; 1808 public void setGradientColor(Colour c) 1809 { 1810 _gradientColour = c; 1624 1811 1625 1812 for (Line line : _lines) { … … 1633 1820 } 1634 1821 1635 public Colo r getGradientColor() {1636 return _ colorGradient;1822 public Colour getGradientColor() { 1823 return _gradientColour; 1637 1824 } 1638 1825 … … 1647 1834 } 1648 1835 1836 /** 1837 * Sets the value <code>_highlight</code> for this item. 1838 * TODO: Appears unused? cts16 1839 * 1840 * @param val The new value for <code>_highlight</code>. 1841 */ 1649 1842 public void setHighlight(boolean val) { 1650 1843 _highlight = val; … … 1693 1886 * The name of the Frame to link this item to. 1694 1887 */ 1695 public void setLink(String frameName) { 1696 if (frameName == null) { 1697 invalidateCommonTrait(ItemAppearence.LinkChanged); 1698 } 1699 1700 // If a link is being removed or set then need to reset poly so the 1888 public void setLink(String frameName) 1889 { 1890 if (frameName == null) invalidateCommonTrait(ItemAppearence.LinkChanged); 1891 1892 // If a link is being removed or set then need to reset _bounds so the 1701 1893 // highlighting is drawn with the correct width 1702 if (frameName == null || getLink() == null) 1703 _poly = null; 1704 1705 if (FrameIO.isValidLink(frameName)) 1894 if (frameName == null || getLink() == null) invalidateBounds(); 1895 1896 if (FrameIO.isValidLink(frameName)) { 1706 1897 _link = frameName; 1707 else1708 MessageBay.errorMessage("[" + frameName 1709 + "] is not a valid frame name");1898 } else { 1899 MessageBay.errorMessage("[" + frameName + "] is not a valid frame name"); 1900 } 1710 1901 // TODO make this throw exceptions etc... 1711 1902 … … 1721 1912 } 1722 1913 1723 public void setLinkFrameset(String frameset) { 1724 if (frameset == null || FrameIO.isValidFramesetName(frameset)) 1914 public void setLinkFrameset(String frameset) 1915 { 1916 if (frameset == null || FrameIO.isValidFramesetName(frameset)) { 1725 1917 _link_frameset = frameset; 1726 else1727 MessageBay.errorMessage("[" + frameset 1728 + "] is not a valid frameset name");1918 } else { 1919 MessageBay.errorMessage("[" + frameset + "] is not a valid frameset name"); 1920 } 1729 1921 // TODO make this throw exceptions etc... 1730 1922 } 1731 1923 1732 public void setLinkMark(boolean val) {1733 if (!val)1734 1735 _poly = null;1924 public void setLinkMark(boolean val) 1925 { 1926 if (!val) invalidateCommonTrait(ItemAppearence.LinkChanged); 1927 invalidateBounds(); 1736 1928 _linkMark = val; 1737 if (val) 1738 invalidateCommonTrait(ItemAppearence.LinkChanged);1739 } 1740 1741 public void setLinkTemplate(String template){1742 if (FrameIO.isValidLink(template)) 1929 if (val) invalidateCommonTrait(ItemAppearence.LinkChanged); 1930 } 1931 1932 public void setLinkTemplate(String template) 1933 { 1934 if (FrameIO.isValidLink(template)) { 1743 1935 _link_template = template; 1744 else1745 MessageBay.errorMessage("[" + template 1746 + "] is not a valid frame name");1936 } else { 1937 MessageBay.errorMessage("[" + template + "] is not a valid frame name"); 1938 } 1747 1939 // TODO make this throw exceptions etc... 1748 1940 } … … 1763 1955 1764 1956 public void setOffset(int x, int y) { 1765 _offset.set Location(x, y);1957 _offset.set(x, y); 1766 1958 } 1767 1959 1768 1960 public void setOffset(Point p) { 1769 _offset.set Location(p);1961 _offset.set(p); 1770 1962 } 1771 1963 … … 1805 1997 } 1806 1998 } 1807 if (_ colorFill!= null) {1999 if (_fillColour != null) { 1808 2000 invalidateFill(); // only invalidates if has fill 1809 2001 } … … 1814 2006 } 1815 2007 1816 1817 1818 1819 1820 2008 protected void anchorConstraints() 1821 2009 { … … 1830 2018 if (isAnchoredY()) { 1831 2019 // Make the 'other' item have the same anchor top/bottom values as this 1832 other._anchorTop = _anchorTop; 1833 other._anchorBottom = _anchorBottom; 2020 other._anchoring.setYAnchor(this._anchoring); 1834 2021 } 1835 2022 } else if (c.getType() == Constraint.VERTICAL) { 1836 2023 if (isAnchoredX()) { 1837 2024 // Make the 'other' item have the same anchor left/right values as this 1838 other._anchorLeft = _anchorLeft; 1839 other._anchorRight = _anchorRight; 2025 other._anchoring.setXAnchor(this._anchoring); 1840 2026 } 1841 2027 } else if (c.isDiagonal()) { … … 1855 2041 * The new Y coordinate 1856 2042 */ 1857 public void setPosition(float x, float y) { 2043 public void setPosition(float x, float y) 2044 { 1858 2045 float deltaX = x - _x; 1859 2046 float deltaY = y - _y; 1860 2047 1861 if (deltaX == 0 && deltaY == 0) 1862 return; 2048 if (deltaX == 0 && deltaY == 0) return; 1863 2049 1864 2050 invalidateCommonTraitForAll(ItemAppearence.PreMoved); … … 1868 2054 1869 2055 for (Item i : getEnclosures()) { 1870 i. updatePolygon();1871 } 1872 updatePolygon();2056 i.invalidateBounds(); 2057 } 2058 invalidateBounds(); 1873 2059 1874 2060 // update the position of any dots that are constrained by this one … … 1951 2137 1952 2138 for (Line line : getLines()) { 1953 line. updatePolygon();2139 line.invalidateBounds(); 1954 2140 } 1955 2141 … … 2007 2193 * their thickness set 2008 2194 */ 2009 public void setThickness(float thick, boolean setConnectedThickness) { 2010 if (thick == _thickness) 2011 return; 2195 public void setThickness(float thick, boolean setConnectedThickness) 2196 { 2197 if (thick == _thickness) return; 2198 2012 2199 boolean bigger = thick > _thickness; 2013 2200 … … 2015 2202 if (setConnectedThickness) { 2016 2203 // TODO is there a more efficient way of doing this? 2017 for (Item i : getConnected()) 2018 i.invalidateCommonTrait(ItemAppearence.Thickness); 2204 for (Item i : getConnected()) i.invalidateCommonTrait(ItemAppearence.Thickness); 2019 2205 } else { 2020 2206 invalidateCommonTrait(ItemAppearence.Thickness); … … 2028 2214 * etc... 2029 2215 */ 2030 for (Line line : getLines()) 2031 line.setThickness(thick, setConnectedThickness); 2032 2033 if (setConnectedThickness) 2034 updatePolygon(); 2216 for (Line line : getLines()) line.setThickness(thick, setConnectedThickness); 2217 2218 if (setConnectedThickness) invalidateBounds(); 2035 2219 2036 2220 if (bigger) { 2037 2221 if (setConnectedThickness) { 2038 for (Item i : getConnected()) 2039 i.invalidateCommonTrait(ItemAppearence.Thickness); 2222 for (Item i : getConnected()) i.invalidateCommonTrait(ItemAppearence.Thickness); 2040 2223 } else { 2041 2224 invalidateCommonTrait(ItemAppearence.Thickness); … … 2050 2233 * set). 2051 2234 */ 2052 public float getThickness() { 2235 public float getThickness() 2236 { 2053 2237 return _thickness; 2054 2238 } … … 2062 2246 * Item's border. 2063 2247 */ 2064 public void setTopShadowColor(Colo r top) {2248 public void setTopShadowColor(Colour top) { 2065 2249 _colorTopShadow = top; 2066 2250 } 2067 2251 2068 public void setWidth(Integer width) throws UnsupportedOperationException { 2069 throw new UnsupportedOperationException( 2070 "Item type does not support width attribute!"); 2071 } 2072 2073 public void setRightMargin(int i, boolean fixWidth) { 2252 public void setWidth(Integer width) throws UnsupportedOperationException 2253 { 2254 throw new UnsupportedOperationException("Item type does not support width attribute!"); 2255 } 2256 2257 public void setRightMargin(int i, boolean fixWidth) 2258 { 2074 2259 int newWidth = i - getX() - Item.MARGIN_LEFT; 2260 if (newWidth < 0) newWidth = 0; 2075 2261 if (!fixWidth) { 2076 2262 newWidth *= -1; … … 2113 2299 * means no change) 2114 2300 */ 2115 public int setHighlightColor() { 2116 return setHighlightColor(DEFAULT_HIGHLIGHT); 2117 } 2118 2119 public int setHighlightColor(Color c) { 2301 2302 /** 2303 * 2304 * 2305 * @return 2306 */ 2307 public void setHighlightColorToDefault() { 2308 setHighlightColor(DEFAULT_HIGHLIGHT); 2309 } 2310 2311 public void setHighlightColor(Colour c) { 2312 if (c == null) return; 2313 2120 2314 if (!this.isVisible() && this.hasVector()) { 2121 2315 for (Item i : this.getParentOrCurrentFrame().getVectorItems()) { … … 2128 2322 _highlightThickness = DEFAULT_HIGHLIGHT_THICKNESS; 2129 2323 2130 Colo r selColor = (c != null) ? c : DEFAULT_HIGHLIGHT;2131 if (_highlightColo r != c) {2132 _highlightColo r = selColor;2324 Colour selColor = (c != null) ? c : DEFAULT_HIGHLIGHT; 2325 if (_highlightColour != c) { 2326 _highlightColour = selColor; 2133 2327 this.invalidateCommonTrait(ItemAppearence.HighlightColorChanged); 2134 2328 } 2135 2136 return Item.UNCHANGED_CURSOR;2137 2329 2138 2330 } … … 2146 2338 } 2147 2339 2148 public abstract void updatePolygon(); 2340 /** Returns a Bounds which represents the area covered by the item (including its gravity). */ 2341 public abstract Bounds updateBounds(); 2149 2342 2150 2343 public void setHidden(boolean state) { … … 2172 2365 } 2173 2366 2174 public void setHighlightMode(HighlightMode mode, Color color) { 2175 setHighlightColor(color); 2176 if (hasPermission(UserAppliedPermission.followLinks) 2177 || getEditTarget().hasPermission(UserAppliedPermission.followLinks)) { 2178 if (_mode != mode) { 2179 _mode = mode; 2180 this.invalidateCommonTrait(ItemAppearence.HighlightModeChanged); 2181 } 2182 } 2367 /** 2368 * Sets the highlight mode and colour at the same time. 2369 * 2370 * @param mode The new highlight mode. 2371 * @param colour The new highlight colour. 2372 */ 2373 public void setHighlightModeAndColour(HighlightMode mode, Colour colour) 2374 { 2375 setHighlightMode(mode); 2376 setHighlightColor(colour); 2183 2377 } 2184 2378 2185 2379 public HighlightMode getHighlightMode() { 2186 return _ mode;2380 return _highlightMode; 2187 2381 } 2188 2382 … … 2191 2385 // only set the id if we've moved to a different frame, or if the frame already has an item with that id 2192 2386 if(!current.equals(_oldParent) || current.getItemWithID(getID()) != null) { 2193 int id = _id;2194 2387 setID(current.getNextItemID()); 2195 // System.out.println(this + " - Set ID to " + _id + " (was " + id + ")");2196 2388 } else { 2197 2389 // System.out.println(this + " - Kept old ID of " + _id); … … 2239 2431 // if the item is from an overlay the parent will NOT be null 2240 2432 if (getParent() == null) { 2241 return Display IO.getCurrentFrame();2433 return DisplayController.getCurrentFrame(); 2242 2434 } 2243 2435 return getParent(); … … 2275 2467 * the enclosed list. 2276 2468 */ 2277 public Polygon getEnclosedShape() {2278 if (_enclosure == null)2279 2280 2281 Polygon poly = new Polygon();2469 public PolygonBounds getEnclosedShape() 2470 { 2471 if (_enclosure == null) return null; 2472 2473 PolygonBounds poly = new PolygonBounds(); 2282 2474 for (Item d : _enclosure) { 2283 poly.addPoint( d.getX(), d.getY());2475 poly.addPoint(new Point(d.getX(), d.getY())); 2284 2476 } 2285 2477 … … 2332 2524 * the new color for the line 2333 2525 */ 2334 protected void lineColorChanged(Colo r c) {2526 protected void lineColorChanged(Colour c) { 2335 2527 for (Line l : getLines()) { 2336 2528 if (l.getColor() != c) … … 2345 2537 */ 2346 2538 public boolean offScreenTopOrLeft() { 2347 Rectangle itemRect = getArea().getBounds(); 2539 Bounds bounds = getBoundingBox(); 2540 2348 2541 // Check that the bottom right corner of this item is on the screen 2349 if (itemRect.x + itemRect.width >= 0 2350 && itemRect.y + itemRect.height >= 0) 2542 if (bounds.getMaxX() >= 0 && bounds.getMaxY() >= 0) { 2351 2543 return false; 2544 } 2545 2352 2546 // Check if all the items it is connected to are offscreen 2353 2547 for (Item i : getAllConnected()) { 2354 Rectangle iRect = i.getArea().getBounds();2548 bounds = i.getBoundingBox(); 2355 2549 // Check that the bottom right corner of this item is on the screen 2356 if ( iRect.x + iRect.width >= 0 && iRect.y + iRect.height>= 0) {2550 if (bounds.getMaxX() >= 0 && bounds.getMaxY() >= 0) { 2357 2551 return false; 2358 2552 } 2359 2553 } 2554 2360 2555 return true; 2361 2556 } … … 2374 2569 } 2375 2570 2376 public void setAction(String action) {2377 // Want to resize the highlight box for text items if actions are been2378 // added2571 public void setAction(String action) 2572 { 2573 // Want to resize the highlight box for text items if actions are been added 2379 2574 if (action == null || action.length() == 0) { 2380 2575 invalidateCommonTrait(ItemAppearence.LinkChanged); 2381 2576 } 2577 2382 2578 if (_actions == null || _actions.size() == 0) { 2383 _poly = null;2579 invalidateBounds(); 2384 2580 _actions = new LinkedList<String>(); 2385 2581 } else { 2386 2582 _actions.clear(); 2387 2583 } 2388 if (action != null && action.length() > 0) 2389 _actions.add(action); 2584 2585 if (action != null && action.length() > 0) _actions.add(action); 2586 2390 2587 invalidateCommonTrait(ItemAppearence.LinkChanged); 2391 2588 } … … 2395 2592 } 2396 2593 2397 protected RectanglegetLinkDrawArea() {2594 protected AxisAlignedBoxBounds getLinkDrawArea() { 2398 2595 return getLinkDrawArea(getX() - LEFT_MARGIN, getY() + getLinkYOffset()); 2399 2596 } … … 2410 2607 * @return The drawing area of the link at the given coordinates. 2411 2608 */ 2412 public RectanglegetLinkDrawArea(int x, int y) {2413 return new Rectangle(x + 2, y - 1, 8, 8);2609 public AxisAlignedBoxBounds getLinkDrawArea(int x, int y) { 2610 return new AxisAlignedBoxBounds(x + 2, y - 1, 8, 8); 2414 2611 } 2415 2612 … … 2419 2616 * @param g 2420 2617 */ 2421 protected void paintLink( Graphics2D g) {2422 paintLinkGraphic(g , getX() - LEFT_MARGIN, getY() + getLinkYOffset());2618 protected void paintLink() { 2619 paintLinkGraphic(getX() - LEFT_MARGIN, getY() + getLinkYOffset()); 2423 2620 } 2424 2621 … … 2438 2635 * centered) 2439 2636 */ 2440 public void paintLinkGraphic( Graphics2D g,int x, int y) {2441 2442 boolean hasLink = getLink() != null;2637 public void paintLinkGraphic(int x, int y) { 2638 2639 boolean hasLink = hasLink(); 2443 2640 boolean hasAction = hasAction(); 2444 2641 2445 2642 if (hasLink || hasAction) { 2446 g.setStroke(HIGHLIGHT_STROKE); 2643 GraphicsManager g = EcosystemManager.getGraphicsManager(); 2644 Fill fill = new Fill(); 2645 Colour colour = null; 2646 Point offset = new Point(x, y); 2647 2447 2648 if (hasLink && hasAction) { 2448 g.setColor(LINK_ACTION_COLOR);2649 colour = LINK_ACTION_COLOR; 2449 2650 } else if (hasLink) { 2450 g.setColor(LINK_COLOR);2651 colour = LINK_COLOR; 2451 2652 } else if (hasAction) { 2452 g.setColor(ACTION_COLOR);2653 colour = ACTION_COLOR; 2453 2654 } 2454 2455 AffineTransform at = new AffineTransform(); 2456 AffineTransform orig = g.getTransform(); 2457 at.translate(x, y); 2458 g.setTransform(at); 2459 2460 if (getLinkMark() && getLink() != null) { 2461 g.drawPolygon(getLinkPoly()); 2462 2655 fill.setColour(colour); 2656 2657 // Small circles look rubbish without AA. cts16 2658 g.setAntialiasing(true); 2659 2660 if (hasLink && getLinkMark()) { 2661 g.drawOval(offset, getLinkBounds().getDiameters(), 0.0f, null, colour, HIGHLIGHT_STROKE); 2662 2463 2663 // if the link is not valid, cross out the circle 2464 if (!isLinkValid()) 2465 g.drawPolygon(getCircleCross()); 2664 if (!isLinkValid()) { 2665 g.drawPolygon(getCircleCross(), offset, null, 0.0f, null, colour, HIGHLIGHT_STROKE); 2666 } 2466 2667 } 2467 2668 2468 if (getActionMark() && hasAction()) { 2469 g.drawPolygon(getLinkPoly()); 2470 g.fillPolygon(getLinkPoly()); 2669 if (hasAction && getActionMark()) { 2670 g.drawOval(offset, getLinkBounds().getDiameters(), 0.0f, fill, colour, HIGHLIGHT_STROKE); 2471 2671 2472 2672 // if the link is not valid, cross out the circle 2473 2673 if (!isLinkValid() && getLink() != null) { 2474 g.setColor(getParent().getPaintBackgroundColor()); 2475 g.drawPolygon(getCircleCross()); 2674 g.drawPolygon(getCircleCross(), offset, null, 0.0f, null, getParent().getPaintBackgroundColor(), HIGHLIGHT_STROKE); 2476 2675 } 2477 2676 } 2478 2479 // reset the graphics tranformation 2480 g.setTransform(orig); 2677 2678 g.setAntialiasing(false); 2481 2679 } 2482 2680 } … … 2539 2737 return null; 2540 2738 // assert (_parent!= null); 2541 Frame parent = Display IO.getCurrentFrame();2739 Frame parent = DisplayController.getCurrentFrame(); 2542 2740 assert (parent != null); 2543 2741 … … 2587 2785 while (!lines.isEmpty()) { 2588 2786 Line l = lines.remove(); 2589 // if we hav nt visited the line yet visit it2787 // if we haven't visited the line yet visit it 2590 2788 if (!visited.contains(l)) { 2591 2789 visited.add(l); 2592 2790 Item otherEnd = l.getOppositeEnd(this); 2593 // Add all the enexplored lines to our list2791 // Add all the unexplored lines to our list 2594 2792 while (!lines.isEmpty()) { 2595 2793 l = lines.remove(); … … 2613 2811 * is part of 2614 2812 */ 2615 public double getEnclosedArea() {2616 if (_enclosure == null)2617 return 0.0;2618 Rectangle2D box = getEnclosedShape().getBounds2D();2813 public double getEnclosedArea() 2814 { 2815 AxisAlignedBoxBounds box = getEnclosedBox(); 2816 if (box == null) return 0.0; 2619 2817 return box.getWidth() * box.getHeight(); 2620 2818 } 2621 2819 2622 public Rectangle getEnclosedRectangle() { 2623 if (_enclosure == null) 2624 return null; 2625 return getEnclosedShape().getBounds(); 2626 } 2627 2628 public int getEnclosureID() { 2820 /** 2821 * Gets the box encompassing all points that form an enclosure with this item. 2822 * 2823 * @return An axis-aligned box around all enclosure points. 2824 */ 2825 public AxisAlignedBoxBounds getEnclosedBox() 2826 { 2827 if (_enclosure == null) return null; 2828 2829 return AxisAlignedBoxBounds.getEnclosing(getEnclosedShape()); 2830 } 2831 2832 public int getEnclosureID() 2833 { 2629 2834 return _enclosure == null ? 0 : _enclosure.hashCode(); 2630 2835 } 2631 2836 2632 2837 /** 2633 * Returns the Shapethat surrounds this Item representing this Item's2838 * Returns the Bounds that surrounds this Item representing this Item's 2634 2839 * 'gravity'. 2635 2840 * 2636 * @return The Shape (rectangle)surrounding this Item, which represents2841 * @return The Bounds surrounding this Item, which represents 2637 2842 * this Items 'gravity'. 2638 2843 */ 2639 public final Polygon getPolygon() { 2640 if (_poly == null) 2641 updatePolygon(); 2642 2643 return new Polygon(_poly.xpoints, _poly.ypoints, _poly.npoints); 2844 public final Bounds getBounds() 2845 { 2846 if (_bounds == null) _bounds = updateBounds(); 2847 2848 // DEBUG 2849 if (_bounds == null) { 2850 //System.out.println("updateBounds failed!"); 2851 } 2852 2853 return _bounds; 2854 } 2855 2856 public final Bounds getOldBounds() 2857 { 2858 return _oldBounds; 2859 } 2860 2861 public final void invalidateBounds() 2862 { 2863 if (_bounds != null) _oldBounds = _bounds; 2864 _bounds = null; 2865 } 2866 2867 public final AxisAlignedBoxBounds getBoundingBox() 2868 { 2869 return AxisAlignedBoxBounds.getEnclosing(getBounds()); 2644 2870 } 2645 2871 … … 2651 2877 * @param ratio 2652 2878 */ 2653 public void translate(Point 2Dorigin, double ratio) {2879 public void translate(Point origin, double ratio) { 2654 2880 2655 2881 invalidateCommonTraitForAll(ItemAppearence.PreMoved); 2656 2882 2657 _x = (float) (origin. getX() + ratio * (_x - origin.getX()));2658 _y = (float) (origin. getY() + ratio * (_y - origin.getY()));2659 updatePolygon();2883 _x = (float) (origin.x + ratio * (_x - origin.x)); 2884 _y = (float) (origin.y + ratio * (_y - origin.y)); 2885 invalidateBounds(); 2660 2886 for (Line line : getLines()) 2661 line. updatePolygon();2887 line.invalidateBounds(); 2662 2888 2663 2889 invalidateCommonTraitForAll(ItemAppearence.PostMoved); … … 2698 2924 } 2699 2925 2700 Collection<XRayable> _enclosures = new HashSet<XRayable>();2701 2702 private boolean _deleted = false;2703 2704 private Overlay _overlay = null;2705 2706 protected AttributeValuePair _attributeValuePair = null;2707 2708 private Float _autoStamp = null;2709 2710 2926 /** 2711 2927 * For now there can only be one enclosure per item … … 2741 2957 * highlighting bounds 2742 2958 */ 2743 public Rectangle[]getDrawingArea() {2744 2745 return new Rectangle[] { ItemUtils.expandRectangle(getPolygon()2746 .getBounds(), (int) Math.ceil(Math.max(_highlightThickness,2747 getThickness()))) };2748 2959 public AxisAlignedBoxBounds getDrawingArea() { 2960 2961 return ItemUtils.expandRectangle( 2962 getBoundingBox(), 2963 (int) Math.ceil(Math.max(_highlightThickness, getThickness())) + 1 // + 1 to make sure 2964 ); 2749 2965 } 2750 2966 … … 2754 2970 * @return True if area intersects with this items drawing area. 2755 2971 */ 2756 public final boolean isInDrawingArea(Area area) { 2757 for (Rectangle r : getDrawingArea()) { 2758 if (area.intersects(r)) 2759 return true; 2760 } 2761 return false; 2762 } 2763 2764 /** 2765 * Completetly invalidates the item - so that it should be redrawed. Note: 2766 * This is handled internally, it should be reare to invoke this externally 2767 */ 2768 public final void invalidateAll() { 2972 public final boolean isInDrawingArea(AxisAlignedBoxBounds area) 2973 { 2974 AxisAlignedBoxBounds drawingArea = getDrawingArea(); 2975 2976 if (drawingArea == null) return false; 2977 2978 return drawingArea.intersects(area); 2979 } 2980 2981 /** 2982 * Completely invalidates the item - so that it should be redrawn. Note: 2983 * This is handled internally, it should be rare to invoke this externally 2984 */ 2985 public final void invalidateAll() 2986 { 2769 2987 invalidate(getDrawingArea()); 2770 2988 } … … 2776 2994 * @param damagedAreas 2777 2995 */ 2778 protected final void invalidate( Rectangle[] damagedAreas) {2779 for (Rectangle r : damagedAreas)2780 invalidate(r);2996 protected final void invalidate(Bounds[] damagedAreas) 2997 { 2998 if (damagedAreas != null) for (Bounds b : damagedAreas) invalidate(b); 2781 2999 } 2782 3000 … … 2787 3005 * @param damagedAreas 2788 3006 */ 2789 protected final void invalidate(Rectangle damagedArea) { 2790 FrameGraphics.invalidateItem(this, damagedArea); 3007 protected final void invalidate(Bounds damagedArea) 3008 { 3009 if (damagedArea != null) DisplayController.invalidateItem(this, damagedArea); 2791 3010 } 2792 3011 … … 2796 3015 * @param trait 2797 3016 */ 2798 public final void invalidateCommonTrait(ItemAppearence trait) { 3017 public final void invalidateCommonTrait(ItemAppearence trait) 3018 { 2799 3019 invalidate(getDamagedArea(trait)); 2800 3020 2801 if (_colorFill != null 2802 && (trait == ItemAppearence.Added || trait == ItemAppearence.Removed)) { 3021 if (_fillColour != null && (trait == ItemAppearence.Added || trait == ItemAppearence.Removed)) { 2803 3022 invalidateFill(); 2804 3023 } … … 2808 3027 * Invalidates fill if has one, even if no color is set. 2809 3028 */ 2810 public void invalidateFill() { 3029 public void invalidateFill() 3030 { 2811 3031 if (isLineEnd() && _enclosure != null) { 2812 invalidate(getEnclosed Shape().getBounds());3032 invalidate(getEnclosedBox()); 2813 3033 } 2814 3034 } … … 2826 3046 * @return The damaged area according to the visual trait that has changed. 2827 3047 */ 2828 protected Rectangle[] getDamagedArea(ItemAppearence trait) {2829 3048 protected AxisAlignedBoxBounds getDamagedArea(ItemAppearence trait) 3049 { 2830 3050 if (trait == ItemAppearence.LinkChanged) 2831 return new Rectangle[] { getLinkDrawArea() }; // Invalidate area 2832 // where link is 2833 // drawn 3051 return getLinkDrawArea(); // Invalidate area where link is drawn 2834 3052 2835 3053 return getDrawingArea(); 2836 2837 3054 } 2838 3055 … … 2864 3081 } 2865 3082 2866 public void setAnchorLeft( Float anchor) {2867 this._anchorLeft = anchor;2868 this._anchor Right = null;3083 public void setAnchorLeft(Integer anchor) 3084 { 3085 this._anchoring.setLeftAnchor(anchor); 2869 3086 if (anchor != null) { 2870 3087 anchorConstraints(); … … 2873 3090 } 2874 3091 2875 public void setAnchorRight( Float anchor) {2876 this._anchorRight = anchor;2877 this._anchor Left = null;3092 public void setAnchorRight(Integer anchor) 3093 { 3094 this._anchoring.setRightAnchor(anchor); 2878 3095 if (anchor != null) { 2879 3096 anchorConstraints(); 2880 setX(FrameGraphics.getMaxFrameSize().width - anchor 2881 - getBoundsWidth()); 2882 } 2883 } 2884 2885 public void setAnchorTop(Float anchor) { 2886 this._anchorTop = anchor; 2887 this._anchorBottom = null; 3097 setX(DisplayController.getFramePaintArea().getMaxX() - anchor - getBoundsWidth()); 3098 } 3099 } 3100 3101 public void setAnchorTop(Integer anchor) 3102 { 3103 this._anchoring.setTopAnchor(anchor); 2888 3104 if (anchor != null) { 2889 3105 anchorConstraints(); … … 2893 3109 2894 3110 2895 public void setAnchorBottom( Float anchor) {2896 this._anchorBottom = anchor;2897 this._anchor Top = null;3111 public void setAnchorBottom(Integer anchor) 3112 { 3113 this._anchoring.setBottomAnchor(anchor); 2898 3114 if (anchor != null) { 2899 3115 anchorConstraints(); 2900 setY(FrameGraphics.getMaxFrameSize().height - anchor); 2901 } 2902 } 2903 2904 2905 public boolean isAnchored() { 2906 return ((_anchorLeft != null) || (_anchorRight != null) 2907 || (_anchorTop != null) || (_anchorBottom != null)); 3116 setY(DisplayController.getFramePaintArea().getMaxY() - anchor); 3117 } 3118 } 3119 3120 public boolean isAnchored() 3121 { 3122 return _anchoring.isAnchored(); 2908 3123 } 2909 3124 2910 3125 public boolean isAnchoredX() { 2911 return ((_anchorLeft != null) || (_anchorRight != null));3126 return _anchoring.isXAnchored(); 2912 3127 } 2913 3128 2914 3129 public boolean isAnchoredY() { 2915 return ((_anchorTop != null) || (_anchorBottom != null));2916 } 2917 2918 public FloatgetAnchorLeft() {2919 return _anchor Left;2920 } 2921 2922 public FloatgetAnchorRight() {2923 return _anchor Right;2924 } 2925 2926 public FloatgetAnchorTop() {2927 return _anchor Top;2928 } 2929 2930 public FloatgetAnchorBottom() {2931 return _anchor Bottom;3130 return _anchoring.isYAnchored(); 3131 } 3132 3133 public Integer getAnchorLeft() { 3134 return _anchoring.getLeftAnchor(); 3135 } 3136 3137 public Integer getAnchorRight() { 3138 return _anchoring.getRightAnchor(); 3139 } 3140 3141 public Integer getAnchorTop() { 3142 return _anchoring.getTopAnchor(); 3143 } 3144 3145 public Integer getAnchorBottom() { 3146 return _anchoring.getBottomAnchor(); 2932 3147 } 2933 3148 … … 3024 3239 // Invalidate them again!! 3025 3240 for (Item i : this.getAllConnected()) { 3026 i. updatePolygon();3241 i.invalidateBounds(); 3027 3242 i.invalidateAll(); 3028 3243 } 3029 3244 } 3030 3245 3031 3032 3246 protected void anchorConnected(AnchorEdgeType anchorEdgeType, Float delta) { 3033 3247 … … 3087 3301 // Invalidate them again!! 3088 3302 for (Item i : this.getAllConnected()) { 3089 i. updatePolygon();3303 i.invalidateBounds(); 3090 3304 i.invalidateAll(); 3091 3305 } … … 3123 3337 // DONT PUT SIZE IN HERE CAUSE IT STUFFS UP CIRCLES 3124 3338 3125 updatePolygon();3339 invalidateBounds(); 3126 3340 } 3127 3341 … … 3168 3382 return _autoStamp != null && _autoStamp >= 0.0; 3169 3383 } 3170 3171 public void setDotType(DotType type) {3172 invalidateAll();3173 _type = type;3174 invalidateAll();3175 }3176 3177 public DotType getDotType() {3178 return _type;3179 }3180 3181 public void setFilled(boolean filled) {3182 invalidateAll();3183 _filled = filled;3184 invalidateAll();3185 }3186 3187 public boolean getFilled() {3188 return _filled;3189 }3190 3191 private Item _magnetizedItemLeft = null;3192 private Item _magnetizedItemRight = null;3193 private Item _magnetizedItemTop = null;3194 private Item _magnetizedItemBottom = null;3195 3384 3196 3385 public int getMagnetizedItemLeft() { … … 3245 3434 setMagnetizedItemBottom(this.getParent().getItemWithID(id)); 3246 3435 } 3436 3437 /** 3438 * Replaces the given dot item with a text item displaying the given character. 3439 * 3440 * @param dot 3441 * The Dot item to replace. 3442 * 3443 * @param ch 3444 * The character to display as the text for the created Text item. 3445 * 3446 * @return 3447 * The created Text item. 3448 */ 3449 public static Text replaceDot(Item dot, char ch) { 3450 // TODO: Should this make sure 'dot' is actually a Dot and not some other item? cts16 3451 Text text = Text.createText(ch); 3452 Item.DuplicateItem(dot, text); 3453 FrameUtils.setLastEdited(text); 3454 3455 // Copy the lines list so it can be modified 3456 List<Line> lines = new LinkedList<Line>(dot.getLines()); 3457 for (Line line : lines) 3458 line.replaceLineEnd(dot, text); 3459 Frame current = dot.getParentOrCurrentFrame(); 3460 current.removeItem(dot); 3461 ItemUtils.EnclosedCheck(current.getItems()); 3462 return text; 3463 // TODO: Should this add the newly-created Text item to the frame? cts16 3464 } 3465 3466 /** 3467 * Replaces the given text item with a dot 3468 */ 3469 public static Item replaceText(Item text) { 3470 Item dot = new Dot(text.getX(), text.getY(), text.getID()); 3471 Item.DuplicateItem(text, dot); 3472 3473 List<Line> lines = new LinkedList<Line>(); 3474 lines.addAll(text.getLines()); 3475 if (lines.size() > 0) 3476 dot.setColor(lines.get(0).getColor()); 3477 for (Line line : lines) { 3478 line.replaceLineEnd(text, dot); 3479 } 3480 text.delete(); 3481 Frame current = text.getParentOrCurrentFrame(); 3482 current.addItem(dot); 3483 DisplayController.setCursor(Item.DEFAULT_CURSOR); 3484 ItemUtils.EnclosedCheck(current.getItems()); 3485 return dot; 3486 } 3247 3487 } -
trunk/src/org/expeditee/items/ItemAppearence.java
r919 r1102 20 20 21 21 /** 22 * Used for inv laidation on items.22 * Used for invalidation on items. 23 23 * @author Brook Novak 24 24 */ … … 37 37 Removed, 38 38 ToggleDashed, 39 Thickness, GradientColor, BorderColorChanged 39 Thickness, 40 GradientColor, 41 BorderColorChanged 40 42 } -
trunk/src/org/expeditee/items/ItemUtils.java
r922 r1102 19 19 package org.expeditee.items; 20 20 21 import java.awt.Color;22 import java.awt.Rectangle;23 import java.awt.image.ImageObserver;24 21 import java.io.File; 25 22 import java.io.UnsupportedEncodingException; … … 34 31 import java.util.Map; 35 32 36 import org.expeditee.gui.DisplayIO; 33 import org.expeditee.core.Colour; 34 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 35 import org.expeditee.gui.DisplayController; 36 import org.expeditee.gui.DisplayController.TwinFramesSide; 37 37 import org.expeditee.gui.Frame; 38 38 import org.expeditee.gui.FrameUtils; … … 40 40 import org.expeditee.gui.Vector; 41 41 import org.expeditee.items.Item.HighlightMode; 42 import org.expeditee.items.widgets. InteractiveWidget;42 import org.expeditee.items.widgets.Widget; 43 43 import org.expeditee.items.widgets.InteractiveWidgetInitialisationFailedException; 44 44 import org.expeditee.items.widgets.InteractiveWidgetNotAvailableException; … … 360 360 * 361 361 * @param source 362 * The Text file containing the Picture info mation362 * The Text file containing the Picture information 363 363 * @return The Picture object representing the file, or Null if the file is 364 364 * not found. 365 365 */ 366 public static Picture CreatePicture(Text source, ImageObserver observer,boolean tryRemote) {366 public static Picture CreatePicture(Text source, boolean tryRemote) { 367 367 String text = source.getText(); 368 368 String path = ""; … … 424 424 // call CreatePicture again, but with tryRemote set to false so we won't get into an infinite loop 425 425 // if something goes wrong with finding the downloaded image 426 return CreatePicture(source, observer,false);426 return CreatePicture(source, false); 427 427 } 428 428 return null; … … 434 434 435 435 try { 436 Picture pic = new Picture(source, fileName, path, size , observer);436 Picture pic = new Picture(source, fileName, path, size); 437 437 438 438 return pic; … … 444 444 } 445 445 446 public static Picture CreatePicture(Text source , ImageObserver observer) {447 return CreatePicture(source, observer,true);446 public static Picture CreatePicture(Text source) { 447 return CreatePicture(source, true); 448 448 } 449 449 … … 483 483 484 484 // Widgets are super special 485 List< InteractiveWidget> widgets = new ArrayList<InteractiveWidget>();485 List<Widget> widgets = new ArrayList<Widget>(); 486 486 487 487 for (Item i : toCopy) { … … 596 596 Item start = lineEndMap.get(c.getStart()); 597 597 Item end = lineEndMap.get(c.getEnd()); 598 int id = Display IO.getCurrentFrame().getNextItemID();598 int id = DisplayController.getCurrentFrame().getNextItemID(); 599 599 if (start != null && end != null) { 600 600 new Constraint(start, end, id, c.getType()); … … 603 603 604 604 // BROOK 605 for ( InteractiveWidget iw : widgets) {605 for (Widget iw : widgets) { 606 606 try { 607 607 608 InteractiveWidget icopy = iw.copy();608 Widget icopy = iw.copy(); 609 609 copies.addAll(icopy.getItems()); 610 610 … … 680 680 Item copy = origEnd.copy(); 681 681 origEnd.setHighlightMode(HighlightMode.None); 682 origEnd.setHighlightColorToDefault(); 682 683 copy.removeAllLines(); 683 684 copy.removeAllConstraints(); … … 688 689 689 690 // create a new line 690 Frame currentFrame = Display IO.getCurrentFrame();691 Frame currentFrame = DisplayController.getCurrentFrame(); 691 692 Line line = new Line(origEnd, copy, currentFrame.getNextItemID()); 692 693 // if the previous line was constrained then make the new line … … 694 695 // TODO add later a diagonal constraint if getLines() == 3 or 4 695 696 Collection<Constraint> constraints = origEnd.getConstraints(); 696 if (constrain && constraints.size() > 0 697 && origEnd.getLines().size() == 2) { 697 if (constrain && constraints.size() > 0 && origEnd.getLines().size() == 2) { 698 698 Integer type = null; 699 699 for (Constraint c : constraints) { … … 710 710 } 711 711 if (type != null) { 712 new Constraint(origEnd, copy, currentFrame.getNextItemID(), 713 type); 712 new Constraint(origEnd, copy, currentFrame.getNextItemID(), type); 714 713 } 715 714 } … … 726 725 727 726 public static void New() { 728 EnclosedCheck(Display IO.getCurrentFrame().getItems());727 EnclosedCheck(DisplayController.getCurrentFrame().getItems()); 729 728 } 730 729 731 730 public static void Old() { 732 OldEnclosedCheck(Display IO.getCurrentFrame().getItems());731 OldEnclosedCheck(DisplayController.getCurrentFrame().getItems()); 733 732 } 734 733 … … 902 901 */ 903 902 public static boolean isVisible(Item i) { 904 if (Display IO.isTwinFramesOn()) {905 if (!isVisible(Display IO.getFrames()[0], i)) {906 return isVisible(Display IO.getFrames()[1], i);903 if (DisplayController.isTwinFramesOn()) { 904 if (!isVisible(DisplayController.getFrameOnSide(TwinFramesSide.LEFT), i)) { 905 return isVisible(DisplayController.getFrameOnSide(TwinFramesSide.RIGHT), i); 907 906 } else { 908 907 return true; 909 908 } 910 909 } else { 911 return isVisible(Display IO.getCurrentFrame(), i);910 return isVisible(DisplayController.getCurrentFrame(), i); 912 911 } 913 912 } … … 923 922 * @return True if visible/free from given frame. 924 923 */ 925 public static boolean isVisible(Frame fromFrame, Item i) {926 if (fromFrame == null)927 924 public static boolean isVisible(Frame fromFrame, Item i) 925 { 926 if (fromFrame == null) return false; 928 927 929 928 Frame parent = i.getParent(); 930 929 931 if (parent == fromFrame) 930 if (parent == fromFrame) { 932 931 return true; 932 } else if (parent == null) { 933 return FreeItems.getInstance().contains(i) || FreeItems.getCursor().contains(i); 934 } 933 935 934 else if (parent == null)935 return FreeItems.getInstance().contains(i)936 || FreeItems.getCursor().contains(i);937 938 936 return fromFrame.getAllItems().contains(i) && i.isVisible(); 939 937 } 940 938 941 public static Rectangle expandRectangle(Rectangle r, int n) { 942 return new Rectangle(r.x - (n >> 1), r.y - (n >> 1), r.width + n, 943 r.height + n); 939 public static AxisAlignedBoxBounds expandRectangle(AxisAlignedBoxBounds r, int n) 940 { 941 if (r == null) return null; 942 943 return new AxisAlignedBoxBounds(r.getMinX() - (n >> 1), r.getMinY() - (n >> 1), r.getWidth() + n, r.getHeight() + n); 944 944 } 945 945 … … 973 973 int originX = v.Origin.x; 974 974 int originY = v.Origin.y; 975 Colo r defaultForeground = v.Foreground;976 Colo r defaultBackground = v.Background;975 Colour defaultForeground = v.Foreground; 976 Colour defaultBackground = v.Background; 977 977 UserAppliedPermission permission = v.permission; 978 978 // TODO should this be checking if the frame has the … … 1014 1014 * @return List of (unique)widgets in items. Never null. 1015 1015 */ 1016 public static List< InteractiveWidget> extractWidgets(List<Item> items) {1016 public static List<Widget> extractWidgets(List<Item> items) { 1017 1017 assert (items != null); 1018 1018 1019 List< InteractiveWidget> iWidgets = new LinkedList<InteractiveWidget>();1019 List<Widget> iWidgets = new LinkedList<Widget>(); 1020 1020 1021 1021 for (Item i : items) { … … 1053 1053 * @param frame 1054 1054 */ 1055 public static void Justify(Frame frame) { 1055 public static void Justify(Frame frame) 1056 { 1057 if (frame == null) return; 1056 1058 EnclosedCheck(frame.getItems()); 1057 1059 Justify(frame.getItems()); -
trunk/src/org/expeditee/items/JSItem.java
r1080 r1102 19 19 package org.expeditee.items; 20 20 21 import java.awt.Graphics2D;22 import java.awt.Polygon;23 21 import java.util.LinkedList; 24 22 import java.util.List; … … 29 27 import javax.script.ScriptException; 30 28 31 import org.expeditee.gui.DisplayIO; 32 import org.expeditee.items.widgets.InteractiveWidget; 29 import org.expeditee.Util; 30 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 31 import org.expeditee.gui.DisplayController; 33 32 34 33 public class JSItem extends XRayable implements JSThreadable { … … 64 63 65 64 private static Text getSauce(int width, int height) { 66 Text source = new Text(Display IO.getCurrentFrame().getNextItemID(), "@js: " + width + " " + height);67 source.setParent(Display IO.getCurrentFrame());65 Text source = new Text(DisplayController.getCurrentFrame().getNextItemID(), "@js: " + width + " " + height); 66 source.setParent(DisplayController.getCurrentFrame()); 68 67 return source; 69 68 } … … 115 114 116 115 @Override 117 public void paint(Graphics2D g) { 118 try { 119 this.invocable.invokeFunction("paint", (Object)g); 116 public void paint(/*Graphics2D g*/) { 117 try { 118 // Not sure of the consequences of changing this? cts16 119 //this.invocable.invokeFunction("paint", (Object)g); 120 this.invocable.invokeFunction("paint"); 120 121 } catch (Exception e) { 121 122 e.printStackTrace(); … … 130 131 131 132 @Override 132 public void updatePolygon() { 133 _poly = new Polygon(); 134 _poly.addPoint(getX(), getY()); 135 _poly.addPoint(getX() + _width, getY()); 136 _poly.addPoint(getX() + _width, getY() + _height); 137 _poly.addPoint(getX(), getY() + _height); 133 public AxisAlignedBoxBounds updateBounds() 134 { 135 return new AxisAlignedBoxBounds(getX(), getY(), _width, _height); 138 136 } 139 137 … … 158 156 return; 159 157 } 160 String[] args = InteractiveWidget.parseArgs(text.substring(index));158 String[] args = Util.parseArgs(text.substring(index)); 161 159 try { 162 160 this.scriptEngine.eval("load = " + this.load); … … 189 187 newText.append(_width).append(" ").append(_height); 190 188 191 String stateArgs = InteractiveWidget.formatArgs(saveArgs());189 String stateArgs = Util.formatArgs(saveArgs()); 192 190 if (stateArgs != null) { 193 191 newText.append(':'); … … 239 237 } 240 238 239 @Override 240 public float getSize() { 241 // TODO Auto-generated method stub 242 return 0; 243 } 244 241 245 } -
trunk/src/org/expeditee/items/Line.java
r919 r1102 19 19 package org.expeditee.items; 20 20 21 import java.awt.BasicStroke;22 import java.awt.Color;23 import java.awt.Graphics2D;24 import java.awt.Point;25 import java.awt.Polygon;26 import java.awt.Rectangle;27 import java.awt.RenderingHints;28 import java.awt.Shape;29 import java.awt.Stroke;30 import java.awt.geom.AffineTransform;31 import java.awt.geom.Point2D;32 21 import java.util.ArrayList; 33 22 import java.util.Collection; … … 37 26 import java.util.List; 38 27 39 import org.expeditee.gui.DisplayIO; 28 import org.expeditee.core.Colour; 29 import org.expeditee.core.Dimension; 30 import org.expeditee.core.Fill; 31 import org.expeditee.core.Point; 32 import org.expeditee.core.Stroke; 33 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 34 import org.expeditee.core.bounds.CombinationBoxBounds; 35 import org.expeditee.core.bounds.PolygonBounds; 36 import org.expeditee.gio.EcosystemManager; 37 import org.expeditee.gio.GraphicsManager; 38 import org.expeditee.gui.DisplayController; 40 39 import org.expeditee.gui.Frame; 41 40 import org.expeditee.gui.FrameGraphics; … … 59 58 60 59 61 public static Polygon createArrowheadPolygon(double x0, double y0, float arrowLength0, double arrowRatio0, double arrowNibPerc0)60 public static PolygonBounds createArrowheadPolygon(double x0, double y0, float arrowLength0, double arrowRatio0, double arrowNibPerc0) 62 61 { 63 64 Polygon arrowhead = new Polygon(); 62 PolygonBounds arrowhead = new PolygonBounds(); 65 63 66 64 int ix0 = (int)Math.round(x0); … … 73 71 int flange_iy_left = (int) Math.round((y0 - flange_y_width)); 74 72 int flange_iy_right = (int) Math.round((y0 + flange_y_width)); 75 76 77 arrowhead.addPoint(ix0, iy0); 78 arrowhead.addPoint(flange_ix_project, flange_iy_left); 79 80 arrowhead.addPoint(ix_nib, iy0); 81 82 arrowhead.addPoint(flange_ix_project, flange_iy_right); 73 74 arrowhead.addPoint(new Point(ix0, iy0)); 75 arrowhead.addPoint(new Point(flange_ix_project, flange_iy_left)); 76 arrowhead.addPoint(new Point(ix_nib, iy0)); 77 arrowhead.addPoint(new Point(flange_ix_project, flange_iy_right)); 83 78 84 79 return arrowhead; … … 95 90 96 91 // brush strokes used for painting this line and highlighting 97 private Stroke _lineStroke = new BasicStroke(DEFAULT_THICKNESS, CAP, JOIN, 4.0F);92 private Stroke _lineStroke = new Stroke(DEFAULT_THICKNESS, DEFAULT_CAP, DEFAULT_JOIN); 98 93 99 94 Stroke getStroke() { … … 143 138 for (int i = 0; i < pattern.length; i++) 144 139 dash[i] = (float) pattern[i]; 145 _lineStroke = new BasicStroke(Math.max(thick, 146 MINIMUM_PAINT_THICKNESS), CAP, JOIN, 10f, dash, 0.0f); 140 _lineStroke = new Stroke(Math.max(thick, MINIMUM_PAINT_THICKNESS), DEFAULT_CAP, DEFAULT_JOIN, dash, 0.0f); 147 141 } else { 148 _lineStroke = new BasicStroke(Math.max(thick, 149 MINIMUM_PAINT_THICKNESS), CAP, JOIN); 150 } 151 152 updatePolygon(); 142 _lineStroke = new Stroke(Math.max(thick, MINIMUM_PAINT_THICKNESS), DEFAULT_CAP, DEFAULT_JOIN); 143 } 144 145 invalidateBounds(); 153 146 } 154 147 … … 240 233 _start = start; 241 234 _start.addLine(this); 242 updatePolygon();235 invalidateBounds(); 243 236 } 244 237 } … … 258 251 _end = end; 259 252 _end.addLine(this); 260 updatePolygon();253 invalidateBounds(); 261 254 } 262 255 } … … 317 310 for (int i = 0; i < pattern.length; i++) 318 311 dash[i] = (float) pattern[i]; 319 _lineStroke = new BasicStroke(Math.max(thick, MINIMUM_THICKNESS), 320 CAP, JOIN, 10f, dash, 0.0f); 312 _lineStroke = new Stroke(Math.max(thick, MINIMUM_THICKNESS), DEFAULT_CAP, DEFAULT_JOIN, dash, 0.0f); 321 313 } else 322 _lineStroke = new BasicStroke(Math.max(thick, MINIMUM_THICKNESS), 323 CAP, JOIN); 314 _lineStroke = new Stroke(Math.max(thick, MINIMUM_THICKNESS), DEFAULT_CAP, DEFAULT_JOIN); 324 315 325 316 if (_start.getLinePattern() != pattern) … … 333 324 334 325 @Override 335 public void paint(Graphics2D g) { 336 if (!isVisible()) 337 return; 338 339 // Dont paint lines with thickness 0 if they are the border on a filled 340 // shape 341 if (dontPaint()) 342 return; 343 344 g.setColor(getPaintColor()); 326 public void paint() 327 { 328 if (!isVisible()) return; 329 330 // Dont paint lines with thickness 0 if they are the border on a filled shape 331 if (dontPaint()) return; 345 332 346 333 // if (this._mode == Item.SelectedMode.Disconnect) 347 334 // System.out.println("Disconnect mode!"); 348 g.setStroke(_lineStroke);349 335 // Get a path of points 350 int[][][] paths = getPaths(); 351 for (int i = 0; i < paths.length; i++) { 352 int[][] path = paths[i]; 353 int last = path[0].length - 1; 354 if (path[0][0] == path[0][last] && path[1][0] == path[1][last]) { 355 g.drawPolygon(path[0], path[1], last); 356 } else { 357 g.drawPolyline(path[0], path[1], last + 1); 358 } 359 } 336 PolygonBounds[] paths = getPaths(); 337 for (PolygonBounds path : paths) { 338 EcosystemManager.getGraphicsManager().drawPolygon(path, null, null, 0.0f, null, getPaintColor(), _lineStroke); 339 } 340 360 341 // paint the arrowhead (if necessary) 361 paintArrows(g); 362 363 if (showLineHighlight() && isHighlighted()) { 364 g.setColor(getHighlightColor()); 365 g.setStroke(HIGHLIGHT_STROKE); 366 ((Graphics2D) g).draw(this.getArea()); 342 paintArrows(); 343 344 if (shouldShowLineHighlight() && isHighlighted()) { 345 PolygonBounds poly = (PolygonBounds) getBounds(); 346 EcosystemManager.getGraphicsManager().drawPolygon(poly, null, null, 0.0f, null, getHighlightColor(), HIGHLIGHT_STROKE); 367 347 } 368 348 } … … 371 351 // enable invisible shapes (for web browser divs) only when XRayMode is off 372 352 return getThickness() <= 0 && _start.isEnclosed() 373 && (_start.getFillColor() != null || ! FrameGraphics.isXRayMode());374 } 375 376 protected int[][][] getPaths() {353 && (_start.getFillColor() != null || !DisplayController.isXRayMode()); 354 } 355 356 protected PolygonBounds[] getPaths() { 377 357 List<List<Point>> pointPaths = new LinkedList<List<Point>>(); 378 358 Collection<Line> visited = new HashSet<Line>(); … … 388 368 } 389 369 // Put the paths into int arrays 390 int[][][] paths = new int[pointPaths.size()][][];370 PolygonBounds[] paths = new PolygonBounds[pointPaths.size()]; 391 371 Iterator<List<Point>> iter = pointPaths.iterator(); 392 372 393 373 for (int i = 0; i < paths.length; i++) { 394 374 List<Point> pointPath = iter.next(); 395 int[][] path = new int[2][pointPath.size()];375 PolygonBounds path = new PolygonBounds(); 396 376 paths[i] = path; 397 377 // Add all the x and y's to the array 398 for (int j = 0; j < p ath[0].length; j++) {399 path [0][j] = pointPath.get(j).x;400 path[1][j] = pointPath.get(j).y;401 402 }378 for (int j = 0; j < pointPath.size(); j++) { 379 path.addPoint(pointPath.get(j).x, pointPath.get(j).y); 380 } 381 } 382 403 383 return paths; 404 384 } 405 385 406 protected List<Point> getPath(Collection<Line> visited, 407 LinkedList<Line> toExplore){386 protected List<Point> getPath(Collection<Line> visited, LinkedList<Line> toExplore) 387 { 408 388 LinkedList<Point> points = new LinkedList<Point>(); 409 389 // put the start item points into our list … … 417 397 } 418 398 419 public void paintArrows(Graphics2D g) { 420 if (dontPaint()) 421 return; 422 423 g.setColor(getPaintColor()); 424 g.setStroke(new BasicStroke(getPaintThickness(), CAP, 425 BasicStroke.JOIN_MITER)); 426 paintArrow(g, getStartArrow()); 427 paintArrow(g, getEndArrow()); 428 399 public void paintArrows() 400 { 401 if (dontPaint()) return; 402 403 paintArrow(getStartArrow()); 404 paintArrow(getEndArrow()); 405 406 // TODO: What is a virtual spot? cts16 429 407 if (_virtualSpot != null) { 430 _virtualSpot.paint( g);408 _virtualSpot.paint(); 431 409 invalidateVirtualSpot(); 432 410 _virtualSpot = null; … … 456 434 * @return 457 435 */ 458 private Shape getArrow(Item withArrow, Point startOffset, Point endOffset) { 459 boolean disconnectMode = withArrow._mode == Item.HighlightMode.Disconnect; 436 private PolygonBounds getArrow(Item withArrow, Point startOffset, Point endOffset) 437 { 438 boolean disconnectMode = withArrow._highlightMode == Item.HighlightMode.Disconnect; 439 460 440 // only draw an arrowhead if necessary 461 if (!(this._mode == Item.HighlightMode.Disconnect && disconnectMode) 462 && (!withArrow.hasVisibleArrow() || withArrow.getLines().size() > 1)) 441 if ( !(this._highlightMode == Item.HighlightMode.Disconnect && disconnectMode) && 442 (!withArrow.hasVisibleArrow() || withArrow.getLines().size() > 1)) 443 { 463 444 return null; 464 445 } 446 465 447 int x0, x1, y0, y1; 466 448 … … 475 457 476 458 // set the size of the disconnect indicator arrowhead 477 if (this._ mode == Item.HighlightMode.Disconnect) {459 if (this._highlightMode == Item.HighlightMode.Disconnect) { 478 460 arrowLength = 15; 479 461 arrowRatio = 0.3; … … 494 476 // The length of the line must at least be as long as the arrow or we 495 477 // wont show the arrow 496 if (length <= MINIMUM_ARROW_HEAD_LENGTH) 497 return null;478 if (length <= MINIMUM_ARROW_HEAD_LENGTH) return null; 479 498 480 if (arrowLength == AUTO_ARROWHEAD_LENGTH) { 499 481 arrowLength = getAutoArrowheadLength(length); … … 508 490 509 491 // only calculate the arrowhead polygon if necessary 510 Polygon arrowhead = withArrow.getArrowhead();492 PolygonBounds arrowhead = withArrow.getArrowhead(); 511 493 if (arrowhead == null || disconnectMode) { 512 arrowhead = createArrowheadPolygon(x0, y0,arrowLength,arrowRatio,arrowNibPerc);494 arrowhead = createArrowheadPolygon(x0, y0, arrowLength, arrowRatio, arrowNibPerc); 513 495 514 496 if (!disconnectMode) 515 withArrow.setArrowhead(arrowhead); 516 } 497 withArrow.setArrowhead(new PolygonBounds(arrowhead)); 498 } 499 arrowhead = arrowhead.clone(); 517 500 double rad = calcAngle((float) x0, (float) y0, (float) x1, (float) y1); 518 arrowhead.translate((x0 + length) - arrowhead.xpoints[0], y0 519 - arrowhead.ypoints[0]); 520 AffineTransform tx = AffineTransform.getRotateInstance(rad, x0, y0); 521 522 int[] rx = new int[arrowhead.npoints]; 523 int[] ry = new int[arrowhead.npoints]; 524 525 for(int i = 0; i < arrowhead.npoints; i++){ 526 Point2D p = new Point2D.Double(arrowhead.xpoints[i], arrowhead.ypoints[i]); 527 tx.transform(p,p); 528 rx[i] = (int) p.getX(); 529 ry[i] = (int) p.getY(); 530 } 531 532 return new Polygon(rx, ry, arrowhead.npoints); 501 arrowhead.translate((x0 + length) - arrowhead.toArray()[0].x, y0 - arrowhead.toArray()[0].y); 502 arrowhead.rotate(rad, x0, y0); 503 504 return arrowhead; 533 505 } 534 506 535 public Polygon getStartArrow() {536 return (Polygon)getArrow(_start, _startOffset, _endOffset);507 public PolygonBounds getStartArrow() { 508 return getArrow(_start, _startOffset, _endOffset); 537 509 } 538 510 539 public Polygon getEndArrow() {540 return (Polygon)getArrow(_end, _endOffset, _startOffset);511 public PolygonBounds getEndArrow() { 512 return getArrow(_end, _endOffset, _startOffset); 541 513 } 542 514 … … 544 516 * Based on code from DeSL (Arrow2D) http://sourceforge.net/projects/desl/ 545 517 */ 546 private void paintArrow(Graphics2D g, Shape arrow) { 518 private void paintArrow(PolygonBounds arrow) 519 { 520 Colour arrowColour = getPaintColor(); 521 Fill arrowFill = new Fill(arrowColour); 522 Stroke arrowStroke = new Stroke(getPaintThickness(), DEFAULT_CAP, Stroke.JOIN.MITER); 547 523 548 524 if(arrow == null) { … … 557 533 // **** 558 534 559 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);560 561 g. draw(arrow);562 g. fill(arrow);535 GraphicsManager g = EcosystemManager.getGraphicsManager(); 536 537 g.setAntialiasing(true); 538 g.drawPolygon(arrow.close(), null, null, 0.0f, arrowFill, arrowColour, arrowStroke); 563 539 564 540 } … … 630 606 return temp; 631 607 } 608 609 public Item getEndPointToDisconnect(Point p) 610 { 611 return getEndPointToDisconnect(p.x, p.y); 612 } 632 613 633 614 public Item getEndPointToDisconnect(int x, int y) { … … 653 634 654 635 if (distStart < NORMAL_THRESHHOLD) { 655 start._ mode = Item.HighlightMode.Normal;636 start._highlightMode = Item.HighlightMode.Normal; 656 637 return start; 657 638 } else if (distEnd < NORMAL_THRESHHOLD) { 658 end._ mode = Item.HighlightMode.Normal;639 end._highlightMode = Item.HighlightMode.Normal; 659 640 return end; 660 641 } else if (distStart < DISCONNECT_THRESHHOLD) { 661 642 if (start.getLines().size() > 1 662 643 || start.getConstraints().size() > 0) 663 start._ mode = Item.HighlightMode.Disconnect;644 start._highlightMode = Item.HighlightMode.Disconnect; 664 645 else 665 start._ mode = Item.HighlightMode.Normal;646 start._highlightMode = Item.HighlightMode.Normal; 666 647 return start; 667 648 } else if (distEnd < DISCONNECT_THRESHHOLD) { 668 649 if (end.getLines().size() > 1 || end.getConstraints().size() > 0) 669 end._ mode = Item.HighlightMode.Disconnect;650 end._highlightMode = Item.HighlightMode.Disconnect; 670 651 else 671 end._ mode = Item.HighlightMode.Normal;652 end._highlightMode = Item.HighlightMode.Normal; 672 653 return end; 673 654 } … … 677 658 678 659 @Override 679 public int setHighlightColor() {680 super.setHighlightColor ();681 682 return Item.UNCHANGED_CURSOR;660 public void setHighlightColorToDefault() { 661 super.setHighlightColorToDefault(); 662 663 //return Item.UNCHANGED_CURSOR; 683 664 } 684 665 … … 690 671 */ 691 672 @Override 692 public void setColor(Colo r c) {673 public void setColor(Colour c) { 693 674 super.setColor(c); 694 675 … … 698 679 699 680 @Override 700 public Colo r getFillColor() {681 public Colour getFillColor() { 701 682 return _start.getFillColor(); 702 683 } … … 882 863 private Item _virtualSpot = null; 883 864 884 public void showVirtualSpot(Item orig, int mouseX, int mouseY) {885 if (orig.getLines().size() != 1)886 865 public void showVirtualSpot(Item orig, int mouseX, int mouseY) 866 { 867 if (orig.getLines().size() != 1) return; 887 868 888 869 // lines that are in 'connected' mode, also cannot be attached 889 if (orig.getLines().get(0).getOppositeEnd(orig).isFloating()) 890 return; 870 if (orig.getLines().get(0).getOppositeEnd(orig).isFloating()) return; 891 871 892 872 Item spot = new Dot(-1, orig.getX(), orig.getY()); 893 873 Item.DuplicateItem(orig, spot); 894 874 spot.setThickness(Math.max(this.getThickness(), 5)); 895 if (this.getColor() != Color.RED) 896 spot.setColor(Color.RED); 897 else 898 spot.setColor(Color.BLUE); 899 875 if (!this.getColor().equals(Colour.RED)) { 876 spot.setColor(Colour.RED); 877 } else { 878 spot.setColor(Colour.BLUE); 879 } 880 900 881 // unhighlight all the dots 901 882 for (Item conn : getAllConnected()) { 902 883 conn.setHighlightMode(Item.HighlightMode.None); 903 } 884 conn.setHighlightColorToDefault(); 885 } 886 887 // calculate nearest point on line from spot 888 org.expeditee.core.Line line = new org.expeditee.core.Line(_start.getPosition(), _end.getPosition()); 889 Point nearest = line.getPointNearestTo(spot.getPosition()); 890 891 // position spot on the line 892 spot.setPosition(nearest); 893 _virtualSpot = spot; 894 invalidateVirtualSpot(); 895 } 896 897 public void showVirtualSpot(int mouseX, int mouseY) { 898 Item spot = new Dot(mouseX, mouseY, -1); 899 spot.setThickness(Math.max(this.getThickness(), 5)); 900 if (DEFAULT_HIGHLIGHT.equals(this.getColor())) 901 spot.setColor(ALTERNATE_HIGHLIGHT); 902 else 903 spot.setColor(DEFAULT_HIGHLIGHT); 904 905 906 // calculate nearest point on line from spot 907 org.expeditee.core.Line line = new org.expeditee.core.Line(_start.getPosition(), _end.getPosition()); 908 Point nearest = line.getPointNearestTo(spot.getPosition()); 909 910 // position spot on the line 911 spot.setPosition(nearest); 912 _virtualSpot = spot; 913 invalidateVirtualSpot(); 914 } 915 916 public Item forceMerge(Item spot, int mouseX, int mouseY) { 904 917 905 918 // calculate nearest point on line from spot … … 930 943 // position spot on the line 931 944 spot.setPosition((int) x, (int) y); 932 _virtualSpot = spot;933 invalidateVirtualSpot();934 }935 936 public void showVirtualSpot(int mouseX, int mouseY) {937 Item spot = new Dot(mouseX, mouseY, -1);938 spot.setThickness(Math.max(this.getThickness(), 5));939 if (DEFAULT_HIGHLIGHT.equals(this.getColor()))940 spot.setColor(ALTERNATE_HIGHLIGHT);941 else942 spot.setColor(DEFAULT_HIGHLIGHT);943 944 // calculate nearest point on line from spot945 double slope1;946 double slope2;947 double x, y;948 949 slope1 = (_start.getY() - _end.getY() * 1.0)950 / (_start.getX() - _end.getX());951 slope2 = -1 / slope1;952 953 // if the line is horizontal954 if (slope1 == 0) {955 x = spot.getX();956 y = _start.getY();957 // if the line is vertical958 } else if (slope2 == 0) {959 x = _start.getX();960 y = spot.getY();961 // otherwise, the line is sloped962 } else {963 x = (-1 * slope2 * spot.getX() + spot.getY() - _start.getY() + slope1964 * _start.getX())965 / (slope1 - slope2);966 y = slope1 * (x - _start.getX()) + _start.getY();967 }968 969 // position spot on the line970 spot.setPosition((int) x, (int) y);971 _virtualSpot = spot;972 invalidateVirtualSpot();973 }974 975 public Item forceMerge(Item spot, int mouseX, int mouseY) {976 977 // calculate nearest point on line from spot978 double slope1;979 double slope2;980 double x, y;981 982 slope1 = (_start.getY() - _end.getY() * 1.0)983 / (_start.getX() - _end.getX());984 slope2 = -1 / slope1;985 986 // if the line is horizontal987 if (slope1 == 0) {988 x = spot.getX();989 y = _start.getY();990 // if the line is vertical991 } else if (slope2 == 0) {992 x = _start.getX();993 y = spot.getY();994 // otherwise, the line is sloped995 } else {996 x = (-1 * slope2 * spot.getX() + spot.getY() - _start.getY() + slope1997 * _start.getX())998 / (slope1 - slope2);999 y = slope1 * (x - _start.getX()) + _start.getY();1000 }1001 1002 // position spot on the line1003 spot.setPosition((int) x, (int) y);1004 945 1005 946 // Keep constraints … … 1018 959 Line temp = copy(); 1019 960 1020 Frame currentFrame = Display IO.getCurrentFrame();961 Frame currentFrame = DisplayController.getCurrentFrame(); 1021 962 temp.setID(currentFrame.getNextItemID()); 1022 963 temp.setEndItem(_end); … … 1101 1042 1102 1043 @Override 1103 public void updatePolygon() {1104 _poly = new Polygon();1105 1106 Rectangleone;1107 Rectangletwo;1044 public PolygonBounds updateBounds() { 1045 PolygonBounds ret = new PolygonBounds(); 1046 1047 AxisAlignedBoxBounds one; 1048 AxisAlignedBoxBounds two; 1108 1049 1109 1050 /** … … 1121 1062 Item e = new Dot(_end.getX(), _end.getY(), -1); 1122 1063 1123 one = s.getPolygon().getBounds();1124 two = e.getPolygon().getBounds();1064 one = AxisAlignedBoxBounds.getEnclosing(s.getBounds()); 1065 two = AxisAlignedBoxBounds.getEnclosing(e.getBounds()); 1125 1066 } else { 1126 1067 Item s = new Dot(_start.getX(), _start.getY(), -1); 1127 1068 Item e = new Dot(_end.getX(), _end.getY(), -1); 1128 1069 1129 one = e.getPolygon().getBounds();1130 two = s.getPolygon().getBounds();1070 one = AxisAlignedBoxBounds.getEnclosing(e.getBounds()); 1071 two = AxisAlignedBoxBounds.getEnclosing(s.getBounds()); 1131 1072 /* 1132 1073 * one = _end.getPolygon().getBounds(); two = … … 1136 1077 1137 1078 // if one is above two 1138 if (one.get Y() < two.getY()) {1139 _poly.addPoint((int) one.getMaxX(), (int)one.getMinY());1140 _poly.addPoint((int) two.getMaxX(), (int)two.getMinY());1141 _poly.addPoint((int) two.getMinX(), (int)two.getMaxY());1142 _poly.addPoint((int) one.getMinX(), (int)one.getMaxY());1079 if (one.getMinY() < two.getMinY()) { 1080 ret.addPoint(one.getMaxX(), one.getMinY()); 1081 ret.addPoint(two.getMaxX(), two.getMinY()); 1082 ret.addPoint(two.getMinX(), two.getMaxY()); 1083 ret.addPoint(one.getMinX(), one.getMaxY()); 1143 1084 // if one is below two 1144 1085 } else { 1145 _poly.addPoint((int) one.getMinX(), (int) one.getMinY()); 1146 _poly.addPoint((int) two.getMinX(), (int) two.getMinY()); 1147 _poly.addPoint((int) two.getMaxX(), (int) two.getMaxY()); 1148 _poly.addPoint((int) one.getMaxX(), (int) one.getMaxY()); 1149 } 1150 1086 ret.addPoint(one.getMinX(), one.getMinY()); 1087 ret.addPoint(two.getMinX(), two.getMinY()); 1088 ret.addPoint(two.getMaxX(), two.getMaxY()); 1089 ret.addPoint(one.getMaxX(), one.getMaxY()); 1090 } 1091 1092 return ret.close(); 1151 1093 } 1152 1094 … … 1199 1141 1200 1142 public double getLength() { 1201 return getLength(_start.getPosition(), _end.getPosition());1143 return Point.distanceBetween(_start.getPosition(), _end.getPosition()); 1202 1144 } 1203 1145 … … 1210 1152 } 1211 1153 1212 public static double getLength(Point p1, Point p2) {1213 return Point.distance(p1 .x, p1.y, p2.x, p2.y);1214 } 1215 1216 @Override 1217 public Rectangle[]getDrawingArea() { // TODO: CACHE - LIKE UPDATE POLYGON1154 /* public static double getLength(Point p1, Point p2) { 1155 return Point.distance(p1, p2); 1156 }*/ 1157 1158 @Override 1159 public AxisAlignedBoxBounds getDrawingArea() { // TODO: CACHE - LIKE UPDATE POLYGON 1218 1160 1219 1161 float currentThickness = this.getThickness() + 4; … … 1236 1178 y -= halfThickness; 1237 1179 1238 Rectangle bounds = new Rectangle(x, y, w, h);1180 AxisAlignedBoxBounds bounds = new AxisAlignedBoxBounds(x, y, w, h); 1239 1181 1240 1182 // TODO: Cap bounds … … 1257 1199 overall as opposed to advanced/expensive calculations for getting exact 1258 1200 bounding box */ 1259 Rectangle arrowBounds = new Rectangle(_end.getX() - nArrowLength,1201 AxisAlignedBoxBounds arrowBounds = new AxisAlignedBoxBounds(_end.getX() - nArrowLength, 1260 1202 _end.getY() - nArrowLength, 2 * nArrowLength, 1261 1203 2 * nArrowLength); … … 1263 1205 if (currentThickness > 0.0f) { 1264 1206 1265 arrowBounds = new Rectangle(arrowBounds.x- halfThickness,1266 arrowBounds. y - halfThickness, arrowBounds.width1267 + thickness, arrowBounds. height+ thickness);1268 } 1269 1270 return new Rectangle[] { bounds, arrowBounds };1207 arrowBounds = new AxisAlignedBoxBounds(arrowBounds.getMinX() - halfThickness, 1208 arrowBounds.getMinY() - halfThickness, arrowBounds.getWidth() 1209 + thickness, arrowBounds.getHeight() + thickness); 1210 } 1211 1212 return bounds.combineWith(arrowBounds); 1271 1213 } else { 1272 return new Rectangle[] { bounds };1214 return bounds; 1273 1215 } 1274 1216 … … 1294 1236 public void scale(Float scale, int originX, int originY) { 1295 1237 } 1238 1239 @Override 1240 public float getSize() 1241 { 1242 return getThickness(); 1243 } 1296 1244 } -
trunk/src/org/expeditee/items/MagneticConstraint/Actions/AttractTextAction.java
r974 r1102 1 1 package org.expeditee.items.MagneticConstraint.Actions; 2 2 3 import java.awt.Point; 4 3 import org.expeditee.core.Point; 5 4 import org.expeditee.gui.FrameUtils; 6 5 import org.expeditee.items.Item; -
trunk/src/org/expeditee/items/MagneticConstraint/Actions/BackspaceAction.java
r967 r1102 1 1 package org.expeditee.items.MagneticConstraint.Actions; 2 2 3 import org.expeditee.gui.Display IO;3 import org.expeditee.gui.DisplayController; 4 4 import org.expeditee.items.Item; 5 5 import org.expeditee.items.Text; … … 15 15 if(item.getParent() == null || !this.isSpIDERCodePage(item.getParent())) return false; 16 16 if(item == null || ((Text) item).isEmpty()) { 17 final Text temp = Display IO.getCurrentFrame().createNewText(".");17 final Text temp = DisplayController.getCurrentFrame().createNewText("."); 18 18 callback(temp); 19 19 if(temp.getMagnetizedItemLeft() != -1) 20 Display IO.setTextCursor((Text) temp.getParent().getItemWithID(temp.getMagnetizedItemLeft()), Text.END);20 DisplayController.setTextCursor((Text) temp.getParent().getItemWithID(temp.getMagnetizedItemLeft()), Text.END); 21 21 else if(temp.getMagnetizedItemTop() != -1) 22 Display IO.setTextCursor((Text) temp.getParent().getItemWithID(temp.getMagnetizedItemTop()), Text.END);22 DisplayController.setTextCursor((Text) temp.getParent().getItemWithID(temp.getMagnetizedItemTop()), Text.END); 23 23 temp.delete(); 24 24 callback(temp); 25 25 return true; 26 } else if(item.getMagnetizedItemLeft() != -1 && TextLogic.XIsBeforeCharacters((Text) item, Display IO.getMouseX())) {26 } else if(item.getMagnetizedItemLeft() != -1 && TextLogic.XIsBeforeCharacters((Text) item, DisplayController.getMouseX())) { 27 27 new LastItemAction().exec(item); 28 28 return true; 29 } else if(item.getMagnetizedItemTop() != -1 && TextLogic.XIsBeforeCharacters((Text) item, Display IO.getMouseX())) {29 } else if(item.getMagnetizedItemTop() != -1 && TextLogic.XIsBeforeCharacters((Text) item, DisplayController.getMouseX())) { 30 30 callback(item); 31 31 final Line currentLine = Line.getLineFromToken(item); … … 33 33 if(lastLine != null && Paragraph.getParagraphFromLine(lastLine).contains(currentLine)) { 34 34 lastLine.appendLine(currentLine); 35 Display IO.setTextCursor((Text) item, Text.HOME);35 DisplayController.setTextCursor((Text) item, Text.HOME); 36 36 callback(item); 37 37 return true; -
trunk/src/org/expeditee/items/MagneticConstraint/Actions/DeleteAction.java
r967 r1102 1 1 package org.expeditee.items.MagneticConstraint.Actions; 2 2 3 import org.expeditee.gui.Display IO;3 import org.expeditee.gui.DisplayController; 4 4 import org.expeditee.items.Item; 5 5 import org.expeditee.items.Text; … … 15 15 if(item.getParent() == null || !this.isSpIDERCodePage(item.getParent())) return false; 16 16 if(item == null || ((Text) item).isEmpty()) { 17 final Text temp = Display IO.getCurrentFrame().createNewText(".");17 final Text temp = DisplayController.getCurrentFrame().createNewText("."); 18 18 callback(temp); 19 19 if(temp.getMagnetizedItemRight() != -1) 20 Display IO.setTextCursor((Text) temp.getParent().getItemWithID(temp.getMagnetizedItemRight()), Text.HOME);20 DisplayController.setTextCursor((Text) temp.getParent().getItemWithID(temp.getMagnetizedItemRight()), Text.HOME); 21 21 else if(temp.getMagnetizedItemBottom() != -1) 22 Display IO.setTextCursor((Text) temp.getParent().getItemWithID(temp.getMagnetizedItemBottom()), Text.HOME);22 DisplayController.setTextCursor((Text) temp.getParent().getItemWithID(temp.getMagnetizedItemBottom()), Text.HOME); 23 23 temp.delete(); 24 24 callback(temp); 25 25 return true; 26 } else if(item.getMagnetizedItemRight() != -1 && TextLogic.XIsAfterCharacters((Text) item, Display IO.getMouseX())) {26 } else if(item.getMagnetizedItemRight() != -1 && TextLogic.XIsAfterCharacters((Text) item, DisplayController.getMouseX())) { 27 27 new NextItemAction().exec(item); 28 28 return true; 29 } else if(item.getMagnetizedItemBottom() != -1 && TextLogic.XIsAfterCharacters((Text) item, Display IO.getMouseX())) {29 } else if(item.getMagnetizedItemBottom() != -1 && TextLogic.XIsAfterCharacters((Text) item, DisplayController.getMouseX())) { 30 30 callback(item); 31 31 final Line currentLine = Line.getLineFromToken(item); … … 33 33 if(nextLine != null && Paragraph.getParagraphFromLine(currentLine).contains(nextLine)) { 34 34 currentLine.appendLine(nextLine); 35 Display IO.setTextCursor((Text) item, Text.END);35 DisplayController.setTextCursor((Text) item, Text.END); 36 36 callback(item); 37 37 return true; -
trunk/src/org/expeditee/items/MagneticConstraint/Actions/DownALineAction.java
r967 r1102 1 1 package org.expeditee.items.MagneticConstraint.Actions; 2 2 3 import org.expeditee.gui.Display IO;3 import org.expeditee.gui.DisplayController; 4 4 import org.expeditee.items.Item; 5 5 import org.expeditee.items.Text; … … 19 19 final int nextLineLength = 20 20 nextLine.get(nextLine.size() - 1).getX() + nextLine.get(nextLine.size() - 1).getBoundsWidth() - nextLine.get(0).getX(); 21 final int distanceThroughCurrentLine = Display IO.getMouseX() - startOfThisLine.getX();21 final int distanceThroughCurrentLine = DisplayController.getMouseX() - startOfThisLine.getX(); 22 22 if(distanceThroughCurrentLine <= nextLineLength) { 23 23 Item beneith = nextLine.get(0); … … 43 43 if(toMoveTo instanceof Text) { 44 44 final Text asText = (Text) toMoveTo; 45 Display IO.setTextCursor(asText, Text.END);46 } else Display IO.setCursorPosition(toMoveTo.getPosition(), false);45 DisplayController.setTextCursor(asText, Text.END); 46 } else DisplayController.setCursorPosition(toMoveTo.getPosition(), false); 47 47 return true; 48 48 } -
trunk/src/org/expeditee/items/MagneticConstraint/Actions/LastItemAction.java
r977 r1102 1 1 package org.expeditee.items.MagneticConstraint.Actions; 2 2 3 import org.expeditee.gui.Display IO;3 import org.expeditee.gui.DisplayController; 4 4 import org.expeditee.gui.FrameGraphics; 5 5 import org.expeditee.gui.FrameUtils; … … 44 44 // DisplayIO.setCursorPosition(position.x + asText.getPixelBoundsUnion().width, position.y, false); 45 45 // FrameGraphics.refresh(false); 46 Display IO.setTextCursor((Text)toMoveTo, Text.END);46 DisplayController.setTextCursor((Text)toMoveTo, Text.END); 47 47 if(FrameUtils.getCurrentItem() != toMoveTo) { 48 48 Line.getLineFromToken(toMoveFrom).deltaX(1); 49 49 moveCursor(toMoveTo, toMoveFrom); 50 50 } 51 } else Display IO.setCursorPosition(toMoveTo.getPosition(), false);51 } else DisplayController.setCursorPosition(toMoveTo.getPosition(), false); 52 52 return true; 53 53 } -
trunk/src/org/expeditee/items/MagneticConstraint/Actions/NextItemAction.java
r967 r1102 1 1 package org.expeditee.items.MagneticConstraint.Actions; 2 2 3 import org.expeditee.gui.Display IO;3 import org.expeditee.gui.DisplayController; 4 4 import org.expeditee.items.Item; 5 5 import org.expeditee.items.Text; … … 34 34 return false; 35 35 //System.err.println("Next item requests move to item with text: " + toMoveTo.getText()); 36 Display IO.setTextCursor((Text)toMoveTo, Text.HOME);36 DisplayController.setTextCursor((Text)toMoveTo, Text.HOME); 37 37 return true; 38 38 } -
trunk/src/org/expeditee/items/MagneticConstraint/Actions/RepelTextAction.java
r974 r1102 1 1 package org.expeditee.items.MagneticConstraint.Actions; 2 2 3 import java.awt.Point; 4 5 import org.expeditee.gui.Browser; 3 import org.expeditee.core.Point; 4 import org.expeditee.gio.EcosystemManager; 6 5 import org.expeditee.gui.FrameUtils; 7 6 import org.expeditee.items.Item; … … 45 44 return false; 46 45 } else { 47 final int charDistance = Browser._theBrowser.getFontMetrics(((Text)item).getFont()).stringWidth("X");46 final int charDistance = EcosystemManager.getTextLayoutManager().getStringWidth(((Text)item).getFont(), "X"); 48 47 final Line tokensToMove = Line.getLineFromToken(item); 49 48 tokensToMove.removeFirst(); -
trunk/src/org/expeditee/items/MagneticConstraint/Actions/RepelTextDownAction.java
r967 r1102 1 1 package org.expeditee.items.MagneticConstraint.Actions; 2 2 3 import java.awt.Point; 4 5 import org.expeditee.gui.DisplayIO; 3 import org.expeditee.core.Point; 4 import org.expeditee.gui.DisplayController; 6 5 import org.expeditee.gui.FrameIO; 7 6 import org.expeditee.gui.FrameUtils; … … 28 27 (FrameUtils.getCurrentItem().getPosition().equals(item.getPosition()) 29 28 && remainderOfLine.size() > 0 30 && TextLogic.XIsTowardsRight(Display IO.getMouseX(), (Text) remainderOfLine.getFirst()))) {29 && TextLogic.XIsTowardsRight(DisplayController.getMouseX(), (Text) remainderOfLine.getFirst()))) { 31 30 remainderOfLine.removeFirst(); 32 31 } … … 42 41 if(!remainderOfLine.isEmpty() && currentParagraph.contains(nextLine) && MergeSameLineParagraphCollisions) { 43 42 nextLine.prependLine(remainderOfLine); 44 Display IO.setTextCursor((Text) remainderOfLine.getFirst(), Text.HOME);43 DisplayController.setTextCursor((Text) remainderOfLine.getFirst(), Text.HOME); 45 44 callback(remainderOfLine.getFirst()); 46 45 FrameIO.SaveFrame(remainderOfLine.getLast().getParent()); 47 46 } else if(!remainderOfLine.isEmpty()) { 48 47 newLineAt = currentParagraph.split(currentLine); 49 final Point first = remainderOfLine.getBoundingBox().get Location();48 final Point first = remainderOfLine.getBoundingBox().getTopLeft(); 50 49 for(final Item token : remainderOfLine) { 51 50 double newX = token.getX() - first.getX() + newLineAt.getX(); 52 51 token.setPosition((float) newX, (float) newLineAt.getY()); 53 52 } 54 Display IO.setTextCursor((Text) remainderOfLine.getFirst(), Text.HOME);53 DisplayController.setTextCursor((Text) remainderOfLine.getFirst(), Text.HOME); 55 54 callback(remainderOfLine.getFirst()); 56 55 FrameIO.SaveFrame(remainderOfLine.getLast().getParent()); … … 58 57 //3a No. Move the cursor 59 58 newLineAt = currentParagraph.split(currentLine); 60 Display IO.setCursorPosition(newLineAt);59 DisplayController.setCursorPosition(newLineAt); 61 60 } 62 61 -
trunk/src/org/expeditee/items/MagneticConstraint/Actions/UpALineAction.java
r967 r1102 1 1 package org.expeditee.items.MagneticConstraint.Actions; 2 2 3 import org.expeditee.gui.Display IO;3 import org.expeditee.gui.DisplayController; 4 4 import org.expeditee.items.Item; 5 5 import org.expeditee.items.Text; … … 19 19 final int lastLineLength = 20 20 lastLine.get(lastLine.size() - 1).getX() + lastLine.get(lastLine.size() - 1).getBoundsWidth() - lastLine.get(0).getX(); 21 final int distanceThroughCurrentLine = Display IO.getMouseX() - startOfThisLine.getX();21 final int distanceThroughCurrentLine = DisplayController.getMouseX() - startOfThisLine.getX(); 22 22 if(distanceThroughCurrentLine <= lastLineLength) { 23 23 Item above = lastLine.get(0); … … 37 37 if(toMoveTo instanceof Text) { 38 38 final Text asText = (Text) toMoveTo; 39 Display IO.setTextCursor(asText, Text.END);40 } else Display IO.setCursorPosition(toMoveTo.getPosition(), false);39 DisplayController.setTextCursor(asText, Text.END); 40 } else DisplayController.setCursorPosition(toMoveTo.getPosition(), false); 41 41 return true; 42 42 } -
trunk/src/org/expeditee/items/MagneticConstraint/Actions/VerticalTabAction.java
r967 r1102 1 1 package org.expeditee.items.MagneticConstraint.Actions; 2 2 3 import org.expeditee.g ui.Browser;4 import org.expeditee.gui.Display IO;3 import org.expeditee.gio.EcosystemManager; 4 import org.expeditee.gui.DisplayController; 5 5 import org.expeditee.items.Item; 6 6 import org.expeditee.items.MagneticConstraint.MagneticConstraintAction; … … 12 12 public boolean exec(final Item item) { 13 13 if(item.getParent() == null || !this.isSpIDERCodePage(item.getParent())) return false; 14 final int tabWidth = Browser._theBrowser.getFontMetrics(Browser._theBrowser.getFont()).stringWidth("");14 final int tabWidth = EcosystemManager.getTextLayoutManager().getStringWidth(null, " "); 15 15 tab(item, tabWidth); 16 16 return true; … … 20 20 public boolean invert(Item item) { 21 21 if(item.getParent() == null || !this.isSpIDERCodePage(item.getParent())) return false; 22 final int tabWidth = -( Browser._theBrowser.getFontMetrics(Browser._theBrowser.getFont()).stringWidth(" "));22 final int tabWidth = -(EcosystemManager.getTextLayoutManager().getStringWidth(null, " ")); 23 23 tab(item, tabWidth); 24 24 return true; … … 27 27 private void tab(final Item item, final int tabWidth) { 28 28 if(item == null) { 29 Display IO.setCursorPosition(DisplayIO.getMouseX() + tabWidth, DisplayIO.getMouseY());29 DisplayController.setCursorPosition(DisplayController.getMouseX() + tabWidth, DisplayController.getMouseY()); 30 30 } else { 31 31 final Line postTabLine = Line.getLineFromToken(item); 32 32 postTabLine.deltaX(tabWidth); 33 33 if(postTabLine.size() > 0) 34 Display IO.setCursorPosition(postTabLine.get(0).getPosition());34 DisplayController.setCursorPosition(postTabLine.get(0).getPosition()); 35 35 } 36 36 } -
trunk/src/org/expeditee/items/MagneticConstraint/Utilities/BoxLogic.java
r963 r1102 1 1 package org.expeditee.items.MagneticConstraint.Utilities; 2 2 3 import java.awt.Rectangle;4 3 import java.util.Collection; 5 4 import java.util.LinkedList; 6 5 import java.util.List; 7 6 7 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 8 8 import org.expeditee.gui.Frame; 9 9 import org.expeditee.items.Dot; … … 40 40 final int bottomPos = Math.max(canditate.getStartItem().getY(), 41 41 canditate.getEndItem().getY()); 42 final Rectangle itemHitBox = item.getArea().getBounds();43 if (topPos < itemHitBox.get Y() && bottomPos > itemHitBox.getY()) {44 if (itemHitBox.get X() + itemHitBox.getWidth() > canditate45 .getStartItem().getX()46 && itemHitBox.getX() < canditate.getStartItem().getX()){42 final AxisAlignedBoxBounds itemHitBox = item.getBoundingBox(); 43 if (topPos < itemHitBox.getMinY() && bottomPos > itemHitBox.getMinY()) { 44 if (itemHitBox.getMinX() + itemHitBox.getWidth() > canditate.getStartItem().getX() && 45 itemHitBox.getMinX() < canditate.getStartItem().getX()) 46 { 47 47 return true; 48 48 } -
trunk/src/org/expeditee/items/MagneticConstraint/Utilities/Line.java
r966 r1102 1 1 package org.expeditee.items.MagneticConstraint.Utilities; 2 2 3 import java.awt.Rectangle;4 3 import java.util.LinkedList; 5 4 5 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 6 6 import org.expeditee.items.Item; 7 7 … … 18 18 19 19 public Line prependLine(final Line line) { 20 final int x = this.getBoundingBox(). x;21 final int width = line.getBoundingBox(). width;20 final int x = this.getBoundingBox().getMinX(); 21 final int width = line.getBoundingBox().getWidth(); 22 22 this.deltaX(width); 23 23 line.setX(x); … … 27 27 28 28 public Line appendLine(final Line line) { 29 final int x = this.getBoundingBox(). x;30 final int width = this.getBoundingBox(). width;29 final int x = this.getBoundingBox().getMinX(); 30 final int width = this.getBoundingBox().getWidth(); 31 31 line.setX(x + width); 32 32 line.setY(this.getFirst().getY()); … … 83 83 } 84 84 85 public RectanglegetBoundingBox() {85 public AxisAlignedBoxBounds getBoundingBox() { 86 86 // final Rectangle rect = new Rectangle(this.getFirst().getX(), this.getFirst().getY(), this.getFirst().getBoundsWidth(), this.getFirst().getBoundsHeight()); 87 87 // for(final Item token : this) 88 88 // rect.add(new Rectangle(token.getX(), token.getY(), token.getBoundsWidth(), token.getBoundsHeight())); 89 89 // return rect; 90 final Rectangle rect = this.getFirst().getArea().getBounds();90 final AxisAlignedBoxBounds rect = this.getFirst().getBoundingBox(); 91 91 for(final Item token : this) 92 rect. add(token.getArea().getBounds());92 rect.combineWith(token.getBoundingBox()); 93 93 return rect; 94 94 } -
trunk/src/org/expeditee/items/MagneticConstraint/Utilities/Paragraph.java
r962 r1102 1 1 package org.expeditee.items.MagneticConstraint.Utilities; 2 2 3 import java.awt.*;4 3 import java.util.LinkedList; 4 5 import org.expeditee.core.Point; 6 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 5 7 import org.expeditee.items.Text; 6 8 … … 30 32 } 31 33 32 public Rectangle getBoundingBox() { 33 final Rectangle rect = new Rectangle(); 34 for(final Line ln : this) rect.add(ln.getBoundingBox()); 34 public AxisAlignedBoxBounds getBoundingBox() { 35 AxisAlignedBoxBounds rect = null; 36 for(final Line ln : this) { 37 if (rect == null) rect = ln.getBoundingBox(); 38 else rect.combineWith(ln.getBoundingBox()); 39 } 35 40 return rect; 36 41 } … … 50 55 if(nextLine == null) { 51 56 //2a. No; then we simply need to calculate the position of where it would be and return that. 52 final RectangleboundingBox = splitAt.getBoundingBox();53 return new Point((int)boundingBox.get X(), (int)boundingBox.getMaxY() + lineHeight);57 final AxisAlignedBoxBounds boundingBox = splitAt.getBoundingBox(); 58 return new Point((int)boundingBox.getMinX(), (int)boundingBox.getMaxY() + lineHeight); 54 59 } 55 60 //3. Get paragraph starting from the next line … … 58 63 if(!this.containsAll(paragraphStartingAtNextLine)) { 59 64 //4b. No; then we simply need to calculate the position of the next line and return that. 60 final RectangleboundingBox = splitAt.getBoundingBox();65 final AxisAlignedBoxBounds boundingBox = splitAt.getBoundingBox(); 61 66 return new Point(((Text) splitAt.getFirst()).getX(), (int)boundingBox.getMaxY() + lineHeight); 62 67 } … … 66 71 //6. Return the position of the new line we have made space for. 67 72 68 final RectangleboundingBox = splitAt.getBoundingBox();73 final AxisAlignedBoxBounds boundingBox = splitAt.getBoundingBox(); 69 74 final int x = ((Text) splitAt.getFirst()).getX(); 70 75 return new Point(x, (int)boundingBox.getMaxY() + lineHeight); … … 72 77 73 78 private static int getLineHeight(final Line line) { 74 return (int) (line.get(0).get Area().getBounds().getHeight() * 1.2);79 return (int) (line.get(0).getBoundingBox().getHeight() * 1.2); 75 80 } 76 81 … … 89 94 private static boolean isInSameParagraph(final Line thisLine, final Line nextLine, final int lineHeight) { 90 95 if(!XGroupLogic.areInSameXGroup(thisLine.get(0), nextLine.get(0))) return false; 91 final RectanglethisLineBoundingBox = thisLine.getBoundingBox();92 final RectanglenextLineBoundingBox = nextLine.getBoundingBox();93 final Point toAdd = new Point(Math.min((int)thisLineBoundingBox.get X(),(int) nextLineBoundingBox.getX()), (int)thisLineBoundingBox.getMaxY() + lineHeight);94 final Rectangle overlappingSection = new Rectangle(thisLineBoundingBox);95 overlappingSection. add(toAdd);96 final AxisAlignedBoxBounds thisLineBoundingBox = thisLine.getBoundingBox(); 97 final AxisAlignedBoxBounds nextLineBoundingBox = nextLine.getBoundingBox(); 98 final Point toAdd = new Point(Math.min((int)thisLineBoundingBox.getMinX(),(int) nextLineBoundingBox.getMinX()), (int)thisLineBoundingBox.getMaxY() + lineHeight); 99 final AxisAlignedBoxBounds overlappingSection = new AxisAlignedBoxBounds(thisLineBoundingBox); 100 overlappingSection.combineWith(toAdd); 96 101 return overlappingSection.intersects(nextLineBoundingBox); 97 102 } -
trunk/src/org/expeditee/items/MagneticConstraint/Utilities/TextLogic.java
r963 r1102 1 1 package org.expeditee.items.MagneticConstraint.Utilities; 2 2 3 import org.expeditee.g ui.Browser;4 import org.expeditee.gui.Display IO;3 import org.expeditee.gio.EcosystemManager; 4 import org.expeditee.gui.DisplayController; 5 5 import org.expeditee.items.Text; 6 6 … … 9 9 public static boolean XIsTowardsRight(final int x, final Text text) { 10 10 if(text.getPixelBoundsUnion() == null) return false; 11 final double distanceThroughText = x - text.getPixelBoundsUnion().get X();11 final double distanceThroughText = x - text.getPixelBoundsUnion().getMinX(); 12 12 return /*text.getText().length() == 1 ||*/ distanceThroughText > (text.getPixelBoundsUnion().getWidth() / 2); 13 13 } … … 15 15 public static boolean XIsTowardsLeft(final Text text, final int x) { 16 16 if(text.getPixelBoundsUnion() == null) return false; 17 final double distanceThroughText = x - text.getPixelBoundsUnion().get X();17 final double distanceThroughText = x - text.getPixelBoundsUnion().getMinX(); 18 18 return distanceThroughText < (text.getPixelBoundsUnion().getWidth() / 2); 19 19 } … … 21 21 public static boolean XIsBeforeCharacters(final Text text, final int x) { 22 22 try { 23 final int firstLetterWidth = Browser._theBrowser.getFontMetrics(Browser._theBrowser.getFont()).stringWidth(text.getText().substring(0, 1));24 final double distanceThroughText = x - text.getPixelBoundsUnion().get X();23 final int firstLetterWidth = EcosystemManager.getTextLayoutManager().getStringWidth(null, text.getText().substring(0, 1)); 24 final double distanceThroughText = x - text.getPixelBoundsUnion().getMinX(); 25 25 return firstLetterWidth > distanceThroughText; 26 26 } catch (NullPointerException e) { … … 33 33 public static boolean XIsAfterCharacters(final Text text, final int x) { 34 34 try { 35 final double distanceThroughText = x - text.getPixelBoundsUnion().get X();35 final double distanceThroughText = x - text.getPixelBoundsUnion().getMinX(); 36 36 return distanceThroughText > text.getPixelBoundsUnion().getWidth(); 37 37 } catch (NullPointerException e) { … … 41 41 42 42 public static int GetInsertionIndexSelected(final Text text) { 43 return text.getCharPosition(0, Display IO.getMouseX()).getInsertionIndex();43 return text.getCharPosition(0, DisplayController.getMouseX()).getInsertionIndex(); 44 44 } 45 45 } -
trunk/src/org/expeditee/items/Picture.java
r1047 r1102 19 19 package org.expeditee.items; 20 20 21 import java.awt.AlphaComposite;22 import java.awt.BasicStroke;23 import java.awt.Color;24 import java.awt.Graphics2D;25 import java.awt.Image;26 import java.awt.Point;27 import java.awt.Polygon;28 import java.awt.Rectangle;29 import java.awt.Shape;30 import java.awt.Stroke;31 import java.awt.Toolkit;32 import java.awt.geom.AffineTransform;33 import java.awt.geom.Point2D;34 import java.awt.image.BufferedImage;35 import java.awt.image.CropImageFilter;36 import java.awt.image.FilteredImageSource;37 import java.awt.image.ImageObserver;38 import java.awt.image.PixelGrabber;39 21 import java.io.File; 40 22 import java.io.IOException; 41 23 import java.text.DecimalFormat; 42 43 import javax.imageio.ImageIO;44 import javax.swing.ImageIcon;45 24 46 25 import org.apache.commons.cli.CommandLine; … … 49 28 import org.apache.commons.cli.Options; 50 29 import org.apache.commons.cli.ParseException; 51 import org.expeditee.gui.DisplayIO; 30 import org.expeditee.core.Clip; 31 import org.expeditee.core.Colour; 32 import org.expeditee.core.Dimension; 33 import org.expeditee.core.EnforcedClipStack.EnforcedClipKey; 34 import org.expeditee.core.Image; 35 import org.expeditee.core.Point; 36 import org.expeditee.core.Stroke; 37 import org.expeditee.core.bounds.AxisAlignedBoxBounds; 38 import org.expeditee.core.bounds.CombinationBoxBounds; 39 import org.expeditee.core.bounds.PolygonBounds; 40 import org.expeditee.gio.EcosystemManager; 41 import org.expeditee.gio.GraphicsManager; 42 import org.expeditee.gui.DisplayController; 52 43 import org.expeditee.gui.FrameGraphics; 53 44 import org.expeditee.gui.FrameIO; 54 import org.expeditee.gui.FrameMouseActions;55 45 import org.expeditee.gui.FrameUtils; 56 import org.expeditee.items.widgets.InteractiveWidget;57 import org.expeditee.stats.Logger;58 46 59 47 /** … … 75 63 */ 76 64 public class Picture extends XRayable { 65 66 private static final float CROPPING_COMPOSITE_ALPHA = 0.5f; 77 67 78 68 private static final int MINIMUM_WIDTH = 10; … … 114 104 private String _fileName = null; 115 105 116 // used to repaint animated GIF images, among other things. 117 protected ImageObserver _imageObserver = null; 118 119 protected Picture(Text source, ImageObserver observer, Image image) { 106 protected Picture(Text source, Image image) { 120 107 super(source); 121 _imageObserver = observer;122 108 _image = image; 123 109 … … 150 136 * screen. 151 137 */ 152 public Picture(Text source, String fileName, String path, String size ,153 ImageObserver observer){138 public Picture(Text source, String fileName, String path, String size) 139 { 154 140 super(source); 155 _imageObserver = observer;156 141 _fileName = fileName; 157 142 _path = path; … … 226 211 227 212 // set the default values for start and end 228 _start.set Location(0, 0);213 _start.set(0, 0); 229 214 if (_image == null) 230 _end.set Location(0, 0);215 _end.set(0, 0); 231 216 else 232 _end.set Location(_image.getWidth(null), _image.getHeight(null));217 _end.set(_image.getWidth(), _image.getHeight()); 233 218 size = size.trim(); 234 219 String sizeLower = size.toLowerCase(); … … 272 257 try { 273 258 if (size.length() == 0) { 274 size = "" + _image.getWidth( null);259 size = "" + _image.getWidth(); 275 260 _source.setText(getTagText() + size); 276 261 return; … … 293 278 } 294 279 280 public void setStartCrop(Point p) 281 { 282 if (p != null) setStartCrop(p.x, p.y); 283 } 284 295 285 public void setStartCrop(int x, int y) { 296 286 invalidateCroppedArea(); 297 287 _cropStart = new Point(x - getX(), y - getY()); 298 288 invalidateCroppedArea(); 289 } 290 291 public void setEndCrop(Point p) 292 { 293 if (p != null) setEndCrop(p.x, p.y); 299 294 } 300 295 … … 312 307 int startY = getY() + topLeft.y - _highlightThickness; 313 308 int border = 2 * _highlightThickness; 314 invalidate(new Rectangle(startX, startY, bottomRight.x - topLeft.x 315 + 2 * border, bottomRight.y - topLeft.y + 2 * border)); 309 // TODO: Why invalidate specific area just before invalidateAll? cts16 310 invalidate(new AxisAlignedBoxBounds(startX, startY, 311 bottomRight.x - topLeft.x + 2 * border, bottomRight.y - topLeft.y + 2 * border)); 316 312 invalidateAll(); 317 313 } else { … … 325 321 } 326 322 327 public Point getBottomRightCrop() {328 return new Point(Math.max(_cropStart.x, _cropEnd.x), Math.max(329 323 public Point getBottomRightCrop() 324 { 325 return new Point(Math.max(_cropStart.x, _cropEnd.x), Math.max(_cropStart.y, _cropEnd.y)); 330 326 } 331 327 … … 335 331 invalidateCroppedArea(); 336 332 } 337 338 public boolean isCropTooSmall() { 339 if (_cropStart == null || _cropEnd == null) 340 return true; 333 334 public boolean isBeingCropped() 335 { 336 return (_cropStart != null && _cropEnd != null); 337 } 338 339 public boolean isCropTooSmall() 340 { 341 if (!isBeingCropped()) return true; 341 342 342 343 int cropWidth = Math.abs(_cropEnd.x - _cropStart.x); … … 353 354 } 354 355 355 public void updatePolygon() { 356 public PolygonBounds updateBounds() 357 { 356 358 if (_image == null) { 357 359 refresh(); … … 360 362 361 363 Point[] ori = new Point[4]; 362 Point2D[] rot = new Point2D[4];363 364 Point centre = new Point(); 364 365 … … 393 394 centre.y = base_y + (bottomRight.y - topLeft.y) / 2; 394 395 395 Rectangle clip = new Rectangle(topLeft.x + base_x,396 AxisAlignedBoxBounds clip = new AxisAlignedBoxBounds(topLeft.x + base_x, 396 397 topLeft.y + base_y, bottomRight.x - topLeft.x, 397 bottomRight.y - topLeft.y) .getBounds();398 bottomRight.y - topLeft.y); 398 399 // _poly.addPoint((int) clip.getMinX() - 1, (int) clip.getMinY() - 1); 399 400 // _poly.addPoint((int) clip.getMinX() - 1, (int) clip.getMaxY()); … … 408 409 } 409 410 410 AffineTransform.getRotateInstance(Math.PI * _rotate / 180, centre.x, centre.y).transform(ori, 0, rot, 0, 4); 411 412 _poly = new Polygon(); 413 for(Point2D p : rot) { 414 _poly.addPoint((int)p.getX(), (int)p.getY()); 415 } 411 PolygonBounds poly = new PolygonBounds(); 412 for (Point p : ori) { 413 poly.addPoint(p); 414 } 415 poly.rotate(Math.PI * _rotate / 180, centre); 416 417 return poly.close(); 416 418 } 417 419 … … 454 456 */ 455 457 @Override 456 protected void paintLink( Graphics2D g) {457 if (FrameGraphics.isAudienceMode())458 459 super.paintLink( g);460 } 461 462 public void paintImageTiling(Graphics2D g) {463 if (_image == null) {464 return;465 }466 467 i nt iw = _image.getWidth(null);468 int ih = _image.getHeight(null);469 i f(iw <= 0 || ih <= 0) {470 return;471 }472 473 int base_x = (_anchorLeft !=null) ? _anchorLeft : _source.getX();474 int base_y = (_anchorTop !=null) ? _anchorTop : _source.getY();458 protected void paintLink() 459 { 460 if (DisplayController.isAudienceMode()) return; 461 super.paintLink(); 462 } 463 464 /** 465 * Paint the image repeatedly tiled over the drawing area. 466 */ 467 public void paintImageTiling() 468 { 469 if (_image == null) return; 470 471 int iw = _image.getWidth(); 472 int ih = _image.getHeight(); 473 if(iw <= 0 || ih <= 0) return; 474 475 int base_x = (_anchorLeft != null) ? _anchorLeft : _source.getX(); 476 int base_y = (_anchorTop != null) ? _anchorTop : _source.getY(); 475 477 476 478 int dX1 = base_x; … … 479 481 int dY2 = base_y + getHeight(); 480 482 481 BufferedImage tmp = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); 482 Graphics2D g2d = tmp.createGraphics(); 483 Image tmp = Image.createImage(getWidth(), getHeight()); 484 EcosystemManager.getGraphicsManager().pushDrawingSurface(tmp); 485 483 486 int offX = (tmp.getWidth() - getWidth()) / 2; 484 487 int offY = (tmp.getHeight() - getHeight()) / 2; 485 486 // g2d.rotate(rotate, tmp.getWidth() / 2, tmp.getHeight() / 2);487 488 488 489 int cropStartX = _start.x; … … 491 492 cropEndX = iw; 492 493 } 494 493 495 for(int x = dX1; x < dX2; ) { 494 496 // end - start = (cropEnd - cropStart) * scale … … 506 508 cropEndY = ih; 507 509 } 510 508 511 for(int y = dY1; y < dY2; ) { 509 512 int h = (int) ((cropEndY - cropStartY) * _scale); … … 518 521 int sy = _flipY ? cropEndY : cropStartY; 519 522 int ey = _flipY ? cropStartY : cropEndY; 520 g2d.drawImage(_image, x - dX1 + offX, y - dY1 + offY, endX - dX1 + offX, endY - dY1 + offY, sx, sy, ex, ey, null); 523 524 Point topLeft = new Point(x - dX1 + offX, y - dY1 + offY); 525 Dimension size = new Dimension(endX - x, endY - y); 526 Point cropTopLeft = new Point(sx, sy); 527 Dimension cropSize = new Dimension(ex - sx, ey - sy); 528 if (cropSize.width > 0 && cropSize.height > 0) { 529 EcosystemManager.getGraphicsManager().drawImage(_image, topLeft, size, 0.0, cropTopLeft, cropSize); 530 } 521 531 522 532 cropStartY = 0; … … 531 541 x = endX; 532 542 } 533 534 AffineTransform at = new AffineTransform();535 at.translate(dX1, dY1);536 at.rotate(Math.PI * _rotate / 180, tmp.getWidth() / 2, tmp.getHeight() / 2);537 g.drawImage(tmp, at, _imageObserver);538 // g.drawImage(tmp, dX1, dY1, dX2, dY2, 0, 0, tmp.getWidth(), tmp.getHeight(), _imageObserver); 539 }540 541 @Override542 public void paint(Graphics2D g) {543 if (_image == null) 544 return;545 546 paintLink(g);547 548 // if we are showing the cropping , then show the original as transparent543 544 EcosystemManager.getGraphicsManager().popDrawingSurface(); 545 EcosystemManager.getGraphicsManager().drawImage(tmp, new Point(dX1, dY1), null, Math.PI * _rotate / 180); 546 tmp.releaseImage(); 547 } 548 549 @Override 550 public void paint() 551 { 552 if (_image == null) return; 553 554 paintLink(); 555 556 GraphicsManager g = EcosystemManager.getGraphicsManager(); 557 558 // if we are showing the cropping 549 559 if (_showCropping && !isCropTooSmall()) { 550 // show the full image as transparent 551 float alpha = .5f; 552 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 553 alpha)); 554 555 paintImageTiling(g); 556 557 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 558 1.0f)); 560 // show the uncropped area as transparent 561 g.setCompositeAlpha(CROPPING_COMPOSITE_ALPHA); 562 paintImageTiling(); 563 g.setCompositeAlpha(1.0f); 564 559 565 // show the cropped area normally 560 566 Point topLeft = getTopLeftCrop(); 561 567 Point bottomRight = getBottomRightCrop(); 562 int base_x = (_anchorLeft!=null) ? _anchorLeft : _source.getX(); 563 int base_y = (_anchorTop!=null) ? _anchorTop : _source.getY(); 564 565 Shape clip = new Rectangle(base_x + topLeft.x, base_y + topLeft.y, 566 bottomRight.x - topLeft.x, bottomRight.y - topLeft.y); 567 g.setColor(getPaintHighlightColor()); 568 g.draw(clip); 569 g.setClip(clip); 570 571 paintImageTiling(g); 572 573 g.draw(clip); 574 // if the image is cropped, but we are not showing the cropping 575 // otherwise, paint normally 568 int base_x = (_anchorLeft != null) ? _anchorLeft : _source.getX(); 569 int base_y = (_anchorTop != null) ? _anchorTop : _source.getY(); 570 571 Clip clip = new Clip(new AxisAlignedBoxBounds( base_x + topLeft.x, 572 base_y + topLeft.y, 573 bottomRight.x - topLeft.x, 574 bottomRight.y - topLeft.y)); 575 EnforcedClipKey key = g.pushClip(clip); 576 paintImageTiling(); 577 g.popClip(key); 578 579 // Draw an outline for the crop selection box 580 g.drawRectangle(clip.getBounds(), 0.0, null, getPaintHighlightColor(), HIGHLIGHT_STROKE, null); 581 582 // otherwise, paint normally 576 583 } else { 577 paintImageTiling(g); 578 } 579 584 paintImageTiling(); 585 } 586 587 PolygonBounds poly = (PolygonBounds) getBounds(); 588 580 589 if (hasVisibleBorder()) { 581 g.setColor(getPaintBorderColor()); 582 Stroke borderStroke = new BasicStroke(getThickness(), CAP, JOIN); 583 g.setStroke(borderStroke); 584 g.drawPolygon(getPolygon()); 590 Stroke borderStroke = new Stroke(getThickness(), DEFAULT_CAP, DEFAULT_JOIN); 591 g.drawPolygon(poly, null, null, 0.0, null, getPaintBorderColor(), borderStroke); 585 592 } 586 593 587 594 if (isHighlighted()) { 588 Stroke borderStroke = new BasicStroke(1, CAP, JOIN); 589 g.setStroke(borderStroke); 590 g.setColor(getHighlightColor()); 591 g.drawPolygon(getPolygon()); 592 } 593 594 //System.out.print("p_"); 595 } 596 597 @Override 598 public Color getHighlightColor() { 599 if (_highlightColor.equals(getBorderColor())) 600 return ALTERNATE_HIGHLIGHT; 601 return _highlightColor; 602 } 603 604 @Override 605 public int setHighlightColor() { 606 super.setHighlightColor(); 607 608 return Item.DEFAULT_CURSOR; 609 } 610 611 protected Picture createPicture() { 612 return ItemUtils.CreatePicture((Text) _source.copy(), _imageObserver); 595 Stroke borderStroke = new Stroke(1, DEFAULT_CAP, DEFAULT_JOIN); 596 g.drawPolygon(poly, null, null, 0.0, null, getHighlightColor(), borderStroke); 597 } 598 } 599 600 @Override 601 public Colour getHighlightColor() 602 { 603 if (_highlightColour.equals(getBorderColor())) return ALTERNATE_HIGHLIGHT; 604 return _highlightColour; 605 } 606 607 protected Picture createPicture() 608 { 609 return ItemUtils.CreatePicture((Text) _source.copy()); 613 610 } 614 611 … … 617 614 Picture p = createPicture(); 618 615 p._image = _image; 619 p._ mode = _mode;616 p._highlightMode = _highlightMode; 620 617 // Doing Duplicate item duplicates link mark which we dont want to do 621 618 // when in audience mode because the linkMark will be copied incorrectly … … 632 629 int endX = Math.round(bottomRight.x / _scale + _start.x); 633 630 int endY = Math.round(bottomRight.y / _scale + _start.y); 634 int width = _image.getWidth( null);635 int height = _image.getHeight( null);631 int width = _image.getWidth(); 632 int height = _image.getHeight(); 636 633 // adjust our start and end if the user has dragged outside of the 637 634 // shape … … 663 660 664 661 p.updateSource(); 665 p. updatePolygon();662 p.invalidateBounds(); 666 663 667 664 return p; … … 678 675 public void scaleCrop() { 679 676 // scale crop values to within image bounds 680 int iw = _image.getWidth( null);681 int ih = _image.getHeight( null);677 int iw = _image.getWidth(); 678 int ih = _image.getHeight(); 682 679 if(iw > 0 || ih > 0) { 683 680 while(_start.x >= iw) { … … 723 720 _scale = oldScale; 724 721 } else { 725 _source.translate(new Point2D.Float(FrameMouseActions.MouseX, 726 FrameMouseActions.MouseY), multiplier); 722 _source.translate(EcosystemManager.getInputManager().getCursorPosition(), multiplier); 727 723 } 728 724 updateSource(); 729 updatePolygon();725 invalidateBounds(); 730 726 // Make sure items that are resized display the border 731 727 invalidateAll(); … … 753 749 } 754 750 755 return Toolkit.getDefaultToolkit().createImage( 756 new FilteredImageSource(_image.getSource(), 757 new CropImageFilter(_start.x, _start.y, 758 getUnscaledWidth(), getUnscaledHeight()))); 751 return Image.createImageAsCroppedCopy(_image, _start.x, _start.y, getUnscaledWidth(), getUnscaledHeight()); 759 752 } 760 753 … … 771 764 */ 772 765 public boolean isCropped() { 773 return (_end.x != 0 && _end.x != _image.getWidth( null)) || (_end.y != 0 && _end.y != _image.getHeight(null)) || _start.y != 0 || _start.x != 0;766 return (_end.x != 0 && _end.x != _image.getWidth()) || (_end.y != 0 && _end.y != _image.getHeight()) || _start.y != 0 || _start.x != 0; 774 767 } 775 768 … … 779 772 // (notably.bmp) hence, we try this first, then if it fails we try 780 773 // ImageIO 774 /* 781 775 try { 782 776 _image = new ImageIcon(_path).getImage(); … … 785 779 786 780 // if ImageIcon failed to read the image 787 if (_image == null || _image.getWidth( null) <= 0) {781 if (_image == null || _image.getWidth() <= 0) { 788 782 try { 789 783 _image = ImageIO.read(new File(_path)); … … 795 789 } 796 790 } 791 */ 792 _image = Image.getImage(_path); 797 793 return true; 798 794 } … … 827 823 @Override 828 824 public boolean getLinkMark() { 829 return ! FrameGraphics.isAudienceMode() && _source.getLinkMark();825 return !DisplayController.isAudienceMode() && _source.getLinkMark(); 830 826 } 831 827 … … 892 888 // If the image is cropped add the position for the start and finish of 893 889 // the crop to the soure text 894 if (_start.x > 0 || _start.y > 0 || _end.x != _image.getWidth( null)895 || _end.y != _image.getHeight( null)) {890 if (_start.x > 0 || _start.y > 0 || _end.x != _image.getWidth() 891 || _end.y != _image.getHeight()) { 896 892 newText.append(" ").append(_start.x).append(" ").append(_start.y); 897 893 newText.append(" ").append(_end.x).append(" ").append(_end.y); … … 912 908 913 909 @Override 914 public void translate(Point 2Dorigin, double ratio) {910 public void translate(Point origin, double ratio) { 915 911 _scale *= ratio; 916 912 updateSource(); … … 919 915 920 916 @Override 921 public Rectangle[]getDrawingArea() {922 923 Rectangle[]da = super.getDrawingArea();917 public AxisAlignedBoxBounds getDrawingArea() { 918 919 AxisAlignedBoxBounds da = super.getDrawingArea(); 924 920 925 921 if (getLink() != null || hasAction()) { 926 Rectangle[] da2 = new Rectangle[da.length + 1]; 927 System.arraycopy(da, 0, da2, 0, da.length); 928 da2[da.length] = getLinkPoly().getBounds(); 929 da2[da.length].translate(getX() - LEFT_MARGIN, getY() 930 + getLinkYOffset()); 931 da2[da.length].width += 2; 932 da2[da.length].height += 2; 933 da = da2; 922 AxisAlignedBoxBounds linkBounds = AxisAlignedBoxBounds.getEnclosing(getLinkBounds()); 923 linkBounds.getTopLeft().add(getX() - LEFT_MARGIN, getY() + getLinkYOffset()); 924 linkBounds.getSize().width += 2; 925 linkBounds.getSize().height += 2; 926 da.combineWith(linkBounds); 934 927 } 935 928 … … 963 956 _rotate = rotate; 964 957 updateSource(); 965 updatePolygon();958 invalidateBounds(); 966 959 } 967 960 … … 970 963 } 971 964 972 public boolean MouseOverBackgroundPixel(int mouseX, int mouseY, Color bg_col) 973 { 974 int[] pixels = new int[1]; 975 965 public boolean MouseOverBackgroundPixel(int mouseX, int mouseY, Colour bg_col) 966 { 976 967 int base_x = (_anchorLeft!=null) ? _anchorLeft : _source.getX(); 977 968 int base_y = (_anchorTop!=null) ? _anchorTop : _source.getY(); … … 979 970 int y = mouseY - base_y; 980 971 981 // Consider making this a slightly larger area to check, say 3 x 3? 982 // Back op if all are the same sought after color? 983 PixelGrabber grabber = new PixelGrabber(_image, x,y, 1, 1, pixels, 0, 1); 984 985 // The following might be a better approach, as it sets the color model 986 // when getPixels() is called, however, it might return an int[] or byte[] 987 // array (handled as Object), as so some extra complexity would exist in 988 // handling the returned result 989 990 //PixelGrabber pg = new PixelGrabber(_image, mouseX, mouseY, 1, 1, true); 991 992 try { 993 grabber.grabPixels(0); 994 } 995 catch (Exception e) { 996 e.printStackTrace(); 997 } 998 999 1000 int c = pixels[0]; 1001 int c_red = (c & 0x00ff0000) >> 16; 1002 int c_green = (c & 0x0000ff00) >> 8; 1003 int c_blue = c & 0x000000ff; 1004 1005 int bg_red = (bg_col!=null) ? bg_col.getRed() : 0xff; 1006 int bg_green = (bg_col!=null) ? bg_col.getGreen() : 0xff; 1007 int bg_blue = (bg_col!=null) ? bg_col.getBlue() : 0xff; 972 Colour c = _image.getPixel(x, y); 973 974 int c_red = c.getRed255(); 975 int c_green = c.getGreen255(); 976 int c_blue = c.getBlue255(); 977 978 int bg_red = (bg_col!=null) ? bg_col.getRed255() : 0xff; 979 int bg_green = (bg_col!=null) ? bg_col.getGreen255() : 0xff; 980 int bg_blue = (bg_col!=null) ? bg_col.getBlue255() : 0xff; 1008 981 1009 982 int red_diff = Math.abs(c_red - bg_red); -
trunk/src/org/expeditee/items/Tooltip.java
r977 r1102 9 9 import org.expeditee.settings.templates.TemplateSettings; 10 10 11 /** 12 * TODO: Comment. cts16 13 * 14 * @author cts16 15 */ 11 16 public class Tooltip { 17 18 /** TODO: Comment. cts16 */ 19 private Map<Text, Item> _tooltipItems = new HashMap<Text, Item>(); 12 20 13 Tooltip() { } 14 15 private Map<Text, Item> tooltipItems = new HashMap<Text, Item>(); 16 17 public Text addTooltip(String content, final Item toItem) { 18 if(content.trim().toLowerCase().startsWith("text") && content.contains(":")) 21 /** TODO: Comment. cts16 */ 22 Tooltip() 23 { 24 } 25 26 /** TODO: Comment. cts16 */ 27 public Text addTooltip(String content, final Item toItem) 28 { 29 if(content.trim().toLowerCase().startsWith("text") && content.contains(":")) { 19 30 content = content.substring(content.indexOf(':') + 1); 31 } 20 32 final Text tooltip = TemplateSettings.TooltipTemplate.get().copy(); 33 tooltip.setWidth(Integer.MAX_VALUE); // Tooltip shouldn't be width-limited 21 34 tooltip.setText(content); 22 35 return addTooltip(tooltip, toItem); 23 36 } 24 25 public Text addTooltip(final Text tooltip, final Item toItem) { 26 tooltipItems.put(tooltip, toItem); 37 38 /** TODO: Comment. cts16 */ 39 public Text addTooltip(final Text tooltip, final Item toItem) 40 { 41 _tooltipItems.put(tooltip, toItem); 27 42 return tooltip; 28 43 } 29 30 public Collection<Text> getTooltips() { return tooltipItems.keySet(); } 31 32 public List<String> asStringList() { 44 45 /** TODO: Comment. cts16 */ 46 public Collection<Text> getTooltips() 47 { 48 return _tooltipItems.keySet(); 49 } 50 51 /** TODO: Comment. cts16 */ 52 public List<String> asStringList() 53 { 33 54 final List<String> ret = new LinkedList<String>(); 34 for(final Text tooltip: tooltipItems.keySet()) ret.add(tooltip.getText());55 for(final Text tooltip: _tooltipItems.keySet()) ret.add(tooltip.getText()); 35 56 return ret; 36 57 } 37 38 public int getWidth() { 58 59 /** TODO: Comment. cts16 */ 60 public int getWidth() 61 { 39 62 int max = 0; 40 for(final Text tooltip: tooltipItems.keySet())63 for(final Text tooltip: _tooltipItems.keySet()) { 41 64 if(tooltip.getBoundsWidth() > max) max = tooltip.getBoundsWidth(); 65 } 42 66 return max; 43 67 } 44 68 45 public int getHeight() { 69 /** TODO: Comment. cts16 */ 70 public int getHeight() 71 { 46 72 int max = 0; 47 for(final Text tooltip: tooltipItems.keySet())73 for(final Text tooltip: _tooltipItems.keySet()) { 48 74 if(tooltip.getBoundsWidth() > max) max = tooltip.getBoundsHeight(); 75 } 49 76 return max; 50 77 } 51 52 public int getCollectiveHeight() { 78 79 /** TODO: Comment. cts16 */ 80 public int getCollectiveHeight() 81 { 53 82 int height = 0; 54 for(final Text tooltip: tooltipItems.keySet()) height += tooltip.getBoundsHeight();83 for(final Text tooltip: _tooltipItems.keySet()) height += tooltip.getBoundsHeight(); 55 84 return height; 56 85 } -
trunk/src/org/expeditee/items/XRayable.java
r919 r1102 19 19 package org.expeditee.items; 20 20 21 import java.awt.Color;22 import java.awt.geom.Point2D;23 21 import java.util.Collection; 24 22 import java.util.LinkedList; 25 23 import java.util.List; 26 24 25 import org.expeditee.core.Colour; 26 import org.expeditee.core.Point; 27 import org.expeditee.gui.DisplayController; 27 28 import org.expeditee.gui.FrameGraphics; 28 29 … … 101 102 102 103 @Override 103 public Colo r getColor() {104 public Colour getColor() { 104 105 return _source.getColor(); 105 106 } 106 107 107 108 @Override 108 public void setColor(Colo r c) {109 public void setColor(Colour c) { 109 110 _source.setColor(c); 110 111 invalidateCommonTrait(ItemAppearence.ForegroundColorChanged); … … 112 113 113 114 @Override 114 public void setBackgroundColor(Colo r c) {115 public void setBackgroundColor(Colour c) { 115 116 _source.setBackgroundColor(c); 116 117 } 117 118 118 119 @Override 119 public void setFillColor(Colo r c) {120 public void setFillColor(Colour c) { 120 121 _source.setFillColor(c); 121 122 } 122 123 123 124 @Override 124 public void setBorderColor(Colo r c) {125 public void setBorderColor(Colour c) { 125 126 _source.setBorderColor(c); 126 127 invalidateCommonTrait(ItemAppearence.BorderColorChanged); … … 128 129 129 130 @Override 130 public void setGradientColor(Colo r c) {131 public void setGradientColor(Colour c) { 131 132 _source.setGradientColor(c); 132 133 } … … 153 154 154 155 @Override 155 public FloatgetAnchorLeft() {156 public Integer getAnchorLeft() { 156 157 return _source.getAnchorLeft(); 157 158 } 158 159 159 160 @Override 160 public FloatgetAnchorRight() {161 public Integer getAnchorRight() { 161 162 return _source.getAnchorRight(); 162 163 } 163 164 164 165 @Override 165 public FloatgetAnchorTop() {166 public Integer getAnchorTop() { 166 167 return _source.getAnchorTop(); 167 168 } 168 169 169 170 @Override 170 public FloatgetAnchorBottom() {171 public Integer getAnchorBottom() { 171 172 return _source.getAnchorBottom(); 172 173 } … … 174 175 175 176 @Override 176 public Colo r getBorderColor() {177 public Colour getBorderColor() { 177 178 return _source.getBorderColor(); 178 179 } … … 186 187 187 188 @Override 188 public Colo r getBackgroundColor() {189 public Colour getBackgroundColor() { 189 190 return _source.getBackgroundColor(); 190 191 } 191 192 192 193 @Override 193 public Colo r getFillColor() {194 public Colour getFillColor() { 194 195 return _source.getFillColor(); 195 196 } 196 197 197 198 @Override 198 public Colo r getGradientColor() {199 public Colour getGradientColor() { 199 200 return _source.getGradientColor(); 200 201 } … … 226 227 invalidateAll(); 227 228 _source.setLink(frameName); 228 updatePolygon();229 invalidateBounds(); 229 230 //TODO: only invalidate the link bit 230 231 invalidateAll(); … … 239 240 invalidateAll(); 240 241 _source.setActions(action); 241 updatePolygon();242 invalidateBounds(); 242 243 invalidateAll(); 243 244 } … … 252 253 253 254 @Override 254 public void translate(Point 2Dorigin, double ratio){255 public void translate(Point origin, double ratio){ 255 256 //_source.translate(origin, ratio); 256 updatePolygon();257 invalidateBounds(); 257 258 } 258 259 … … 279 280 280 281 @Override 281 public void setAnchorTop( Floatanchor) {282 public void setAnchorTop(Integer anchor) { 282 283 _source.setAnchorTop(anchor); 283 284 if (anchor != null) … … 286 287 287 288 @Override 288 public void setAnchorBottom( Floatanchor) {289 public void setAnchorBottom(Integer anchor) { 289 290 _source.setAnchorBottom(anchor); 290 291 if (anchor != null) 291 _source.setY( FrameGraphics.getMaxFrameSize().height- getHeight() - anchor);292 } 293 294 295 @Override 296 public void setAnchorLeft( Floatanchor) {292 _source.setY(DisplayController.getFramePaintArea().getHeight() - getHeight() - anchor); 293 } 294 295 296 @Override 297 public void setAnchorLeft(Integer anchor) { 297 298 _source.setAnchorLeft(anchor); 298 299 } 299 300 300 301 @Override 301 public void setAnchorRight( Floatanchor) {302 public void setAnchorRight(Integer anchor) { 302 303 _source.setAnchorRight(anchor); 303 _source.setX( FrameGraphics.getMaxFrameSize().width- anchor - this.getWidth());304 _source.setX(DisplayController.getFramePaintArea().getWidth() - anchor - this.getWidth()); 304 305 } 305 306 -
trunk/src/org/expeditee/items/widgets/ButtonWidget.java
r1005 r1102 1 1 package org.expeditee.items.widgets; 2 2 import java.awt.BorderLayout; 3 import java.awt.Color;4 3 import java.awt.Dimension; 5 4 import java.net.URL; … … 9 8 import javax.swing.border.EmptyBorder; 10 9 10 import org.expeditee.core.Colour; 11 import org.expeditee.gio.swing.SwingConversions; 11 12 import org.expeditee.items.Text; 12 13 … … 14 15 15 16 //Will be the default class for Rubbish Bin, Reset and Undo Button Widgets 16 public class ButtonWidget extends InteractiveWidget{17 17 public class ButtonWidget extends SwingWidget 18 { 18 19 protected JButton clicked_ = new JButton(""); 19 20 protected SVGIcon icon_ = null; 20 21 21 22 public ButtonWidget(int dimension, String filePath, Text source, String[] args) 22 23 { … … 25 26 26 27 clicked_.setBorder(new EmptyBorder(0, 0, 0, 0)); 27 clicked_.setBackground( Color.white);28 clicked_.setBackground(SwingConversions.toSwingColor(Colour.WHITE)); 28 29 29 30 Dimension size = new Dimension(dimension, dimension); 30 31 icon_ = new SVGIcon(); 31 try{ 32 33 try { 32 34 URL imageURL = ClassLoader.getSystemResource(filePath); 33 35 icon_.setSvgURI(imageURL.toURI()); 34 // This STILL works, unsure why. Don't remove it has an affect on the button appearance.36 // This STILL works, unsure why. Don't remove it has an affect on the button appearance. 35 37 icon_.setUseAntiAlias(true); 36 38 icon_.setScaleToFit(true); … … 39 41 _swingComponent.add(clicked_); 40 42 this.setWidgetEdgeThickness(0.0f); 41 this.setWidgetEdgeColor(Color.white); 42 } 43 catch(Exception e){ 44 43 this.setWidgetEdgeColor(Colour.WHITE); 44 } catch(Exception e) { 45 45 //Set a default image if image is missing 46 46 System.out.println("Unable to load image from directory"); … … 49 49 50 50 @Override 51 protected String[] getArgs() { 51 protected String[] getArgs() 52 { 52 53 // TODO Auto-generated method stub 53 54 return null; 54 55 } 55 public boolean itemHeldWhileClicked(InteractiveWidget bw) { 56 57 public boolean itemHeldWhileClicked(Widget bw) 58 { 56 59 // TODO Auto-generated method stub 57 60 return false; 58 61 } 59 public boolean getdropInteractableStatus(){ 62 63 public boolean getdropInteractableStatus() 64 { 60 65 return false; 61 66 } 62 67 63 68 @Override 64 boolean setPositions(WidgetCorner src, float x, float y) { 69 public boolean setPositions(WidgetCorner src, float x, float y) 70 { 65 71 boolean result = super.setPositions(src, x, y); 66 72 -
trunk/src/org/expeditee/items/widgets/DataFrameWidget.java
r919 r1102 19 19 package org.expeditee.items.widgets; 20 20 21 import java.awt.Color;22 import java.awt.Graphics;23 21 import java.util.Collection; 24 22 import java.util.HashSet; … … 26 24 import javax.swing.JComponent; 27 25 28 import org.expeditee.gui.DisplayIO; 26 import org.expeditee.core.Colour; 27 import org.expeditee.core.Point; 28 import org.expeditee.gio.EcosystemManager; 29 import org.expeditee.gio.GraphicsManager; 30 import org.expeditee.gui.DisplayController; 29 31 import org.expeditee.gui.Frame; 30 32 import org.expeditee.gui.FrameIO; … … 34 36 import org.expeditee.items.Text; 35 37 36 public abstract class DataFrameWidget extends InteractiveWidget implements38 public abstract class DataFrameWidget extends SwingWidget implements 37 39 FrameObserver { 38 40 … … 118 120 public void update() { 119 121 Frame parent = getParentFrame(); 120 if (parent != null && parent == Display IO.getCurrentFrame()) {122 if (parent != null && parent == DisplayController.getCurrentFrame()) { 121 123 refresh(); 122 124 } … … 166 168 } 167 169 168 protected void paintInFreeSpace( Graphics g) {169 super.paintInFreeSpace(g);170 g.setFont(((Text) getSource()).getFont());171 g.setColor(Color.WHITE);172 g.drawString(this.getClass().getSimpleName(), getX() + 10, getY() + 20);170 protected void paintInFreeSpace() 171 { 172 super.paintInFreeSpace(); 173 GraphicsManager g = EcosystemManager.getGraphicsManager(); 174 g.drawString(this.getClass().getSimpleName(), new Point(getX() + 10, getY() + 20), ((Text) getSource()).getFont(), Colour.WHITE); 173 175 174 176 } -
trunk/src/org/expeditee/items/widgets/HeavyDutyInteractiveWidget.java
r1046 r1102 19 19 package org.expeditee.items.widgets; 20 20 21 import java.awt.Color;22 21 import java.awt.Font; 23 22 import java.awt.FontMetrics; … … 33 32 import javax.swing.SwingUtilities; 34 33 34 import org.expeditee.core.Colour; 35 import org.expeditee.gio.swing.SwingConversions; 36 import org.expeditee.gio.swing.SwingGraphicsManager; 37 import org.expeditee.gio.swing.SwingMiscManager; 35 38 import org.expeditee.gui.Browser; 36 import org.expeditee.gui.DisplayIO; 37 import org.expeditee.gui.FrameGraphics; 39 import org.expeditee.gui.DisplayController; 38 40 import org.expeditee.gui.FreeItems; 39 41 import org.expeditee.items.Item; … … 53 55 * until expeditee allocates a thread to begin loading. The swing component is set as not-visible. 54 56 * 55 * At the the loading stage, a loadable widget proc cesses its load task and renders a57 * At the the loading stage, a loadable widget processes its load task and renders a 56 58 * load message/bar. 57 59 * … … 59 61 * 60 62 * When a HeavyDutyInteractiveWidget becomes visible / is anchored, it will register itself for saving at the next 61 * save point according to SaveEntityManager. Heav ey duty widgets will only save at the save points63 * save point according to SaveEntityManager. Heavy duty widgets will only save at the save points 62 64 * if the widget still belongs to a frame (i.e. is not removed) and is anchored. 63 65 * 64 * Heav ey duty widgets can also have an expiry on how long they should stay cached for. If they do have an66 * Heavy duty widgets can also have an expiry on how long they should stay cached for. If they do have an 65 67 * expiry then it they unload once expired, and will re-load once in view again. Must take care for 66 68 * unloadable widgets because you must check your unloadable elements to whether they are unloaded or not 67 * every time your widget accesses sthem.69 * every time your widget accesses them. 68 70 * 69 71 * When a heavy duty widget is deleted - any data consuming memory can be dumped temporarily if needed. … … 72 74 * 73 75 */ 74 public abstract class HeavyDutyInteractiveWidget extends InteractiveWidget implements LoadableEntity, SaveableEntity {76 public abstract class HeavyDutyInteractiveWidget extends SwingWidget implements LoadableEntity, SaveableEntity { 75 77 76 78 /** load finished */ … … 90 92 private static final String PENDING_MESSAGE = "Pending"; 91 93 92 private static final Colo r LOAD_BAR_PROGRESS_COLOR = new Color(103, 171, 203);93 private static final Colo r LOAD_BAR_INDETERM_COLOR = Color.ORANGE;94 private static final Colo r LOAD_BAR_HIGHLIGHT_COLOR = new Color(240, 240, 240);95 private static final Colo r LOAD_SCREEN_COLOR = Color.LIGHT_GRAY;96 private static final Colo r LOAD_SCREEN_COLOR_FREESPACE = FREESPACE_BACKCOLOR;94 private static final Colour LOAD_BAR_PROGRESS_COLOR = Colour.FromRGB255(103, 171, 203); 95 private static final Colour LOAD_BAR_INDETERM_COLOR = Colour.ORANGE; 96 private static final Colour LOAD_BAR_HIGHLIGHT_COLOR = Colour.FromRGB255(240, 240, 240); 97 private static final Colour LOAD_SCREEN_COLOR = Colour.LIGHT_GREY; 98 private static final Colour LOAD_SCREEN_COLOR_FREESPACE = FREESPACE_BACKCOLOR; 97 99 98 100 private static final Font LOAD_NORMAL_FONT = new Font("Arial", Font.BOLD, 12); … … 140 142 */ 141 143 protected HeavyDutyInteractiveWidget(Text source, JComponent component, 142 int minWidth, int maxWidth, int minHeight, int maxHeight, int cacheDepth, boolean skipLoad) { 144 int minWidth, int maxWidth, int minHeight, int maxHeight, int cacheDepth, boolean skipLoad) 145 { 143 146 super(source, component, minWidth, maxWidth, minHeight, maxHeight); 144 147 … … 173 176 * 174 177 * @param percent 175 * Must be between 0.0 and 1.0 inclusive for percentage. Or ne agtive if indeterminant.178 * Must be between 0.0 and 1.0 inclusive for percentage. Or negative if indeterminate. 176 179 * 177 180 * @throws IllegalArgumentException … … 182 185 * 183 186 */ 184 protected final void updateLoadPercentage(float percent) { 187 protected final void updateLoadPercentage(float percent) 188 { 185 189 if (percent > 1.0f) 186 190 throw new IllegalArgumentException("loadState is larger than 1.0"); … … 199 203 * @return The current load state. 200 204 */ 201 protected float getLoadState() { 205 protected float getLoadState() 206 { 202 207 return loadState; 203 208 } … … 206 211 * @return True if in a loading phase. 207 212 */ 208 protected boolean isInLoadProgress() { 213 protected boolean isInLoadProgress() 214 { 209 215 return loadState <= 1.0f; 210 216 } … … 226 232 227 233 // Re-render loading state 228 FrameGraphics.invalidateArea(_swingComponent.getBounds());229 FrameGraphics.requestRefresh(true);234 DisplayController.invalidateArea(getBounds()); 235 DisplayController.requestRefresh(true); 230 236 } 231 237 232 238 @Override 233 public void paintInFreeSpace( Graphics g) {234 if (loadState == LOAD_STATE_COMPLETED) super.paintInFreeSpace( g);235 else paintLoadScreen( g,LOAD_SCREEN_COLOR_FREESPACE);239 public void paintInFreeSpace() { 240 if (loadState == LOAD_STATE_COMPLETED) super.paintInFreeSpace(); 241 else paintLoadScreen(LOAD_SCREEN_COLOR_FREESPACE); 236 242 } 237 243 238 244 @Override 239 public void paint(Graphics g) { 245 protected final void paintSwingWidget(Graphics2D g) 246 { 240 247 if (loadState == LOAD_STATE_COMPLETED) { 241 super.paint(g);248 paintHeavyDutyWidget(g); 242 249 } else { 243 paintLoadScreen(g, LOAD_SCREEN_COLOR); 244 this.paintLink((Graphics2D)g); 245 } 246 247 } 248 249 /** 250 * Rendersthe load bar / load messages 250 paintLoadScreen(LOAD_SCREEN_COLOR); 251 } 252 253 } 254 255 /** Can be overridden to provide custom drawing. */ 256 protected void paintHeavyDutyWidget(Graphics2D g) 257 { 258 super.paintSwingWidget(g); 259 } 260 261 /** 262 * Renders the load bar / load messages 251 263 * 252 264 * @param g 253 265 */ 254 private void paintLoadScreen( Graphics g, Color backgroundColor) {266 private void paintLoadScreen(Colour backgroundColor) { 255 267 256 268 if (Browser._theBrowser == null) return; 257 269 270 SwingGraphicsManager manager = SwingMiscManager.getIfUsingSwingGraphicsManager(); 271 Graphics g = manager.getCurrentSurface(); 272 258 273 // Render shaded window over widget 259 g.setColor( backgroundColor);274 g.setColor(SwingConversions.toSwingColor(backgroundColor)); 260 275 g.fillRect(getX(), getY(), getWidth(), getHeight()); 261 276 … … 291 306 Rectangle tmpClip = (clipBackUp != null) ? clipBackUp.getBounds() : 292 307 new Rectangle(0, 0, 293 Browser._theBrowser.getContentPane().getWidth(),294 Browser._theBrowser.getContentPane().getHeight());295 296 g.setClip(tmpClip.intersection( getBounds()));308 manager.getContentPane().getWidth(), 309 manager.getContentPane().getHeight()); 310 311 g.setClip(tmpClip.intersection(SwingConversions.toSwingRectangle(getBounds()))); 297 312 298 313 … … 300 315 301 316 GradientPaint gp = new GradientPaint( 302 0, barY + (int)(BAR_HEIGHT * 0.8), LOAD_BAR_INDETERM_COLOR,303 0, barY, LOAD_BAR_HIGHLIGHT_COLOR);317 0, barY + (int)(BAR_HEIGHT * 0.8), SwingConversions.toSwingColor(LOAD_BAR_INDETERM_COLOR), 318 0, barY, SwingConversions.toSwingColor(LOAD_BAR_HIGHLIGHT_COLOR)); 304 319 ((Graphics2D)g).setPaint(gp); 305 320 … … 311 326 312 327 GradientPaint gp = new GradientPaint( 313 0, barY + (int)(BAR_HEIGHT * 0.8), LOAD_BAR_PROGRESS_COLOR,314 0, barY, LOAD_BAR_HIGHLIGHT_COLOR);328 0, barY + (int)(BAR_HEIGHT * 0.8), SwingConversions.toSwingColor(LOAD_BAR_PROGRESS_COLOR), 329 0, barY, SwingConversions.toSwingColor(LOAD_BAR_HIGHLIGHT_COLOR)); 315 330 ((Graphics2D)g).setPaint(gp); 316 331 … … 319 334 } 320 335 321 g.setColor( Color.DARK_GRAY);336 g.setColor(SwingConversions.toSwingColor(Colour.DARK_GREY)); 322 337 g.drawRect(barX, barY, barWidth, BAR_HEIGHT); 323 338 324 339 if (loadState == LOAD_STATE_FAILED) 325 g.setColor( Color.RED);326 327 else g.setColor( Color.BLACK);340 g.setColor(SwingConversions.toSwingColor(Colour.RED)); 341 342 else g.setColor(SwingConversions.toSwingColor(Colour.BLACK)); 328 343 329 344 … … 638 653 // Re-render loading state - if not expired 639 654 if (!expired) { 640 FrameGraphics.invalidateArea(new Rectangle(getX(), getY(), getWidth(), getHeight()));641 FrameGraphics.requestRefresh(true);655 DisplayController.invalidateArea(getBounds()); 656 DisplayController.requestRefresh(true); 642 657 } 643 658 } … … 680 695 681 696 // Only load if in view 682 if (!isFloating() && getParentFrame() != Display IO.getCurrentFrame())697 if (!isFloating() && getParentFrame() != DisplayController.getCurrentFrame()) 683 698 return; 684 699 -
trunk/src/org/expeditee/items/widgets/JSWidget.java
r1080 r1102 32 32 import javax.swing.JPanel; 33 33 34 import org.expeditee.gui.Display IO;34 import org.expeditee.gui.DisplayController; 35 35 import org.expeditee.items.ItemParentStateChangedEvent; 36 36 import org.expeditee.items.JSThreadable; … … 75 75 76 76 private static Text getSauce() { 77 Text source = new Text(Display IO.getCurrentFrame().getNextItemID(), "@iw: org.expeditee.items.widgets.JSWidget");78 source.setParent(Display IO.getCurrentFrame());77 Text source = new Text(DisplayController.getCurrentFrame().getNextItemID(), "@iw: org.expeditee.items.widgets.JSWidget"); 78 source.setParent(DisplayController.getCurrentFrame()); 79 79 return source; 80 80 } … … 172 172 173 173 @Override 174 protected void paintLink( Graphics2D g) {174 protected void paintLink() { 175 175 return; 176 176 } -
trunk/src/org/expeditee/items/widgets/JfxBrowser.java
r1060 r1102 76 76 import netscape.javascript.JSObject; 77 77 78 import org.expeditee.gui.DisplayIO; 79 import org.expeditee.gui.FrameMouseActions; 78 import org.expeditee.gio.gesture.StandardGestureActions; 79 import org.expeditee.gio.swing.SwingConversions; 80 import org.expeditee.gui.DisplayController; 80 81 import org.expeditee.gui.FreeItems; 81 82 import org.expeditee.gui.MessageBay; … … 468 469 public void handle(KeyEvent e) { 469 470 // Hiding the cursor when typing, to be more Expeditee-like 470 Display IO.setCursor(org.expeditee.items.Item.HIDDEN_CURSOR);471 DisplayController.setCursor(org.expeditee.items.Item.HIDDEN_CURSOR); 471 472 } 472 473 }); … … 481 482 } 482 483 // Checking if the user has been typing - if so, move the cursor to the caret position 483 if (Display IO.getCursor() == Item.HIDDEN_CURSOR) {484 Display IO.setCursor(org.expeditee.items.Item.TEXT_CURSOR);485 Display IO.setCursorPosition(getCoordFromCaret(JfxBrowser.this._urlField));484 if (DisplayController.getCursor() == Item.HIDDEN_CURSOR) { 485 DisplayController.setCursor(org.expeditee.items.Item.TEXT_CURSOR); 486 DisplayController.setCursorPosition(SwingConversions.fromSwingPoint(getCoordFromCaret(JfxBrowser.this._urlField))); 486 487 } else { 487 488 // Otherwise, move the caret to the cursor location … … 523 524 public void changed(ObservableValue<? extends Boolean> property, Boolean oldValue, Boolean newValue) { 524 525 if(newValue.booleanValue()) { 525 Display IO.setCursor(org.expeditee.items.Item.TEXT_CURSOR);526 DisplayController.setCursor(org.expeditee.items.Item.TEXT_CURSOR); 526 527 } else { 527 528 // Restoring the standard cursor, since it is changed to a text cursor when focus is gained 528 Display IO.setCursor(org.expeditee.items.Item.DEFAULT_CURSOR);529 DisplayController.setCursor(org.expeditee.items.Item.DEFAULT_CURSOR); 529 530 } 530 531 } … … 545 546 if (e.getButton() == MouseButton.SECONDARY) { 546 547 // Right mouse button released, so copy the selection (i.e. don't remove the original) 547 item = Display IO.getCurrentFrame().createNewText(JfxBrowser.this._urlField.getSelectedText());548 FrameMouseActions.pickup(item);548 item = DisplayController.getCurrentFrame().createNewText(JfxBrowser.this._urlField.getSelectedText()); 549 StandardGestureActions.pickup(item); 549 550 } else if (e.getButton() == MouseButton.MIDDLE) { 550 551 // Middle mouse button released, so copy the selection then remove it from the URL field 551 item = Display IO.getCurrentFrame().createNewText(JfxBrowser.this._urlField.getSelectedText());552 item = DisplayController.getCurrentFrame().createNewText(JfxBrowser.this._urlField.getSelectedText()); 552 553 JfxBrowser.this._urlField.setText( 553 554 JfxBrowser.this._urlField.getText().substring(0, JfxBrowser.this._urlField.getSelection().getStart()) … … 555 556 JfxBrowser.this._urlField.getText().length())); 556 557 557 FrameMouseActions.pickup(item);558 StandardGestureActions.pickup(item); 558 559 } 559 560 } … … 660 661 661 662 if (((String) style.call("getPropertyValue", new Object[] { "background-image" })).startsWith("url(")) { 662 pic = WebParser.getBackgroundImageFromNode(node, style, Display IO.getCurrentFrame(), null,663 (float) FrameMouseActions.getX(), (float) FrameMouseActions.getY(), width, height);663 pic = WebParser.getBackgroundImageFromNode(node, style, DisplayController.getCurrentFrame(), null, 664 (float) DisplayController.getMouseX(), (float) DisplayController.getMouseY(), width, height); 664 665 665 666 } else { … … 667 668 if(node.getNodeName().toLowerCase().equals("img") && 668 669 (imgSrc = ((JSObject) node).getMember("src").toString()) != null) { 669 pic = WebParser.getImageFromUrl(imgSrc, null, Display IO.getCurrentFrame(),670 (float) FrameMouseActions.getX(), (float) FrameMouseActions.getY(), (int) width, null, null, null, null, null, 0, 0);670 pic = WebParser.getImageFromUrl(imgSrc, null, DisplayController.getCurrentFrame(), 671 (float) DisplayController.getMouseX(), (float) DisplayController.getMouseY(), (int) width, null, null, null, null, null, 0, 0); 671 672 } else { 672 673 return; … … 685 686 } 686 687 687 pic.setXY( FrameMouseActions.getX(), FrameMouseActions.getY());688 FrameMouseActions.pickup(pic);688 pic.setXY(DisplayController.getMouseX(), DisplayController.getMouseY()); 689 StandardGestureActions.pickup(pic); 689 690 } catch (Exception e1) { 690 691 // TODO Auto-generated catch block … … 714 715 + ((JSObject)node).getMember("height") 715 716 + ":" + src); 716 t.setParent(Display IO.getCurrentFrame());717 t.setXY( FrameMouseActions.getX(), FrameMouseActions.getY());717 t.setParent(DisplayController.getCurrentFrame()); 718 t.setXY(DisplayController.getMouseX(), DisplayController.getMouseY()); 718 719 JfxMedia media = new JfxMedia(t, new String[] { src }); 719 FrameMouseActions.pickup(media.getItems());720 StandardGestureActions.pickup(media.getItems()); 720 721 721 722 } else if(node.getNodeName().toLowerCase().equals("a") && ((JSObject)node).getMember("href") != null) { 722 723 // If a link is right clicked, copy the text content and give it an action to create 723 724 // a new frame containing a browser pointing to the linked page 724 Text t = Display IO.getCurrentFrame().createNewText(((String) ((JSObject)node).getMember("textContent")).trim());725 Text t = DisplayController.getCurrentFrame().createNewText(((String) ((JSObject)node).getMember("textContent")).trim()); 725 726 t.addAction("createFrameWithBrowser " + (String) ((JSObject)node).getMember("href")); 726 t.setXY( FrameMouseActions.getX(), FrameMouseActions.getY());727 FrameMouseActions.pickup(t);727 t.setXY(DisplayController.getMouseX(), DisplayController.getMouseY()); 728 StandardGestureActions.pickup(t); 728 729 } 729 730 } 730 731 } else { 731 732 // Copy text and attach to cursor 732 Text t = Display IO.getCurrentFrame().createNewText(selection);733 t.setXY( FrameMouseActions.getX(), FrameMouseActions.getY());734 FrameMouseActions.pickup(t);733 Text t = DisplayController.getCurrentFrame().createNewText(selection); 734 t.setXY(DisplayController.getMouseX(), DisplayController.getMouseY()); 735 StandardGestureActions.pickup(t); 735 736 } 736 737 } … … 871 872 public void getFrame() { 872 873 try { 873 WebParser.parsePageSimple(this, _webEngine, _webView, Display IO.getCurrentFrame());874 WebParser.parsePageSimple(this, _webEngine, _webView, DisplayController.getCurrentFrame()); 874 875 } catch (Exception e) { 875 876 e.printStackTrace(); … … 886 887 new Thread(new Runnable() { 887 888 public void run() { 888 WebParser.parsePageSimple(JfxBrowser.this, JfxBrowser.this._webEngine, JfxBrowser.this._webView, Display IO.getCurrentFrame());889 WebParser.parsePageSimple(JfxBrowser.this, JfxBrowser.this._webEngine, JfxBrowser.this._webView, DisplayController.getCurrentFrame()); 889 890 } 890 891 }).start(); … … 954 955 } 955 956 956 final int x = FrameMouseActions.getX() - this.getX(), y = FrameMouseActions.getY() - this.getY();957 final int x = DisplayController.getMouseX() - this.getX(), y = DisplayController.getMouseY() - this.getY(); 957 958 if(!this._urlField.getBoundsInParent().contains(x, y)) { 958 959 // fails if not clicking on urlField -
trunk/src/org/expeditee/items/widgets/MemoryMonitor.java
r919 r1102 19 19 package org.expeditee.items.widgets; 20 20 21 import java.awt.Color;22 21 import java.awt.Font; 23 22 import java.awt.Graphics; … … 27 26 import javax.swing.SwingUtilities; 28 27 28 import org.expeditee.core.Colour; 29 import org.expeditee.gio.swing.SwingConversions; 30 import org.expeditee.gio.swing.SwingMiscManager; 29 31 import org.expeditee.items.ItemParentStateChangedEvent; 30 32 import org.expeditee.items.Text; … … 36 38 * 37 39 */ 38 public class MemoryMonitor extends InteractiveWidget {40 public class MemoryMonitor extends SwingWidget { 39 41 40 42 private long totalMemoryInBytes; … … 63 65 64 66 @Override 65 public void paint (Graphics g) {66 67 public void paintSwingWidget(Graphics2D g) 68 { 67 69 int height = getHeight(); 68 70 int width = getWidth(); … … 70 72 int memHeight = (int)(height * currentMemoryUsage); 71 73 72 Colo r memColor;74 Colour memColor; 73 75 if (currentMemoryUsage > 0.8f) { 74 memColor = Colo r.RED;76 memColor = Colour.RED; 75 77 } else if (currentMemoryUsage > 0.5f) { 76 memColor = Colo r.ORANGE;78 memColor = Colour.ORANGE; 77 79 } else { 78 memColor = Colo r.GREEN;80 memColor = Colour.GREEN; 79 81 } 80 82 81 g.setColor( memColor);83 g.setColor(SwingConversions.toSwingColor(memColor)); 82 84 g.fillRect(getX(), getY() + height - memHeight, width, memHeight); 83 85 84 g.setColor( Color.WHITE);86 g.setColor(SwingConversions.toSwingColor(Colour.WHITE)); 85 87 g.fillRect(getX(), getY(), width, height - memHeight); 86 88 87 89 int percent = (int)(currentMemoryUsage * 100.0f); 88 90 89 g.setColor( Color.BLACK);91 g.setColor(SwingConversions.toSwingColor(Colour.BLACK)); 90 92 g.setFont(USAGE_FONT); 91 93 g.drawString(percent + "%", getX() + 12, getY() + (height / 2) + 8); 92 93 paintLink((Graphics2D)g);94 94 } 95 95 -
trunk/src/org/expeditee/items/widgets/Password.java
r919 r1102 32 32 * @author jts21 33 33 */ 34 public class Password extends InteractiveWidget {34 public class Password extends SwingWidget { 35 35 36 36 private JPasswordField passwordField; -
trunk/src/org/expeditee/items/widgets/RefreshButton.java
r1005 r1102 4 4 import java.awt.event.ActionListener; 5 5 6 import org.expeditee.gui.Display IO;6 import org.expeditee.gui.DisplayController; 7 7 import org.expeditee.gui.Frame; 8 8 import org.expeditee.gui.FrameGraphics; … … 20 20 public void actionPerformed(ActionEvent e) { 21 21 22 Frame f = Display IO.getCurrentFrame();22 Frame f = DisplayController.getCurrentFrame(); 23 23 try{ 24 24 FrameIO.ForceSaveFrame(f); 25 25 Frame g = FrameIO.LoadRestoreFrame(f); 26 Display IO.setCurrentFrame(g, false);27 FrameGraphics.refresh(true);26 DisplayController.setCurrentFrame(g, false); 27 DisplayController.requestRefresh(true); 28 28 } 29 29 catch(Exception e1){ -
trunk/src/org/expeditee/items/widgets/RubbishBin.java
r1005 r1102 4 4 import java.awt.event.ActionListener; 5 5 6 import org.expeditee.g ui.DisplayIO;7 import org.expeditee.gui. FrameMouseActions;6 import org.expeditee.gio.gesture.StandardGestureActions; 7 import org.expeditee.gui.DisplayController; 8 8 import org.expeditee.gui.FreeItems; 9 9 import org.expeditee.items.Item; 10 10 import org.expeditee.items.Text; 11 11 12 //When the Rubbish Bin Widget is clicked by any of the mouse buttons, whatever is currently being picked up by the mouse is destroyed 13 public class RubbishBin extends ButtonWidget{ 14 15 public RubbishBin(Text source, String[] args){ 16 12 /** 13 * When the Rubbish Bin Widget is clicked by any of the mouse buttons, 14 * whatever is currently being picked up by the mouse is destroyed. 15 * 16 * @author cts16 17 */ 18 public class RubbishBin extends ButtonWidget 19 { 20 public RubbishBin(Text source, String[] args) 21 { 17 22 super(80, "org/expeditee/assets/images/bin.svg", source, args); 18 23 19 clicked_.addActionListener(new ActionListener() { 20 public void actionPerformed(ActionEvent e) { 24 clicked_.addActionListener(new ActionListener() 25 { 26 public void actionPerformed(ActionEvent e) 27 { 21 28 22 29 } 23 30 }); 24 31 } 25 public boolean ItemsLeftClickDropped() { 26 32 33 public boolean ItemsLeftClickDropped() 34 { 27 35 //Find what the mouse was holding at the time and delete it 28 36 Item freeItems = FreeItems.getItemAttachedToCursor(); 29 if( freeItems != null){ 30 freeItems.setParent(DisplayIO.getCurrentFrame()); 37 38 if( freeItems != null) { 39 freeItems.setParent(DisplayController.getCurrentFrame()); 31 40 32 try{ 33 34 FrameMouseActions.delete(freeItems); 35 } 36 catch(Exception e){ 37 41 try { 42 StandardGestureActions.delete(freeItems, null, null, false); 43 } catch(Exception e) { 38 44 e.printStackTrace(); 39 45 } 40 46 } 47 41 48 return true; 42 49 } 43 50 44 51 @Override 45 protected String[] getArgs() { 52 protected String[] getArgs() 53 { 46 54 // TODO Auto-generated method stub 47 55 return null; 48 56 } 49 //this should be a generic method for any widget that is clicked while an item is being held 50 public boolean itemHeldWhileClicked(InteractiveWidget iw){ 51 57 58 /** 59 * This should be a generic method for any widget that is clicked while an item is being held. 60 */ 61 public boolean itemHeldWhileClicked(Widget iw) 62 { 52 63 ItemsLeftClickDropped(); 53 return true; 54 55 } 56 public boolean getdropInteractableStatus(){ 64 57 65 return true; 58 66 } 59 67 68 public boolean getdropInteractableStatus() 69 { 70 return true; 71 } 60 72 } -
trunk/src/org/expeditee/items/widgets/SampleWidget2.java
r919 r1102 19 19 package org.expeditee.items.widgets; 20 20 21 22 import java.awt.Color;23 21 import java.awt.FlowLayout; 24 22 import java.awt.Font; … … 32 30 import javax.swing.JToggleButton; 33 31 32 import org.expeditee.core.Colour; 33 import org.expeditee.gio.swing.SwingConversions; 34 34 import org.expeditee.items.Text; 35 35 36 public class SampleWidget2 extends InteractiveWidget {36 public class SampleWidget2 extends SwingWidget { 37 37 38 38 private JComboBox _combo; … … 47 47 48 48 JPanel p = new JPanel(new FlowLayout()); 49 p.setBackground( new Color(255,228,195));49 p.setBackground(SwingConversions.toSwingColor(Colour.FromRGB255(255,228,195))); 50 50 51 51 JLabel lbl = new JLabel("This is an example InteractiveWidget!"); -
trunk/src/org/expeditee/items/widgets/Undo.java
r1005 r1102 4 4 import java.awt.event.ActionListener; 5 5 6 import org.expeditee.gui.Display IO;6 import org.expeditee.gui.DisplayController; 7 7 import org.expeditee.items.Text; 8 8 … … 17 17 public void actionPerformed(ActionEvent e) { 18 18 19 Display IO.getCurrentFrame().undo();19 DisplayController.getCurrentFrame().undo(); 20 20 } 21 21 }); -
trunk/src/org/expeditee/items/widgets/WidgetCacheManager.java
r919 r1102 25 25 import java.util.Set; 26 26 27 import org.expeditee.gui.Display IOObserver;27 import org.expeditee.gui.DisplayObserver; 28 28 import org.expeditee.gui.FrameIO; 29 29 … … 37 37 * 38 38 */ 39 public final class WidgetCacheManager implements Display IOObserver {39 public final class WidgetCacheManager implements DisplayObserver { 40 40 41 41 private static HashMap<HeavyDutyInteractiveWidget, Integer> transientWidgets = new HashMap<HeavyDutyInteractiveWidget, Integer>(); -
trunk/src/org/expeditee/items/widgets/WidgetCorner.java
r919 r1102 19 19 package org.expeditee.items.widgets; 20 20 21 import java.awt.Color;22 import java.awt.Graphics2D;23 import java.awt.Polygon;24 21 import java.util.List; 25 22 23 import org.expeditee.core.Colour; 24 import org.expeditee.core.Point; 25 import org.expeditee.core.bounds.PolygonBounds; 26 26 import org.expeditee.items.Dot; 27 27 import org.expeditee.items.ItemParentStateChangedEvent; … … 30 30 public class WidgetCorner extends Dot { 31 31 32 private InteractiveWidget _widgetSource;33 34 WidgetCorner(int x, int y, int id, InteractiveWidget widgetSource) {32 private Widget _widgetSource; 33 34 WidgetCorner(int x, int y, int id, Widget widgetSource) { 35 35 super(x, y, id); 36 36 … … 38 38 throw new NullPointerException("widgetSource"); 39 39 _widgetSource = widgetSource; 40 }41 42 @Override43 public void updatePolygon() {44 super.updatePolygon();45 if (_widgetSource != null)46 _widgetSource.onBoundsChanged();47 40 } 48 41 … … 81 74 82 75 @Override 83 public void onParentStateChanged(ItemParentStateChangedEvent e) { 76 public void onParentStateChanged(ItemParentStateChangedEvent e) 77 { 84 78 super.onParentStateChanged(e); 85 79 _widgetSource.onParentStateChanged(e); 86 80 } 87 81 88 public InteractiveWidget getWidgetSource() {82 public Widget getWidgetSource() { 89 83 return _widgetSource; 90 84 } 91 85 92 86 @Override 93 public void paint(Graphics2D g) { 87 public void paint() 88 { 94 89 // For fixed widgets, always have corner selected with connected context 95 HighlightMode tmp = _ mode; // save mode96 if (_ mode == HighlightMode.Normal && _widgetSource.isFixedSize()) {97 _ mode = HighlightMode.Connected; // draw as connected context for90 HighlightMode tmp = _highlightMode; // save mode 91 if (_highlightMode == HighlightMode.Normal && _widgetSource.isFixedSize()) { 92 _highlightMode = HighlightMode.Connected; // draw as connected context for 98 93 // fixed widgets 99 94 } 100 super.paint( g);101 _ mode = tmp; // restore mode102 } 103 104 @Override 105 public void paintFill( Graphics2D g) {106 _widgetSource.paintFill( g); // only paints a fill if floating95 super.paint(); 96 _highlightMode = tmp; // restore mode 97 } 98 99 @Override 100 public void paintFill() { 101 _widgetSource.paintFill(); // only paints a fill if floating 107 102 } 108 103 … … 127 122 128 123 @Override 129 public void setArrowhead(Polygon arrow) {124 public void setArrowhead(PolygonBounds arrow) { 130 125 } 131 126 … … 139 134 140 135 @Override 141 public void setBackgroundColor(Colo r c) {136 public void setBackgroundColor(Colour c) { 142 137 if (_widgetSource != null) { 143 138 super.setBackgroundColor(c); … … 147 142 148 143 @Override 149 public void setBottomShadowColor(Colo r bottom) {150 } 151 152 @Override 153 public void setFillColor(Colo r c) {144 public void setBottomShadowColor(Colour bottom) { 145 } 146 147 @Override 148 public void setFillColor(Colour c) { 154 149 } 155 150 … … 186 181 } 187 182 188 public void setAnchorCornerX(Float anchorLeft, Float anchorRight) { 189 _anchorLeft = anchorLeft; 190 _anchorRight = anchorRight; 191 } 192 193 public void setAnchorCornerY(Float anchorTop, Float anchorBottom) { 194 _anchorTop = anchorTop; 195 _anchorBottom= anchorBottom; 196 } 197 198 @Override 199 public void setAnchorLeft(Float anchor) { 183 public void setAnchorCornerX(Integer anchorLeft, Integer anchorRight) 184 { 185 _anchoring.setLeftAnchor(anchorLeft); 186 _anchoring.setRightAnchor(anchorRight); 187 } 188 189 public void setAnchorCornerY(Integer anchorTop, Integer anchorBottom) 190 { 191 _anchoring.setTopAnchor(anchorTop); 192 _anchoring.setBottomAnchor(anchorBottom); 193 } 194 195 @Override 196 public void setAnchorLeft(Integer anchor) { 200 197 _widgetSource.setAnchorLeft(anchor); 201 _anchorLeft = anchor; 202 _anchorRight = null; 203 } 204 205 @Override 206 public void setAnchorRight(Float anchor) { 198 _anchoring.setLeftAnchor(anchor); 199 } 200 201 @Override 202 public void setAnchorRight(Integer anchor) { 207 203 _widgetSource.setAnchorRight(anchor); 208 _anchorLeft = null; 209 _anchorRight = anchor; 210 } 211 212 @Override 213 public void setAnchorTop(Float anchor) { 204 _anchoring.setRightAnchor(anchor); 205 } 206 207 @Override 208 public void setAnchorTop(Integer anchor) { 214 209 _widgetSource.setAnchorTop(anchor); 215 _anchorTop = anchor; 216 _anchorBottom = null; 217 } 218 219 @Override 220 public void setAnchorBottom(Float anchor) { 210 _anchoring.setTopAnchor(anchor); 211 } 212 213 @Override 214 public void setAnchorBottom(Integer anchor) { 221 215 _widgetSource.setAnchorBottom(anchor); 222 _anchorTop = null; 223 _anchorBottom = anchor; 216 _anchoring.setBottomAnchor(anchor); 224 217 } 225 218 … … 251 244 252 245 @Override 253 public boolean contains( int x, int y) {254 return super.contains(x, y)255 && !_widgetSource.getBounds().contains(x, y);246 public boolean contains(Point p) 247 { 248 return super.contains(p) && !_widgetSource.getBounds().contains(p); 256 249 } 257 250 … … 268 261 269 262 @Override 270 public void setColor(Colo r color) {263 public void setColor(Colour color) { 271 264 if (_widgetSource != null) { 272 265 super.setColor(color); -
trunk/src/org/expeditee/items/widgets/WidgetEdge.java
r919 r1102 19 19 package org.expeditee.items.widgets; 20 20 21 import java.awt.Color;22 import java.awt.Polygon;23 21 import java.util.List; 24 22 23 import org.expeditee.core.Colour; 24 import org.expeditee.core.Point; 25 import org.expeditee.core.bounds.PolygonBounds; 25 26 import org.expeditee.items.Item; 26 27 import org.expeditee.items.Line; … … 28 29 29 30 /** 30 * Widget edges define the bound ries of an interactive widget.31 * Widget edges define the boundaries of an interactive widget. 31 32 * 32 33 * @author Brook Novak … … 34 35 public class WidgetEdge extends Line { 35 36 36 private InteractiveWidget _widgetSource;37 private Widget _widgetSource; 37 38 38 39 WidgetEdge(WidgetCorner start, WidgetCorner end, int id, 39 InteractiveWidget widgetSource) {40 Widget widgetSource) { 40 41 super(start, end, id); 41 42 … … 45 46 } 46 47 47 public InteractiveWidget getWidgetSource() {48 public Widget getWidgetSource() { 48 49 return _widgetSource; 49 50 } … … 89 90 90 91 @Override 91 public void setArrowhead(Polygon arrow) {92 public void setArrowhead(PolygonBounds arrow) { 92 93 } 93 94 … … 101 102 102 103 @Override 103 public void setBottomShadowColor(Colo r bottom) {104 } 105 106 @Override 107 public void setFillColor(Colo r c) {104 public void setBottomShadowColor(Colour bottom) { 105 } 106 107 @Override 108 public void setFillColor(Colour c) { 108 109 } 109 110 … … 121 122 122 123 @Override 123 public void setAnchorTop( Floatanchor) {124 public void setAnchorTop(Integer anchor) { 124 125 _widgetSource.setAnchorTop(anchor); 125 126 } 126 127 127 128 @Override 128 public void setAnchorBottom( Floatanchor) {129 public void setAnchorBottom(Integer anchor) { 129 130 _widgetSource.setAnchorBottom(anchor); 130 131 } 131 132 132 133 @Override 133 public void setAnchorLeft( Floatanchor) {134 public void setAnchorLeft(Integer anchor) { 134 135 _widgetSource.setAnchorLeft(anchor); 135 136 } 136 137 137 138 @Override 138 public void setAnchorRight( Floatanchor) {139 public void setAnchorRight(Integer anchor) { 139 140 _widgetSource.setAnchorRight(anchor); 140 141 } … … 156 157 157 158 @Override 158 public FloatgetAnchorTop() {159 public Integer getAnchorTop() { 159 160 return _widgetSource.getSource().getAnchorTop(); 160 161 } 161 162 162 163 @Override 163 public FloatgetAnchorBottom() {164 public Integer getAnchorBottom() { 164 165 return _widgetSource.getSource().getAnchorBottom(); 165 166 } 166 167 167 168 @Override 168 public FloatgetAnchorLeft() {169 public Integer getAnchorLeft() { 169 170 return _widgetSource.getSource().getAnchorLeft(); 170 171 } 171 172 172 173 @Override 173 public FloatgetAnchorRight() {174 public Integer getAnchorRight() { 174 175 return _widgetSource.getSource().getAnchorRight(); 175 176 } 176 177 177 178 @Override 178 public boolean contains( int x, int y) {179 return super.contains( x, y) && !_widgetSource.getBounds().contains(x, y);180 } 181 182 @Override 183 public Polygon getEnclosedShape() {179 public boolean contains(Point p) { 180 return super.contains(p) && !_widgetSource.getBounds().contains(p); 181 } 182 183 @Override 184 public PolygonBounds getEnclosedShape() { 184 185 return getStartItem().getEnclosedShape(); 185 186 } … … 219 220 220 221 @Override 221 public void setBackgroundColor(Colo r c) {222 public void setBackgroundColor(Colour c) { 222 223 if (_widgetSource != null) { 223 224 super.setBackgroundColor(c); … … 227 228 228 229 @Override 229 public void setColor(Colo r c) {230 public void setColor(Colour c) { 230 231 if (_widgetSource != null) { 231 232 super.setColor(c); -
trunk/src/org/expeditee/items/widgets/charts/AbstractCategory.java
r919 r1102 19 19 package org.expeditee.items.widgets.charts; 20 20 21 import java.awt.Color;22 21 import java.util.Collection; 23 22 23 import org.expeditee.core.Colour; 24 import org.expeditee.gio.swing.SwingConversions; 24 25 import org.expeditee.gui.AttributeValuePair; 25 26 import org.expeditee.items.Text; … … 49 50 Collection<Text> items, boolean swap) { 50 51 boolean foundData = false; 51 Colo r newColor = null;52 Colour newColor = null; 52 53 for (Text i : items) { 53 54 try { … … 61 62 categoryName); 62 63 if (_paints.get(attribute) == null) { 63 _paints.put(attribute, i.getBackgroundColor());64 _paints.put(attribute, SwingConversions.toSwingColor(i.getBackgroundColor())); 64 65 } 65 66 } else { … … 77 78 } 78 79 if (foundData && !swap) { 79 _paints.put(categoryName, newColor);80 _paints.put(categoryName, SwingConversions.toSwingColor(newColor)); 80 81 } 81 82 return foundData; -
trunk/src/org/expeditee/items/widgets/charts/AbstractChart.java
r919 r1102 20 20 21 21 import java.awt.BasicStroke; 22 import java.awt.Color;23 22 import java.awt.Component; 24 23 import java.awt.Font; 25 24 import java.awt.Paint; 26 import java.awt.Point;27 25 import java.awt.event.KeyEvent; 28 26 import java.awt.event.KeyListener; … … 35 33 import javax.swing.JPanel; 36 34 35 import org.expeditee.core.Colour; 36 import org.expeditee.core.Point; 37 import org.expeditee.gio.gesture.StandardGestureActions; 38 import org.expeditee.gio.swing.SwingConversions; 37 39 import org.expeditee.gui.ColorUtils; 40 import org.expeditee.gui.DisplayController; 38 41 import org.expeditee.gui.Frame; 39 42 import org.expeditee.gui.FrameGraphics; 40 43 import org.expeditee.gui.FrameIO; 41 import org.expeditee.gui.FrameKeyboardActions;42 import org.expeditee.gui.FrameMouseActions;43 44 import org.expeditee.gui.FunctionKey; 44 45 import org.expeditee.items.Text; … … 103 104 case SizeUp: 104 105 invalidateLink(); 105 FrameKeyboardActions.SetSize(getFirstCorner(), 1, false, 106 true, false); 106 StandardGestureActions.SetSize(getFirstCorner(), 1, false, true, false); 107 107 invalidateSelf(); 108 FrameGraphics.refresh(true);108 DisplayController.requestRefresh(true); 109 109 // FrameGraphics.requestRefresh(true); 110 110 break; 111 111 case SizeDown: 112 112 invalidateLink(); 113 FrameKeyboardActions.SetSize(getFirstCorner(), -1, false,113 StandardGestureActions.SetSize(getFirstCorner(), -1, false, 114 114 true, false); 115 115 invalidateSelf(); 116 FrameGraphics.refresh(true);116 DisplayController.requestRefresh(true); 117 117 // FrameGraphics.ForceRepaint(); 118 118 // FrameGraphics.refresh(true); … … 125 125 setSourceFillColor(null); 126 126 } else { 127 Colo r newColor = ColorUtils.getNextColor(127 Colour newColor = ColorUtils.getNextColor( 128 128 getSource().getFillColor(), 129 129 TemplateSettings.BackgroundColorWheel.get(), null); … … 134 134 setBackgroundColor(null); 135 135 } else { 136 Colo r newColor = ColorUtils.getNextColor(136 Colour newColor = ColorUtils.getNextColor( 137 137 getSource().getColor(), TemplateSettings.ColorWheel.get(), 138 138 null); … … 141 141 } 142 142 break; 143 default: 144 break; 143 145 } 144 146 } … … 148 150 149 151 public void keyTyped(KeyEvent e) { 150 FrameKeyboardActions.processChar(e.getKeyChar(), e152 StandardGestureActions.processChar(e.getKeyChar(), e 151 153 .isShiftDown()); 152 154 } … … 155 157 156 158 public void mouseClicked(MouseEvent e) { 157 FrameMouseActions.getInstance().mouseClicked(translateEvent(e));159 //StandardGestureActions.mouseClicked(translateEvent(e)); 158 160 } 159 161 … … 167 169 168 170 public void mousePressed(MouseEvent e) { 169 FrameMouseActions.getInstance().mousePressed(translateEvent(e));171 //StandardGestureActions.mousePressed(translateEvent(e)); 170 172 } 171 173 … … 180 182 181 183 public void mouseReleased(MouseEvent e) { 182 FrameMouseActions.getInstance() 183 .mouseReleased(translateEvent(e)); 184 //StandardGestureActions.mouseReleased(translateEvent(e)); 184 185 } 185 186 … … 272 273 if (foundData |= addCategoryData(categoryName, linkFrame 273 274 .getNonAnnotationText(true), swap)) { 274 Colo r backgroundColor = category.getBackgroundColor();275 Colour backgroundColor = category.getBackgroundColor(); 275 276 if (backgroundColor != null) 276 _paints.put(categoryName, backgroundColor);277 _paints.put(categoryName, SwingConversions.toSwingColor(backgroundColor)); 277 278 addSubject(linkFrame); 278 279 } … … 307 308 308 309 @Override 309 public void setBackgroundColor(Colo r c) {310 public void setBackgroundColor(Colour c) { 310 311 super.setBackgroundColor(c); 311 312 if (_chart == null) … … 314 315 _chart.setBackgroundPaint(JFreeChart.DEFAULT_BACKGROUND_PAINT); 315 316 } else { 316 _chart.setBackgroundPaint( c);317 } 318 } 319 320 @Override 321 public void setSourceColor(Colo r c) {317 _chart.setBackgroundPaint(SwingConversions.toSwingColor(c)); 318 } 319 } 320 321 @Override 322 public void setSourceColor(Colour c) { 322 323 super.setSourceColor(c); 323 324 if (_chart == null) … … 326 327 _chart.getTitle().setPaint(TextTitle.DEFAULT_TEXT_PAINT); 327 328 } else { 328 _chart.getTitle().setPaint( c);329 _chart.getTitle().setPaint(SwingConversions.toSwingColor(c)); 329 330 } 330 331 for (Title t : _chart.getSubtitles()) { … … 332 333 t.setPaint(TextTitle.DEFAULT_TEXT_PAINT); 333 334 } else { 334 t.setPaint( c);335 t.setPaint(SwingConversions.toSwingColor(c)); 335 336 } 336 337 } … … 338 339 if (legend != null) { 339 340 if (c == null) { 340 legend.setFrame(new BlockBorder( Color.black));341 legend.setFrame(new BlockBorder(SwingConversions.toSwingColor(Colour.BLACK))); 341 342 } else { 342 legend.setFrame(new BlockBorder( c));343 } 344 } 345 } 346 347 @Override 348 public void setSourceBorderColor(Colo r c) {343 legend.setFrame(new BlockBorder(SwingConversions.toSwingColor(c))); 344 } 345 } 346 } 347 348 @Override 349 public void setSourceBorderColor(Colour c) { 349 350 super.setSourceBorderColor(c); 350 351 if (_chart == null) … … 353 354 _chart.getPlot().setOutlinePaint(Plot.DEFAULT_OUTLINE_PAINT); 354 355 } else { 355 _chart.getPlot().setOutlinePaint( c);356 } 357 } 358 359 @Override 360 public void setSourceFillColor(Colo r c) {356 _chart.getPlot().setOutlinePaint(SwingConversions.toSwingColor(c)); 357 } 358 } 359 360 @Override 361 public void setSourceFillColor(Colour c) { 361 362 super.setSourceFillColor(c); 362 363 if (_chart == null) … … 368 369 legend.setBackgroundPaint(null); 369 370 } else { 370 _chart.getPlot().setBackgroundPaint( c);371 _chart.getPlot().setBackgroundPaint(SwingConversions.toSwingColor(c)); 371 372 if (legend != null) 372 legend.setBackgroundPaint( c);373 legend.setBackgroundPaint(SwingConversions.toSwingColor(c)); 373 374 } 374 375 } … … 387 388 if (legend != null) { 388 389 legend.setFrame(new BlockBorder(newThickness, newThickness, 389 newThickness, newThickness, getSource().getPaintColor()));390 newThickness, newThickness, SwingConversions.toSwingColor(getSource().getPaintColor()))); 390 391 legend.setItemFont(legend.getItemFont().deriveFont(fontSize)); 391 392 float pad = newThickness + 1; -
trunk/src/org/expeditee/items/widgets/charts/AbstractPie.java
r919 r1102 20 20 21 21 import java.awt.BasicStroke; 22 import java.awt.Color;23 22 23 import org.expeditee.core.Colour; 24 import org.expeditee.gio.swing.SwingConversions; 24 25 import org.expeditee.gui.AttributeValuePair; 25 26 import org.expeditee.gui.Frame; … … 85 86 try { 86 87 _data.setValue(avp.getAttribute(), avp.getDoubleValue()); 87 _paints.put(avp.getAttribute(), t.getBackgroundColor());88 _paints.put(avp.getAttribute(), SwingConversions.toSwingColor(t.getBackgroundColor())); 88 89 } catch (NumberFormatException nfe) { 89 90 … … 94 95 95 96 @Override 96 public void setSourceBorderColor(Colo r c) {97 public void setSourceBorderColor(Colour c) { 97 98 super.setSourceBorderColor(c); 98 99 if (getChart() == null) … … 106 107 plot.setShadowPaint(PiePlot.DEFAULT_SHADOW_PAINT); 107 108 } else { 108 plot.setBaseSectionOutlinePaint( c);109 plot.setLabelLinkPaint( c);110 plot.setLabelOutlinePaint( c);111 Colo r newC = c.darker();112 Colo r faded = new Color(newC.getRed(), newC.getGreen(), newC113 .getBlue(), 128);109 plot.setBaseSectionOutlinePaint(SwingConversions.toSwingColor(c)); 110 plot.setLabelLinkPaint(SwingConversions.toSwingColor(c)); 111 plot.setLabelOutlinePaint(SwingConversions.toSwingColor(c)); 112 Colour newC = c.darker(); 113 Colour faded = new Colour(newC.getRed(), newC.getGreen(), newC 114 .getBlue(), Colour.FromComponent255(128)); 114 115 115 plot.setLabelShadowPaint( faded);116 plot.setShadowPaint( c);116 plot.setLabelShadowPaint(SwingConversions.toSwingColor(faded)); 117 plot.setShadowPaint(SwingConversions.toSwingColor(c)); 117 118 } 118 119 } 119 120 120 121 @Override 121 public void setSourceColor(Colo r c) {122 public void setSourceColor(Colour c) { 122 123 super.setSourceColor(c); 123 124 if (getChart() == null) … … 127 128 plot.setLabelPaint(PiePlot.DEFAULT_LABEL_PAINT); 128 129 } else { 129 plot.setLabelPaint( c);130 plot.setLabelPaint(SwingConversions.toSwingColor(c)); 130 131 } 131 132 } -
trunk/src/org/expeditee/items/widgets/charts/AbstractValueAxis.java
r919 r1102 20 20 21 21 import java.awt.BasicStroke; 22 import java.awt.Color;23 22 import java.awt.Stroke; 24 23 24 import org.expeditee.core.Colour; 25 import org.expeditee.gio.swing.SwingConversions; 25 26 import org.expeditee.gui.Frame; 26 27 import org.expeditee.items.Text; … … 56 57 57 58 @Override 58 public void setSourceColor(Colo r c) {59 public void setSourceColor(Colour c) { 59 60 super.setSourceColor(c); 60 61 if (getChart() == null) … … 70 71 .setTickLabelPaint(Axis.DEFAULT_TICK_LABEL_PAINT); 71 72 } else { 72 plot.getDomainAxis().setLabelPaint( c);73 plot.getRangeAxis().setLabelPaint( c);74 plot.getDomainAxis().setTickLabelPaint( c);75 plot.getRangeAxis().setTickLabelPaint( c);73 plot.getDomainAxis().setLabelPaint(SwingConversions.toSwingColor(c)); 74 plot.getRangeAxis().setLabelPaint(SwingConversions.toSwingColor(c)); 75 plot.getDomainAxis().setTickLabelPaint(SwingConversions.toSwingColor(c)); 76 plot.getRangeAxis().setTickLabelPaint(SwingConversions.toSwingColor(c)); 76 77 } 77 78 } 78 79 79 80 @Override 80 public void setSourceBorderColor(Colo r c) {81 public void setSourceBorderColor(Colour c) { 81 82 super.setSourceBorderColor(c); 82 83 if (getChart() == null) … … 89 90 plot.getRangeAxis().setTickMarkPaint(Plot.DEFAULT_OUTLINE_PAINT); 90 91 } else { 91 Colo r brighter = c.brighter();92 plot.setDomainGridlinePaint( brighter);93 plot.setRangeGridlinePaint( brighter);94 plot.getDomainAxis().setTickMarkPaint( c);95 plot.getRangeAxis().setTickMarkPaint( c);92 Colour brighter = c.brighter(); 93 plot.setDomainGridlinePaint(SwingConversions.toSwingColor(brighter)); 94 plot.setRangeGridlinePaint(SwingConversions.toSwingColor(brighter)); 95 plot.getDomainAxis().setTickMarkPaint(SwingConversions.toSwingColor(c)); 96 plot.getRangeAxis().setTickMarkPaint(SwingConversions.toSwingColor(c)); 96 97 } 97 98 } -
trunk/src/org/expeditee/items/widgets/charts/AbstractXY.java
r919 r1102 19 19 package org.expeditee.items.widgets.charts; 20 20 21 import java.awt.Color;22 21 import java.util.Collection; 23 22 import java.util.HashSet; 24 23 24 import org.expeditee.core.Colour; 25 import org.expeditee.gio.swing.SwingConversions; 25 26 import org.expeditee.gui.AttributeValuePair; 26 27 import org.expeditee.items.Item; … … 55 56 Collection<Text> items, boolean swap) { 56 57 XYSeries newSeries = new XYSeries(categoryName); 57 Colo r categoryColor = null;58 Colour categoryColor = null; 58 59 boolean foundData = false; 59 60 Collection<Item> seen = new HashSet<Item>(); … … 123 124 if (foundData) { 124 125 _data.addSeries(newSeries); 125 _paints.put(categoryName, categoryColor);126 _paints.put(categoryName, SwingConversions.toSwingColor(categoryColor)); 126 127 } 127 128 return foundData; -
trunk/src/org/expeditee/items/widgets/charts/Polar.java
r919 r1102 19 19 package org.expeditee.items.widgets.charts; 20 20 21 import java.awt.Color;22 21 import org.expeditee.core.Colour; 22 import org.expeditee.gio.swing.SwingConversions; 23 23 import org.expeditee.items.Text; 24 24 import org.jfree.chart.ChartFactory; … … 43 43 44 44 @Override 45 public void setSourceColor(Colo r c) {45 public void setSourceColor(Colour c) { 46 46 super.setSourceColor(c); 47 47 if (getChart() == null) … … 53 53 plot.setAngleLabelPaint(Axis.DEFAULT_AXIS_LABEL_PAINT); 54 54 } else { 55 plot.setAngleLabelPaint( c);55 plot.setAngleLabelPaint(SwingConversions.toSwingColor(c)); 56 56 } 57 57 } -
trunk/src/org/expeditee/items/widgets/charts/TimeSeries.java
r919 r1102 19 19 package org.expeditee.items.widgets.charts; 20 20 21 import java.awt.Color;22 21 import java.text.DateFormat; 23 22 import java.text.ParseException; … … 27 26 import java.util.Date; 28 27 28 import org.expeditee.Util; 29 import org.expeditee.core.Colour; 30 import org.expeditee.gio.swing.SwingConversions; 29 31 import org.expeditee.gui.AttributeValuePair; 30 32 import org.expeditee.gui.Frame; … … 100 102 String startDateString = dataFrame.getAnnotationValue("start"); 101 103 if (startDateString != null) { 102 _startDate = parseDate(startDateString);104 _startDate = Util.parseDate(startDateString); 103 105 } 104 106 } catch (Exception e) { … … 135 137 136 138 boolean foundData = false; 137 Colo r newColor = null;139 Colour newColor = null; 138 140 for (Text i : items) { 139 141 if (!i.isLineEnd()) { … … 157 159 RegularTimePeriod rtp = null; 158 160 if (attribute == null) { 159 Date date = parseDate(avp.getAttribute());161 Date date = Util.parseDate(avp.getAttribute()); 160 162 rtp = _periodType.getConstructor( 161 163 new Class[] { Date.class }).newInstance( … … 212 214 if (foundData) { 213 215 _data.addSeries(newSeries); 214 _paints.put(categoryName, newColor);216 _paints.put(categoryName, SwingConversions.toSwingColor(newColor)); 215 217 } 216 218 return foundData; 217 219 } 218 219 /**220 * @param avp221 * @return222 * @throws ParseException223 */224 public static Date parseDate(String dateString) throws ParseException {225 // Select the best match for a date or time format226 DateFormat df = null;227 if (dateString.length() > Formatter.DATE_FORMAT228 .length()) {229 df = new SimpleDateFormat(Formatter.DATE_TIME_FORMAT);230 } else if (dateString.length() <= Formatter.TIME_FORMAT.length()) {231 df = new SimpleDateFormat(Formatter.TIME_FORMAT);232 }else {233 df = new SimpleDateFormat(Formatter.DATE_FORMAT);234 }235 Date date = df.parse(dateString);236 return date;237 }238 220 } -
trunk/src/org/expeditee/reflection/PackageLoader.java
r919 r1102 36 36 public class PackageLoader { 37 37 38 // The following is adapted from: 39 // http://stackoverflow.com/questions/1456930/how-do-i-read-all-classes-from-a-java-package-in-the-classpath 40 41 public static List<Class<?>> getClassesNew(String packageName) 42 throws ClassNotFoundException { 43 44 ClassLoader classLoader = Thread.currentThread() 45 .getContextClassLoader(); 46 47 ArrayList<String> names = new ArrayList<String>(); 48 ; 49 final ArrayList<Class<?>> classes = new ArrayList<Class<?>>(); 50 51 String realPackageName = packageName; 52 packageName = packageName.replace(".", "/"); 53 URL packageURL = classLoader.getResource(packageName); 54 55 if (packageURL.getProtocol().equals("jar")) { 56 57 // build jar file name, then loop through zipped entries 58 59 String jarFileNameUndecoded = packageURL.getFile(); 60 61 try { 62 JarURLConnection ju_connection = (JarURLConnection) packageURL 63 .openConnection(); 64 JarFile jf = ju_connection.getJarFile(); 65 66 Enumeration<JarEntry> jarEntries = jf.entries(); 67 while (jarEntries.hasMoreElements()) { 68 String entryName = jarEntries.nextElement().getName(); 69 70 if (entryName.startsWith(packageName)) { 71 72 if (entryName.endsWith(".class") 73 && !entryName.contains("$")) { 74 75 // Deal with situation where the class found might 76 // be a further sub-package 77 // e.g. for "org.expeditee.action" 78 // there is: 79 // org/expeditee/action/widgets/Chart.class 80 // which would produce a value of 'entryName' as 81 // widgets/Chart.class 82 83 entryName = entryName.substring(0, 84 entryName.length() - 6); // 6 = '.class' 85 entryName = entryName.replace('/', '.'); 86 87 names.add(entryName); 88 classes.add(Class.forName(entryName)); 89 } 90 } 38 // The following is adapted from: 39 // http://stackoverflow.com/questions/1456930/how-do-i-read-all-classes-from-a-java-package-in-the-classpath 40 41 public static List<Class<?>> getClassesNew(String packageName) throws ClassNotFoundException 42 { 43 ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 44 45 ArrayList<String> names = new ArrayList<String>(); 46 47 final ArrayList<Class<?>> classes = new ArrayList<Class<?>>(); 48 49 String realPackageName = packageName; 50 packageName = packageName.replace(".", "/"); 51 URL packageURL = classLoader.getResource(packageName); 52 53 if (packageURL.getProtocol().equals("jar")) { 54 55 // build jar file name, then loop through zipped entries 56 57 String jarFileNameUndecoded = packageURL.getFile(); 58 59 try { 60 JarURLConnection ju_connection = (JarURLConnection) packageURL 61 .openConnection(); 62 JarFile jf = ju_connection.getJarFile(); 63 64 Enumeration<JarEntry> jarEntries = jf.entries(); 65 while (jarEntries.hasMoreElements()) { 66 String entryName = jarEntries.nextElement().getName(); 67 68 if (entryName.startsWith(packageName)) { 69 70 if (entryName.endsWith(".class") 71 && !entryName.contains("$")) { 72 73 // Deal with situation where the class found might 74 // be a further sub-package 75 // e.g. for "org.expeditee.action" 76 // there is: 77 // org/expeditee/action/widgets/Chart.class 78 // which would produce a value of 'entryName' as 79 // widgets/Chart.class 80 81 entryName = entryName.substring(0, 82 entryName.length() - 6); // 6 = '.class' 83 entryName = entryName.replace('/', '.'); 84 85 names.add(entryName); 86 classes.add(Class.forName(entryName)); 87 } 88 } 89 } 90 } catch (Exception e) { 91 System.err.println("Failed to decode jar file: " 92 + jarFileNameUndecoded); 93 e.printStackTrace(); 94 } 95 } else if (packageURL.getProtocol().equals("bundleresource")) { 96 try { 97 final URLConnection urlConnection = packageURL.openConnection(); 98 final Class<?> c = urlConnection.getClass(); 99 final java.lang.reflect.Method toInvoke = c.getMethod("getFileURL"); 100 final URL fileURL = (URL)toInvoke.invoke(urlConnection); 101 final File folder = new File(fileURL.getFile()); 102 final List<String> files = findFiles(folder); 103 for (final String s : files) { 104 String entryName = realPackageName + s; 105 if (entryName.endsWith(".class") && !entryName.contains("$")) { 106 entryName = entryName.substring(0, entryName.lastIndexOf('.')); 107 entryName = entryName.replace('/', '.'); 108 names.add(entryName); 109 try { 110 final Class<?> tmpc = Class.forName(entryName); 111 classes.add(tmpc); 112 } catch (NoClassDefFoundError e) { 113 System.err.println("Unable to instantiate class " + entryName); 114 System.err.println(e.getMessage()); 115 } 116 } 117 } 118 } catch (final Exception e) { 119 System.err.println("Failed to process file: " + packageName); 120 e.printStackTrace(); 121 } 122 } else { 123 // loop through files in classpath 124 125 String packageURLString = packageURL.toString(); 126 try { 127 URI uri = new URI(packageURLString); 128 File folder = new File(uri.getPath()); 129 130 List<String> files = findFiles(folder); 131 for (String s : files) { 132 String entryName = realPackageName + s; 133 134 if (entryName.endsWith(".class") 135 && !entryName.contains("$")) { 136 entryName = entryName.substring(0, 137 entryName.lastIndexOf('.')); 138 entryName = entryName.replace('/', '.'); 139 140 names.add(entryName); 141 classes.add(Class.forName(entryName)); 142 } 143 } 144 } catch (Exception e) { 145 System.err.println("Failed to process file: " 146 + packageURLString); 147 e.printStackTrace(); 148 } 91 149 } 92 } catch (Exception e) { 93 System.err.println("Failed to decode jar file: " 94 + jarFileNameUndecoded); 95 e.printStackTrace(); 96 } 97 } else if (packageURL.getProtocol().equals("bundleresource")) { 98 try { 99 final URLConnection urlConnection = packageURL.openConnection(); 100 final Class<?> c = urlConnection.getClass(); 101 final java.lang.reflect.Method toInvoke = c.getMethod("getFileURL"); 102 final URL fileURL = (URL)toInvoke.invoke(urlConnection); 103 final File folder = new File(fileURL.getFile()); 104 final List<String> files = findFiles(folder); 105 for (final String s : files) { 106 String entryName = realPackageName + s; 107 if (entryName.endsWith(".class") && !entryName.contains("$")) { 108 entryName = entryName.substring(0, entryName.lastIndexOf('.')); 109 entryName = entryName.replace('/', '.'); 110 names.add(entryName); 150 151 return classes; 152 } 153 154 /** 155 * Finds all files in a directory and it's subdirectories 156 * 157 * @param directory 158 * The folder to start in 159 * 160 * @return A list of Strings containing file paths relative to the starting 161 * directory 162 */ 163 private static List<String> findFiles(File directory) { 164 List<String> files = new LinkedList<String>(); 165 for (File f : directory.listFiles()) { 166 if (f.isDirectory()) { 167 for (String s : findFiles(f)) { 168 files.add(f.getName() + "/" + s); 169 } 170 } else { 171 files.add(f.getName()); 172 } 173 } 174 return files; 175 } 176 177 public static List<Class<?>> getClasses(final String pckgname) 178 throws ClassNotFoundException { 179 180 final ArrayList<Class<?>> classes = new ArrayList<Class<?>>(); 181 182 // Must be a forward slash for loading resources 183 final String packagePath = pckgname.replace('.', '/'); 184 185 if (System.getProperty("eclipse.expeditee.home") == null) { 186 final ClassLoader cld = Thread.currentThread() 187 .getContextClassLoader(); 188 if (cld == null) { 189 throw new ClassNotFoundException("Can't get class loader."); 190 } 191 URL resource = null; 111 192 try { 112 final Class<?> tmpc = Class.forName(entryName); 113 classes.add(tmpc); 114 } catch (NoClassDefFoundError e) { 115 System.err.println("Unable to instantiate class " + entryName); 116 System.err.println(e.getMessage()); 117 } 118 } 193 final Enumeration<URL> resources = cld 194 .getResources(packagePath); 195 while (resources.hasMoreElements()) { 196 URL url = resources.nextElement(); 197 resource = url; 198 } 199 } catch (IOException e) { 200 System.err 201 .println("A IO Error has occured when trying to use the ContextClassLoader" 202 + System.getProperty("line.separator") 203 + "Are you running from within Eclipse? (or just not with Jar) Then make sure your" 204 + " 'eclipse.expeditee.home' property is set correctly. It is currently: '" 205 + System.getProperty("eclipse.expeditee.home") 206 + "'" 207 + System.getProperty("line.separator") 208 + "You can set it by adding a VM argument. " 209 + "Example: -Declipse.expeditee.home=D:\\Desktop\\Research\\expeditee-svn"); 210 e.printStackTrace(); 211 } 212 if (resource == null) { 213 throw new ClassNotFoundException("No resource for " 214 + packagePath); 215 } 216 final File directory = new File(resource.getFile()); 217 218 final int splitPoint = directory.getPath().indexOf('!'); 219 if (splitPoint > 0) { 220 String jarName = directory.getPath().substring( 221 "file:".length(), splitPoint); 222 // Windows HACK 223 if (jarName.indexOf(":") >= 0) 224 jarName = jarName.substring(1); 225 226 if (jarName.indexOf("%20") > 0) { 227 jarName = jarName.replace("%20", " "); 228 } 229 // System.out.println("JarName:" + jarName); 230 try { 231 final JarFile jarFile = new JarFile(jarName); 232 final Enumeration<?> entries = jarFile.entries(); 233 while (entries.hasMoreElements()) { 234 final ZipEntry entry = (ZipEntry) entries.nextElement(); 235 final String className = entry.getName(); 236 if (className.startsWith(packagePath)) { 237 if (className.endsWith(".class") 238 && !className.contains("$")) { 239 // The forward slash below is a forwards slash 240 // for 241 // both windows and linux 242 243 String class_forname = className.substring(0, 244 className.length() - 6); 245 class_forname = class_forname.replace('/', '.'); 246 247 classes.add(Class.forName(class_forname)); 248 } 249 } 250 } 251 try { 252 jarFile.close(); 253 } catch (IOException e) { 254 System.err 255 .println("Error attempting to close Jar file"); 256 e.printStackTrace(); 257 } 258 } catch (IOException e) { 259 System.err.println("Error Instantiating Jar File Object"); 260 e.printStackTrace(); 261 } 262 } else { 263 264 System.err 265 .println("A Error has occured when trying to use a Jar file to find actions or agents." 266 + System.getProperty("line.separator") 267 + "Are you running from within Eclipse? (or just not with Jar) Then make sure your" 268 + " 'eclipse.expeditee.home' property is set correctly. It is currently: '" 269 + System.getProperty("eclipse.expeditee.home") 270 + "'" 271 + System.getProperty("line.separator") 272 + "You can set it by adding a VM argument. " 273 + "Example: -Declipse.expeditee.home=D:\\Desktop\\Research\\expeditee-svn"); 274 } 275 } else { 276 String eclipse_expeditee_home = System.getProperty( 277 "eclipse.expeditee.home", ""); 278 String full_package_path = eclipse_expeditee_home + File.separator 279 + "bin" + File.separator + packagePath; 280 281 final File directory = new File(full_package_path); 282 283 if (directory.exists()) { 284 // Get the list of the files contained in the package 285 String[] files = directory.list(); 286 for (int i = 0; i < files.length; i++) { 287 // we are only interested in .class files 288 if (files[i].endsWith(".class") && !files[i].contains("$") 289 && !files[i].equals("Actions.class")) { 290 // removes the .class extension 291 classes.add(Class.forName(pckgname 292 + files[i].substring(0, files[i].length() - 6))); 293 } 294 } 295 } else { 296 throw new ClassNotFoundException("The package '" + pckgname 297 + "' in the directory '" + directory 298 + "' does not appear to be a valid package"); 299 } 119 300 } 120 } catch (final Exception e) { 121 System.err.println("Failed to process file: " + packageName); 122 e.printStackTrace(); 123 } 124 } else { 125 // loop through files in classpath 126 127 String packageURLString = packageURL.toString(); 128 try { 129 URI uri = new URI(packageURLString); 130 File folder = new File(uri.getPath()); 131 132 List<String> files = findFiles(folder); 133 for (String s : files) { 134 String entryName = realPackageName + s; 135 136 if (entryName.endsWith(".class") 137 && !entryName.contains("$")) { 138 entryName = entryName.substring(0, 139 entryName.lastIndexOf('.')); 140 entryName = entryName.replace('/', '.'); 141 142 names.add(entryName); 143 classes.add(Class.forName(entryName)); 144 } 145 } 146 } catch (Exception e) { 147 System.err.println("Failed to process file: " 148 + packageURLString); 149 e.printStackTrace(); 150 } 301 return classes; 151 302 } 152 303 153 return classes;154 }155 156 /**157 * Finds all files in a directory and it's subdirectories158 *159 * @param directory160 * The folder to start in161 *162 * @return A list of Strings containing file paths relative to the starting163 * directory164 */165 private static List<String> findFiles(File directory) {166 List<String> files = new LinkedList<String>();167 for (File f : directory.listFiles()) {168 if (f.isDirectory()) {169 for (String s : findFiles(f)) {170 files.add(f.getName() + "/" + s);171 }172 } else {173 files.add(f.getName());174 }175 }176 return files;177 }178 179 public static List<Class<?>> getClasses(final String pckgname)180 throws ClassNotFoundException {181 182 final ArrayList<Class<?>> classes = new ArrayList<Class<?>>();183 184 // Must be a forward slash for loading resources185 final String packagePath = pckgname.replace('.', '/');186 187 if (System.getProperty("eclipse.expeditee.home") == null) {188 final ClassLoader cld = Thread.currentThread()189 .getContextClassLoader();190 if (cld == null) {191 throw new ClassNotFoundException("Can't get class loader.");192 }193 URL resource = null;194 try {195 final Enumeration<URL> resources = cld196 .getResources(packagePath);197 while (resources.hasMoreElements()) {198 URL url = resources.nextElement();199 resource = url;200 }201 } catch (IOException e) {202 System.err203 .println("A IO Error has occured when trying to use the ContextClassLoader"204 + System.getProperty("line.separator")205 + "Are you running from within Eclipse? (or just not with Jar) Then make sure your"206 + " 'eclipse.expeditee.home' property is set correctly. It is currently: '"207 + System.getProperty("eclipse.expeditee.home")208 + "'"209 + System.getProperty("line.separator")210 + "You can set it by adding a VM argument. "211 + "Example: -Declipse.expeditee.home=D:\\Desktop\\Research\\expeditee-svn");212 e.printStackTrace();213 }214 if (resource == null) {215 throw new ClassNotFoundException("No resource for "216 + packagePath);217 }218 final File directory = new File(resource.getFile());219 220 final int splitPoint = directory.getPath().indexOf('!');221 if (splitPoint > 0) {222 String jarName = directory.getPath().substring(223 "file:".length(), splitPoint);224 // Windows HACK225 if (jarName.indexOf(":") >= 0)226 jarName = jarName.substring(1);227 228 if (jarName.indexOf("%20") > 0) {229 jarName = jarName.replace("%20", " ");230 }231 // System.out.println("JarName:" + jarName);232 try {233 final JarFile jarFile = new JarFile(jarName);234 final Enumeration<?> entries = jarFile.entries();235 while (entries.hasMoreElements()) {236 final ZipEntry entry = (ZipEntry) entries.nextElement();237 final String className = entry.getName();238 if (className.startsWith(packagePath)) {239 if (className.endsWith(".class")240 && !className.contains("$")) {241 // The forward slash below is a forwards slash242 // for243 // both windows and linux244 245 String class_forname = className.substring(0,246 className.length() - 6);247 class_forname = class_forname.replace('/', '.');248 249 classes.add(Class.forName(class_forname));250 }251 }252 }253 try {254 jarFile.close();255 } catch (IOException e) {256 System.err257 .println("Error attempting to close Jar file");258 e.printStackTrace();259 }260 } catch (IOException e) {261 System.err.println("Error Instantiating Jar File Object");262 e.printStackTrace();263 }264 } else {265 266 System.err267 .println("A Error has occured when trying to use a Jar file to find actions or agents."268 + System.getProperty("line.separator")269 + "Are you running from within Eclipse? (or just not with Jar) Then make sure your"270 + " 'eclipse.expeditee.home' property is set correctly. It is currently: '"271 + System.getProperty("eclipse.expeditee.home")272 + "'"273 + System.getProperty("line.separator")274 + "You can set it by adding a VM argument. "275 + "Example: -Declipse.expeditee.home=D:\\Desktop\\Research\\expeditee-svn");276 }277 } else {278 String eclipse_expeditee_home = System.getProperty(279 "eclipse.expeditee.home", "");280 String full_package_path = eclipse_expeditee_home + File.separator281 + "bin" + File.separator + packagePath;282 283 final File directory = new File(full_package_path);284 285 if (directory.exists()) {286 // Get the list of the files contained in the package287 String[] files = directory.list();288 for (int i = 0; i < files.length; i++) {289 // we are only interested in .class files290 if (files[i].endsWith(".class") && !files[i].contains("$")291 && !files[i].equals("Actions.class")) {292 // removes the .class extension293 classes.add(Class.forName(pckgname294 + files[i].substring(0, files[i].length() - 6)));295 }296 }297 } else {298 throw new ClassNotFoundException("The package '" + pckgname299 + "' in the directory '" + directory300 + "' does not appear to be a valid package");301 }302 }303 return classes;304 }305 306 304 } -
trunk/src/org/expeditee/settings/Settings.java
r919 r1102 26 26 27 27 import org.expeditee.gui.AttributeValuePair; 28 import org.expeditee.gui.DisplayIO;29 28 import org.expeditee.gui.Frame; 30 29 import org.expeditee.gui.FrameCreator; … … 32 31 import org.expeditee.gui.FrameUtils; 33 32 import org.expeditee.gui.MessageBay; 34 import org.expeditee.items.Item;35 33 import org.expeditee.items.Text; 36 34 import org.expeditee.items.widgets.Password; … … 56 54 // populate map of settings 57 55 for(Field f : clazz.getFields()) { 58 // only allow valid types 59 if(! Setting.class.isAssignableFrom(f.getType())) { 60 continue; 61 } 56 // Only allow classes that inherit from Setting 57 if(!Setting.class.isAssignableFrom(f.getType())) continue; 58 62 59 try { 63 60 Setting s = (Setting) f.get(null); 64 61 settings.put(f.getName().toLowerCase(), s); 65 if(s instanceof VariableSetting) { 66 settingsList.add((VariableSetting) s); 67 } 62 if (s instanceof VariableSetting) settingsList.add((VariableSetting) s); 68 63 orderedEntries.add(f.getName()); 69 64 } catch (Exception e) { … … 71 66 } 72 67 } 68 73 69 Method m = null; 70 74 71 try { 75 72 m = clazz.getMethod("onParsed", Text.class); … … 77 74 // System.err.println(clazz.getName() + " has no onParsed(Text t) callback"); 78 75 } 76 79 77 this.onParsed = m; 80 78 } 81 79 } 80 82 81 private static HashMap<String, PageDescriptor> _pages = new HashMap<String, PageDescriptor>(); 83 82 84 83 private static boolean _init = false; 85 public static void Init() { 84 85 public static void Init() 86 { 86 87 if(_init) return; 88 87 89 _init = true; 90 88 91 try { 89 92 for(Class<?> clazz : PackageLoader.getClassesNew(SETTINGS_PACKAGE)) { 90 93 // Ignore this class since it's the controller 91 if(clazz.equals(Settings.class)) { 92 continue; 93 } 94 String settingsPage = clazz.getPackage().getName().toLowerCase().substring(SETTINGS_PACKAGE_PARENT.length()); 94 if(clazz.equals(Settings.class)) continue; 95 96 String settingsPageName = clazz.getPackage().getName().toLowerCase().substring(SETTINGS_PACKAGE_PARENT.length()); 95 97 // System.out.println(settingsPage + " : " + clazz.getName()); 96 _pages.put(settingsPage , new PageDescriptor(clazz));98 _pages.put(settingsPageName, new PageDescriptor(clazz)); 97 99 } 98 100 … … 100 102 e.printStackTrace(); 101 103 } 102 FrameUtils.ParseProfile(FrameIO.LoadProfile(UserSettings.ProfileName.get())); 103 } 104 105 /** 106 * Parses the settings tree, then resets any settings that were not set 107 */ 108 public static void parseSettings(Text text) { 104 } 105 106 /** Parses the settings tree, then resets any settings that were not set. */ 107 public static void parseSettings(Text text) 108 { 109 109 List<VariableSetting> set = parseSettings(text, ""); 110 110 List<VariableSetting> toDefault = new LinkedList<VariableSetting>(); 111 for(PageDescriptor pd : _pages.values()) {112 113 }111 112 for(PageDescriptor pd : _pages.values()) toDefault.addAll(pd.settingsList); 113 114 114 toDefault.removeAll(set); 115 115 116 for(VariableSetting s : toDefault) { 116 117 try { 117 // System.out.println("Resetting " + s.getTooltip());118 118 s.reset(); 119 // System.out.println("Set " + f.getName() + " to default value " + f.get(null));120 119 } catch (Exception e) { 121 120 e.printStackTrace(); … … 135 134 136 135 List<VariableSetting> set = new LinkedList<VariableSetting>(); 136 137 137 Frame child = text.getChild(); 138 if(child == null) {139 140 }138 139 if(child == null) return set; 140 141 141 String settingsPage = prefix + text.getText().trim().toLowerCase().replaceAll("^@", ""); 142 142 PageDescriptor pd = _pages.get(settingsPage); 143 if(pd == null) { 144 return set; 145 } 143 if(pd == null) return set; 144 146 145 try { 147 146 // set the fields … … 160 159 } 161 160 } 161 162 162 // parse all the settings items on this page 163 163 for(Text t : items) { … … 186 186 } 187 187 } 188 // System.out.println(s); 189 if(s == null) { 190 continue; 191 } 188 189 if(s == null) continue; 190 192 191 if(validPages.size() > 1) { 193 192 StringBuffer warnMessage = new StringBuffer("Found multiple matching settings in the following settings subpages: "); … … 202 201 } 203 202 } 204 if(s.setSetting(t) && s instanceof VariableSetting) {205 206 }203 204 if(s.setSetting(t) && s instanceof VariableSetting) set.add((VariableSetting) s); 205 207 206 } catch (Exception e) { 208 207 e.printStackTrace(); 209 208 } 210 209 } 210 211 211 // call the onParsed method if one exists 212 212 if(pd.onParsed != null) { 213 213 pd.onParsed.invoke(null, text); 214 214 } 215 215 216 } catch (Exception e) { 216 217 e.printStackTrace(); 217 218 return set; 218 219 } 220 219 221 // if the page was a settings page, check if it has any subpages 220 222 for(Text t : child.getTextItems()) { … … 224 226 } 225 227 226 public static void generateSettingsTree(Text link) { 228 public static void generateSettingsTree(Text link) 229 { 227 230 generateSettingsTree("settings", link); 228 231 } 229 232 230 /** 231 * 232 * Generates settings tree 233 * 234 */ 235 private static void generateSettingsTree(String page, Text text) { 233 /** Generates settings tree */ 234 private static void generateSettingsTree(String page, Text text) 235 { 236 236 FrameCreator frames = new FrameCreator(text.getParentOrCurrentFrame().getFramesetName(), text.getParentOrCurrentFrame().getPath(), page, false, false); 237 237 // Frame frame = FrameIO.CreateFrame(text.getParentOrCurrentFrame().getFramesetName(), page, null); -
trunk/src/org/expeditee/settings/network/proxy/ProxySettings.java
r919 r1102 23 23 import org.expeditee.items.Item; 24 24 import org.expeditee.items.Text; 25 import org.expeditee.items.widgets.InteractiveWidget; 25 import org.expeditee.items.widgets.Widget; 26 import org.expeditee.items.widgets.JavaFXSwingWidget; 26 27 import org.expeditee.items.widgets.Password; 27 28 import org.expeditee.items.widgets.WidgetCorner; … … 52 53 if (passwordWidget == null) { 53 54 try { 54 passwordWidget = (Password) InteractiveWidget.createWidget((Text) i);55 passwordWidget = (Password) Widget.createWidget((Text) i); 55 56 if (Pass.get() != null) { 56 57 // MessageBay.displayMessage("pass was defined multiple times!", Color.ORANGE); … … 65 66 } else if(i instanceof WidgetCorner || i instanceof WidgetEdge) { 66 67 if(passwordWidget == null) { 67 InteractiveWidget iw;68 Widget iw; 68 69 if(i instanceof WidgetCorner) { 69 70 iw = ((WidgetCorner)i).getWidgetSource(); … … 73 74 if(iw instanceof Password) { 74 75 passwordWidget = (Password) iw; 76 } else if (iw instanceof JavaFXSwingWidget && ((JavaFXSwingWidget) iw).getSwingWidget() instanceof Password) { 77 passwordWidget = (Password) ((JavaFXSwingWidget) iw).getSwingWidget(); 75 78 } 76 79 if(Pass.get() != null) { -
trunk/src/org/expeditee/settings/templates/TemplateSettings.java
r919 r1102 19 19 package org.expeditee.settings.templates; 20 20 21 import java.awt.Color; 22 23 import org.expeditee.gui.DisplayIO; 21 import org.expeditee.core.Colour; 22 import org.expeditee.gui.DisplayController; 24 23 import org.expeditee.gui.Frame; 25 24 import org.expeditee.gui.FrameUtils; … … 50 49 i.setParent(null); 51 50 } 52 Display IO.setCursor(Item.HIDDEN_CURSOR);53 Display IO.setCursor(Item.DEFAULT_CURSOR);51 DisplayController.setCursor(Item.HIDDEN_CURSOR); 52 DisplayController.setCursor(Item.DEFAULT_CURSOR); 54 53 } 55 54 }; 56 55 57 public static final ArraySetting<Colo r> ColorWheel = new ArraySetting<Color>("The colours of items in the child frame are used to populate the colour wheel",58 new Colo r[] { Color.BLACK, Color.RED, Color.BLUE, Item.GREEN, Color.MAGENTA, Color.YELLOW.darker(), Color.WHITE }) {56 public static final ArraySetting<Colour> ColorWheel = new ArraySetting<Colour>("The colours of items in the child frame are used to populate the colour wheel", 57 new Colour[] { Colour.BLACK, Colour.RED, Colour.BLUE, Item.GREEN, Colour.MAGENTA, Colour.YELLOW.darker(), Colour.WHITE }) { 59 58 @Override 60 59 public boolean setSetting(Text text) { … … 68 67 }; 69 68 70 public static final ArraySetting<Colo r> FillColorWheel = new ArraySetting<Color>("The colours of items in the child frame are used to populate the colour wheel",71 new Colo r[] { new Color(255, 150, 150), new Color(150, 150, 255), new Color(150, 255, 150),72 new Color(255, 150, 255), new Color(255, 255, 100), Color.WHITE, Color.BLACK }) {69 public static final ArraySetting<Colour> FillColorWheel = new ArraySetting<Colour>("The colours of items in the child frame are used to populate the colour wheel", 70 new Colour[] { Colour.FromRGB255(255, 150, 150), Colour.FromRGB255(150, 150, 255), Colour.FromRGB255(150, 255, 150), 71 Colour.FromRGB255(255, 150, 255), Colour.FromRGB255(255, 255, 100), Colour.WHITE, Colour.BLACK }) { 73 72 @Override 74 73 public boolean setSetting(Text text) { … … 82 81 }; 83 82 84 public static final ArraySetting<Colo r> BackgroundColorWheel = new ArraySetting<Color>("The colours of items in the child frame are used to populate the colour wheel",85 new Colo r[] { new Color(235, 235, 235), new Color(225, 225, 255), new Color(195, 255, 255),86 new Color(225, 255, 225), new Color(255, 255, 195), new Color(255, 225, 225),87 new Color(255, 195, 255), Color.WHITE, Color.GRAY, Color.DARK_GRAY, Color.BLACK, null }) {83 public static final ArraySetting<Colour> BackgroundColorWheel = new ArraySetting<Colour>("The colours of items in the child frame are used to populate the colour wheel", 84 new Colour[] { Colour.FromRGB255(235, 235, 235), Colour.FromRGB255(225, 225, 255), Colour.FromRGB255(195, 255, 255), 85 Colour.FromRGB255(225, 255, 225), Colour.FromRGB255(255, 255, 195), Colour.FromRGB255(255, 225, 225), 86 Colour.FromRGB255(255, 195, 255), Colour.WHITE, Colour.GREY, Colour.DARK_GREY, Colour.BLACK, null }) { 88 87 @Override 89 88 public boolean setSetting(Text text) { … … 107 106 public Text generateText() { 108 107 Text t = new Text("AnnotationTemplate"); 109 t.setColor(Colo r.gray);108 t.setColor(Colour.GREY); 110 109 return t; 111 110 } … … 116 115 public Text generateText() { 117 116 Text t = new Text("CommentTemplate"); 118 t.setColor(Colo r.green.darker());117 t.setColor(Colour.GREEN.darker()); 119 118 return t; 120 119 } … … 125 124 public Text generateText() { 126 125 Text t = new Text("StatsTemplate"); 127 t.setColor(Colo r.BLACK);128 t.setBackgroundColor(new Colo r(0.9F, 0.9F, 0.9F));126 t.setColor(Colour.BLACK); 127 t.setBackgroundColor(new Colour(0.9F, 0.9F, 0.9F)); 129 128 t.setFamily(Text.MONOSPACED_FONT); 130 129 t.setSize(14); … … 140 139 t.setFontStyle("Bold"); 141 140 t.setFamily("SansSerif"); 142 t.setColor(Colo r.BLUE);141 t.setColor(Colour.BLUE); 143 142 t.setPosition(25, 50); 144 143 return t; … … 157 156 public Text generateText() { 158 157 Text t = new Text("TooltipTemplate"); 159 t.setColor(Colo r.BLACK);160 t.setBackgroundColor(new Colo r(0.7F, 0.7F, 0.9F));158 t.setColor(Colour.BLACK); 159 t.setBackgroundColor(new Colour(0.7F, 0.7F, 0.9F)); 161 160 // t.setFamily(Text.MONOSPACED_FONT); 162 161 t.setSize(14); -
trunk/src/org/expeditee/stats/SessionStats.java
r919 r1102 19 19 package org.expeditee.stats; 20 20 21 import java.awt.event.KeyEvent;22 import java.awt.event.MouseEvent;23 21 import java.sql.Time; 24 22 import java.util.ArrayList; … … 27 25 import java.util.List; 28 26 29 import org.expeditee.gui.DisplayIO; 27 import org.expeditee.gio.input.KBMInputEvent; 28 import org.expeditee.gui.DisplayController; 30 29 import org.expeditee.gui.Frame; 31 import org.expeditee.gui.FrameMouseActions;32 30 import org.expeditee.gui.FrameUtils; 33 31 import org.expeditee.gui.TimeKeeper; … … 103 101 stats.append(getCharacterStats()); 104 102 105 stats.append("Version: ").append(Display IO.TITLE);103 stats.append("Version: ").append(DisplayController.TITLE); 106 104 107 105 return stats.toString(); … … 159 157 chars += counts[i]; 160 158 161 chars -= counts[ KeyEvent.VK_BACK_SPACE];162 chars -= counts[ KeyEvent.VK_DELETE];159 chars -= counts[Text.BACKSPACE_CHARACTER]; 160 chars -= counts[Text.DELETE_CHARACTER]; 163 161 164 162 int EOS = counts['.'] + counts[','] + counts['!'] + counts['?']; … … 177 175 appendStat(stats, "Escape", _EscapeCount); 178 176 appendStat(stats, "Backspace", _BackspaceCount); 179 appendStat(stats, "Left", _MouseCounters[ MouseEvent.BUTTON1]);180 appendStat(stats, "Middle", _MouseCounters[ MouseEvent.BUTTON2]);181 appendStat(stats, "Right", _MouseCounters[ MouseEvent.BUTTON3]);177 appendStat(stats, "Left", _MouseCounters[KBMInputEvent.MouseButton.LEFT.ordinal()]); 178 appendStat(stats, "Middle", _MouseCounters[KBMInputEvent.MouseButton.MIDDLE.ordinal()]); 179 appendStat(stats, "Right", _MouseCounters[KBMInputEvent.MouseButton.RIGHT.ordinal()]); 182 180 183 181 return stats.toString(); … … 231 229 * ascii value for the typed character 232 230 */ 233 public static void TypedChar(int ch) {234 if (ch == KeyEvent.VK_BACK_SPACE || ch == KeyEvent.VK_DELETE)235 231 public static void TypedChar(int ch) 232 { 233 if (ch == ((int) Text.BACKSPACE_CHARACTER) || ch == ((int) Text.DELETE_CHARACTER)) _BackspaceCount++; 236 234 UserEvent(); 237 235 _CharCounts[ch]++; … … 252 250 253 251 _FrameEvents.add(Formatter.getTimeWithMillis(elapsedTime) + " " 254 + Display IO.getMouseX() + " " + FrameMouseActions.getY() + " "252 + DisplayController.getMouseX() + " " + DisplayController.getMouseY() + " " 255 253 + description); 256 254 } … … 278 276 } 279 277 280 public static void MouseClicked( intbutton) {278 public static void MouseClicked(KBMInputEvent.MouseButton button) { 281 279 UserEvent(); 282 _MouseCounters[button ]++;280 _MouseCounters[button.ordinal()]++; 283 281 } 284 282 -
trunk/src/org/expeditee/stats/StatsFrame.java
r919 r1102 19 19 package org.expeditee.stats; 20 20 21 import java.awt.event.MouseEvent;22 21 import java.lang.reflect.Method; 23 22 import java.util.HashMap; 24 23 import java.util.Map; 24 25 import org.expeditee.gio.input.KBMInputEvent; 25 26 26 27 public class StatsFrame extends SessionStats { … … 162 163 163 164 public static String getLeftButtonCount() { 164 return _MouseCounters[ MouseEvent.BUTTON1] + "";165 return _MouseCounters[KBMInputEvent.MouseButton.LEFT.ordinal()] + ""; 165 166 } 166 167 167 168 public static String getMiddleButtonCount() { 168 return _MouseCounters[ MouseEvent.BUTTON2] + "";169 return _MouseCounters[KBMInputEvent.MouseButton.MIDDLE.ordinal()] + ""; 169 170 } 170 171 171 172 public static String getRightButtonCount() { 172 return _MouseCounters[ MouseEvent.BUTTON3] + "";173 return _MouseCounters[KBMInputEvent.MouseButton.RIGHT.ordinal()] + ""; 173 174 } 174 175 } -
trunk/src/org/expeditee/taskmanagement/EntitySaveManager.java
r919 r1102 24 24 import java.util.Set; 25 25 26 import javax.swing.SwingUtilities;27 28 26 29 27 /** 30 * Manages time/resource-consuming saving procedures. For enti es in an expeditee Frame that28 * Manages time/resource-consuming saving procedures. For entities in an expeditee Frame that 31 29 * requires heavy-duty saving, implement the entity as a SaveableEntity. 32 30 * … … 135 133 * Saves all current registered entities and clears registrations. 136 134 * 137 * Returns immediat ly.135 * Returns immediately. 138 136 */ 139 137 public synchronized void saveAll() { … … 167 165 /** 168 166 * If something is saving, this will block the thread until all entities that 169 * have been requested to be saved has finished their saving proc cesses.167 * have been requested to be saved has finished their saving processes. 170 168 * 171 169 * @throws InterruptedException … … 237 235 if (entity.doesNeedSaving()) { 238 236 239 // notify observers that save has started - on swing thread240 SwingUtilities.invokeLater(new SafeFireEvent(entity, true));237 // notify observers that save has started 238 (new SafeFireEvent(entity, true)).run(); 241 239 242 240 // Complete the save … … 248 246 249 247 // notify observers that save has finished - on swing thread 250 SwingUtilities.invokeLater(new SafeFireEvent(entity, false));248 (new SafeFireEvent(entity, false)).run(); 251 249 } 252 250 } … … 254 252 255 253 /** 256 * Notifies all list ners of save start/completion event when run.254 * Notifies all listeners of save start/completion event when run. 257 255 * 258 256 * @author Brook Novak -
trunk/tests/org/expeditee/gui/AttributeValuePairTest.java
r310 r1102 1 1 package org.expeditee.gui; 2 3 import java.awt.Color;4 2 5 3 import junit.framework.TestCase; 6 4 5 import org.expeditee.core.Colour; 7 6 import org.expeditee.items.Text; 8 7 … … 35 34 attributes.setText("c:red"); 36 35 assertTrue(AttributeUtils.setAttribute(attributes, attributes)); 37 assertEquals(Colo r.red, attributes.getColor());36 assertEquals(Colour.RED, attributes.getColor()); 38 37 attributes.setText("color:green"); 39 38 assertTrue(AttributeUtils.setAttribute(attributes, attributes)); 40 assertEquals(Colo r.green, attributes.getColor());39 assertEquals(Colour.GREEN, attributes.getColor()); 41 40 } 42 41 -
trunk/tests/org/expeditee/gui/DisplayIOTest.java
r361 r1102 11 11 showBlankFrame(); 12 12 13 Display IO.ToggleTwinFrames();14 assertTrue(Display IO.isTwinFramesOn());15 Display IO.ToggleTwinFrames();16 assertFalse(Display IO.isTwinFramesOn());13 DisplayController.toggleTwinFrames(); 14 assertTrue(DisplayController.isTwinFramesOn()); 15 DisplayController.toggleTwinFrames(); 16 assertFalse(DisplayController.isTwinFramesOn()); 17 17 } 18 18 … … 22 22 23 23 //Draw a rectangle 24 Display IO.setCursorPosition(250, 250);24 DisplayController.setCursorPosition(250, 250); 25 25 Thread.sleep(100); 26 Display IO.clickMouse(InputEvent.BUTTON3_MASK);26 DisplayController.clickMouse(InputEvent.BUTTON3_MASK); 27 27 Thread.sleep(100); 28 Display IO.setCursorPosition(500, 500);28 DisplayController.setCursorPosition(500, 500); 29 29 Thread.sleep(100); 30 Display IO.clickMouse(InputEvent.BUTTON3_MASK);30 DisplayController.clickMouse(InputEvent.BUTTON3_MASK); 31 31 Thread.sleep(1000); 32 32 //Check that the line is there … … 42 42 public static void drawLine() throws InterruptedException { 43 43 //Draw a line 44 Display IO.setCursorPosition(100, 100);44 DisplayController.setCursorPosition(100, 100); 45 45 Thread.sleep(500); 46 Display IO.clickMouse(InputEvent.BUTTON2_MASK);46 DisplayController.clickMouse(InputEvent.BUTTON2_MASK); 47 47 Thread.sleep(100); 48 Display IO.setCursorPosition(200, 200);48 DisplayController.setCursorPosition(200, 200); 49 49 Thread.sleep(100); 50 Display IO.clickMouse(InputEvent.BUTTON2_MASK);50 DisplayController.clickMouse(InputEvent.BUTTON2_MASK); 51 51 Thread.sleep(100); 52 52 } -
trunk/tests/org/expeditee/gui/FrameKeyboardsActionsTest.java
r347 r1102 12 12 public final void testTypeText() throws Exception { 13 13 Frame testFrame = showBlankFrame(); 14 Display IO.typeKey(KeyEvent.VK_ESCAPE);15 Display IO.typeText("hello");14 DisplayController.typeKey(KeyEvent.VK_ESCAPE); 15 DisplayController.typeText("hello"); 16 16 // Pick the item up in the middle 17 17 Item currentItem = FrameUtils.getCurrentItem(); 18 18 assertNotNull(currentItem); 19 Display IO.setCursorPosition(currentItem.getX()19 DisplayController.setCursorPosition(currentItem.getX() 20 20 + currentItem.getBoundsWidth() / 2, 21 21 FrameMouseActions.MouseY - 2); 22 22 Thread.sleep(DELAY); 23 Display IO.clickMouse(InputEvent.BUTTON2_MASK);23 DisplayController.clickMouse(InputEvent.BUTTON2_MASK); 24 24 Thread.sleep(DELAY); 25 Display IO.setCursorPosition(25 DisplayController.setCursorPosition( 26 26 Math.round(FrameGraphics.getMaxFrameSize().getWidth() / 2), 27 27 FrameMouseActions.MouseY); 28 28 Thread.sleep(DELAY); 29 Display IO.typeKey(KeyEvent.VK_ESCAPE);29 DisplayController.typeKey(KeyEvent.VK_ESCAPE); 30 30 Thread.sleep(DELAY); 31 Display IO.clickMouse(InputEvent.BUTTON2_MASK);31 DisplayController.clickMouse(InputEvent.BUTTON2_MASK); 32 32 Thread.sleep(DELAY); 33 33 … … 35 35 assertEquals(currentItem.getX(), FrameMouseActions.getX()); 36 36 37 Display IO.typeKey(KeyEvent.VK_ESCAPE);37 DisplayController.typeKey(KeyEvent.VK_ESCAPE); 38 38 39 Display IO.typeStringDirect(0.05, "Hello Again!");39 DisplayController.typeStringDirect(0.05, "Hello Again!"); 40 40 41 Display IO.typeKey(KeyEvent.VK_ESCAPE);41 DisplayController.typeKey(KeyEvent.VK_ESCAPE); 42 42 43 Display IO.typeText("Hello Again");43 DisplayController.typeText("Hello Again"); 44 44 45 45 assertEquals(4, testFrame.getItems(false).size()); -
trunk/tests/org/expeditee/gui/FrameMouseActionsTest.java
r361 r1102 16 16 testLeftRanging(title); 17 17 18 String newFrameName = Display IO.getCurrentFrame().getName();18 String newFrameName = DisplayController.getCurrentFrame().getName(); 19 19 Navigation.Back(); 20 20 … … 30 30 DisplayIOTest.drawLine(); 31 31 32 newFrameName = Display IO.getCurrentFrame().getName();32 newFrameName = DisplayController.getCurrentFrame().getName(); 33 33 Navigation.Back(); 34 34 … … 45 45 private void testLeftRanging(Text title) throws InterruptedException { 46 46 int y = title.getY() - 2; 47 Display IO.setCursorPosition(title.getX(), y);47 DisplayController.setCursorPosition(title.getX(), y); 48 48 Thread.sleep(500); 49 Display IO.pressMouse(InputEvent.BUTTON1_MASK);49 DisplayController.pressMouse(InputEvent.BUTTON1_MASK); 50 50 Thread.sleep(100); 51 Display IO.setCursorPosition(title.getX() + title.getBoundsWidth() / 2,51 DisplayController.setCursorPosition(title.getX() + title.getBoundsWidth() / 2, 52 52 y); 53 53 Thread.sleep(500); 54 Display IO.releaseMouse(InputEvent.BUTTON1_MASK);54 DisplayController.releaseMouse(InputEvent.BUTTON1_MASK); 55 55 Thread.sleep(100); 56 56 … … 59 59 60 60 // Highlight then unhighlight 61 Display IO.setCursorPosition(title.getX(), y);61 DisplayController.setCursorPosition(title.getX(), y); 62 62 Thread.sleep(500); 63 Display IO.pressMouse(InputEvent.BUTTON1_MASK);63 DisplayController.pressMouse(InputEvent.BUTTON1_MASK); 64 64 Thread.sleep(100); 65 Display IO.setCursorPosition(title.getX() + title.getBoundsWidth() / 2,65 DisplayController.setCursorPosition(title.getX() + title.getBoundsWidth() / 2, 66 66 y); 67 67 Thread.sleep(500); 68 Display IO.setCursorPosition(title.getX(), y);68 DisplayController.setCursorPosition(title.getX(), y); 69 69 Thread.sleep(500); 70 Display IO.releaseMouse(InputEvent.BUTTON1_MASK);70 DisplayController.releaseMouse(InputEvent.BUTTON1_MASK); 71 71 Thread.sleep(500); 72 72 -
trunk/tests/org/expeditee/gui/FreeItemsTest.java
r330 r1102 13 13 14 14 FrameMouseActions.pickup(testFrame.getTitleItem()); 15 assertTrue(FreeItems. itemsAttachedToCursor());15 assertTrue(FreeItems.hasItemsAttachedToCursor()); 16 16 assertTrue(FreeItems.textOnlyAttachedToCursor()); 17 17 18 18 FrameMouseActions.anchor(FreeItems.getInstance()); 19 assertFalse(FreeItems. itemsAttachedToCursor());19 assertFalse(FreeItems.hasItemsAttachedToCursor()); 20 20 assertFalse(FreeItems.textOnlyAttachedToCursor()); 21 21 22 22 FrameMouseActions.pickup(testFrame.getAllItems()); 23 assertTrue(FreeItems. itemsAttachedToCursor());23 assertTrue(FreeItems.hasItemsAttachedToCursor()); 24 24 assertFalse(FreeItems.textOnlyAttachedToCursor()); 25 25 assertEquals(8, FreeItems.getTextItems().size()); … … 31 31 32 32 FrameMouseActions.anchor(FreeItems.getInstance()); 33 assertFalse(FreeItems. itemsAttachedToCursor());33 assertFalse(FreeItems.hasItemsAttachedToCursor()); 34 34 assertFalse(FreeItems.textOnlyAttachedToCursor()); 35 35 } -
trunk/tests/org/expeditee/gui/GuiTestCase.java
r330 r1102 18 18 Frame testFrame = FrameIO.LoadFrame("ExpediteeTest1"); 19 19 testFrame.clear(false); 20 Display IO.setCurrentFrame(testFrame, true);20 DisplayController.setCurrentFrame(testFrame, true); 21 21 return testFrame; 22 22 } … … 25 25 Frame testFrame = FrameIO.LoadFrame(frameName); 26 26 testFrame.clear(false); 27 Display IO.setCurrentFrame(testFrame, true);27 DisplayController.setCurrentFrame(testFrame, true); 28 28 return testFrame; 29 29 } -
trunk/tests/org/expeditee/io/ConversionTest.java
r428 r1102 1 1 package org.expeditee.io; 2 2 3 import java.awt.Color;4 3 import java.awt.Font; 5 4 import java.awt.Point; … … 10 9 import junit.framework.TestCase; 11 10 11 import org.expeditee.core.Colour; 12 12 import org.expeditee.items.Item; 13 13 import org.expeditee.items.Justification; … … 17 17 18 18 public final void testGetColor() { 19 assertEquals(null, Conversion.getColor("TrAnSpArEnT", Colo r.white));20 assertEquals(null, Conversion.getColor("Clear", Colo r.white));21 assertEquals(null, Conversion.getColor("Auto", Colo r.white));22 assertEquals(null, Conversion.getColor("Default", Colo r.white));23 assertEquals(null, Conversion.getColor("adf", Colo r.red));24 assertEquals(null, Conversion.getColor("none", Colo r.red));25 assertEquals(null, Conversion.getColor("null", Colo r.red));26 assertEquals(null, Conversion.getColor(null, Colo r.red));27 assertEquals(null, Conversion.getColor("a0a0a0", Colo r.white));28 29 assertEquals(Colo r.red, Conversion.getColor("100 0 0", Color.white));30 assertEquals(Colo r.green, Conversion.getColor("0 100 0", Color.white));31 assertEquals(Colo r.blue, Conversion.getColor("0 0 100", Color.white));32 assertEquals(Colo r.white, Conversion.getColor("100 100 100",33 Colo r.white));34 assertEquals(Colo r.gray, Conversion.getColor("50 50 50", Color.white));35 assertEquals(Colo r.green, Conversion.getColor("-100 +0 -100",36 Colo r.white));37 assertEquals(Colo r.green, Conversion.getColor("-10 +100 +0",38 Colo r.black));39 assertEquals(Colo r.green, Conversion.getColor("+0 +110 +0", null));40 41 assertEquals(Conversion.getColor("red9", Colo r.white), new Color(0.9F,19 assertEquals(null, Conversion.getColor("TrAnSpArEnT", Colour.WHITE)); 20 assertEquals(null, Conversion.getColor("Clear", Colour.WHITE)); 21 assertEquals(null, Conversion.getColor("Auto", Colour.WHITE)); 22 assertEquals(null, Conversion.getColor("Default", Colour.WHITE)); 23 assertEquals(null, Conversion.getColor("adf", Colour.RED)); 24 assertEquals(null, Conversion.getColor("none", Colour.RED)); 25 assertEquals(null, Conversion.getColor("null", Colour.RED)); 26 assertEquals(null, Conversion.getColor(null, Colour.RED)); 27 assertEquals(null, Conversion.getColor("a0a0a0", Colour.WHITE)); 28 29 assertEquals(Colour.RED, Conversion.getColor("100 0 0", Colour.WHITE)); 30 assertEquals(Colour.GREEN, Conversion.getColor("0 100 0", Colour.WHITE)); 31 assertEquals(Colour.BLUE, Conversion.getColor("0 0 100", Colour.WHITE)); 32 assertEquals(Colour.WHITE, Conversion.getColor("100 100 100", 33 Colour.WHITE)); 34 assertEquals(Colour.GREY, Conversion.getColor("50 50 50", Colour.WHITE)); 35 assertEquals(Colour.GREEN, Conversion.getColor("-100 +0 -100", 36 Colour.WHITE)); 37 assertEquals(Colour.GREEN, Conversion.getColor("-10 +100 +0", 38 Colour.BLACK)); 39 assertEquals(Colour.GREEN, Conversion.getColor("+0 +110 +0", null)); 40 41 assertEquals(Conversion.getColor("red9", Colour.WHITE), new Colour(0.9F, 42 42 0.0F, 0.0F)); 43 assertEquals(Conversion.getColor("BlUe15", Colo r.white), new Color(43 assertEquals(Conversion.getColor("BlUe15", Colour.WHITE), new Colour( 44 44 0.0F, 0.0F, 1.0F)); 45 assertEquals(Conversion.getColor("GREEN0", Colo r.white), new Color(45 assertEquals(Conversion.getColor("GREEN0", Colour.WHITE), new Colour( 46 46 0.0F, 0.0F, 0.0F)); 47 assertEquals(Conversion.getColor("GREEN3", Colo r.white), new Color(47 assertEquals(Conversion.getColor("GREEN3", Colour.WHITE), new Colour( 48 48 0.0F, 0.3F, 0.0F)); 49 assertEquals(Conversion.getColor("Blue1", Colo r.white), new Color(0.0F,49 assertEquals(Conversion.getColor("Blue1", Colour.WHITE), new Colour(0.0F, 50 50 0.0F, 0.1F)); 51 51 } 52 52 53 53 public final void testGetExpediteeColorCode() { 54 assertTrue(Conversion.getExpediteeColorCode(Colo r.red)54 assertTrue(Conversion.getExpediteeColorCode(Colour.RED) 55 55 .equals("100 0 0")); 56 assertTrue(Conversion.getExpediteeColorCode(Colo r.green).equals(56 assertTrue(Conversion.getExpediteeColorCode(Colour.GREEN).equals( 57 57 "0 100 0")); 58 assertTrue(Conversion.getExpediteeColorCode(Colo r.blue).equals(58 assertTrue(Conversion.getExpediteeColorCode(Colour.BLUE).equals( 59 59 "0 0 100")); 60 60 } … … 127 127 128 128 // Test Color Conversion 129 assertEquals(Colo r.darkGray, Conversion.Convert(Color.class,129 assertEquals(Colour.DARK_GREY, Conversion.Convert(Colour.class, 130 130 "dark_gray")); 131 assertEquals(Colo r.darkGray, Conversion132 .Convert(Colo r.class, "DARKGRAY"));133 assertEquals(Colo r.red, Conversion.Convert(Color.class, "red"));134 assertEquals(Colo r.red, Conversion.Convert(Color.class, "Red"));135 assertEquals(Colo r.red, Conversion.Convert(Color.class, "RED"));136 assertEquals(Colo r.red, Conversion.Convert(Color.class, " 100 "));137 assertEquals(Colo r.green, Conversion.Convert(Color.class, "0 100"));138 assertEquals(Colo r.blue, Conversion.Convert(Color.class, "0 0 100"));131 assertEquals(Colour.DARK_GREY, Conversion 132 .Convert(Colour.class, "DARKGRAY")); 133 assertEquals(Colour.RED, Conversion.Convert(Colour.class, "red")); 134 assertEquals(Colour.RED, Conversion.Convert(Colour.class, "Red")); 135 assertEquals(Colour.RED, Conversion.Convert(Colour.class, "RED")); 136 assertEquals(Colour.RED, Conversion.Convert(Colour.class, " 100 ")); 137 assertEquals(Colour.GREEN, Conversion.Convert(Colour.class, "0 100")); 138 assertEquals(Colour.BLUE, Conversion.Convert(Colour.class, "0 0 100")); 139 139 // Test Boolean Conversion 140 140 assertEquals(true, Conversion.Convert(boolean.class, "")); … … 151 151 152 152 public final void testConvertClassStringObject() { 153 assertEquals( new Color(255, 0, 255), Conversion.Convert(Color.class,153 assertEquals(Colour.FromRGB255(255, 0, 255), Conversion.Convert(Colour.class, 154 154 "+100 +0 +100", null)); 155 assertEquals(Colo r.red, Conversion.Convert(Color.class, "+100 +0 -100",156 Colo r.blue));157 assertEquals(Colo r.black, Conversion.Convert(Color.class, "-0 +0 -100",158 Colo r.blue));155 assertEquals(Colour.RED, Conversion.Convert(Colour.class, "+100 +0 -100", 156 Colour.BLUE)); 157 assertEquals(Colour.BLACK, Conversion.Convert(Colour.class, "-0 +0 -100", 158 Colour.BLUE)); 159 159 // Float test 160 160 assertEquals(2.0F, Conversion.Convert(float.class, "2.0", null)); … … 305 305 306 306 assertEquals("100 0 0", Conversion.ConvertToExpeditee(getPosition, 307 Colo r.red));307 Colour.RED)); 308 308 309 309 assertEquals(null, Conversion.ConvertToExpeditee(getPosition, null)); … … 325 325 326 326 public final void testGetCssColor() { 327 assertEquals("rgb(255,0,0)", Conversion.getCssColor(Colo r.red));328 assertEquals("rgb(255,0,255)", Conversion.getCssColor(Colo r.magenta));329 assertEquals("rgb(128,128,128)", Conversion.getCssColor(Colo r.gray));327 assertEquals("rgb(255,0,0)", Conversion.getCssColor(Colour.RED)); 328 assertEquals("rgb(255,0,255)", Conversion.getCssColor(Colour.MAGENTA)); 329 assertEquals("rgb(128,128,128)", Conversion.getCssColor(Colour.GREY)); 330 330 } 331 331 } -
trunk/tests/org/expeditee/items/widgets/InteractiveWidgetTest.java
r227 r1102 7 7 public void testParseArgs1() { 8 8 9 assertNull( InteractiveWidget.parseArgs(null));10 assertNull( InteractiveWidget.parseArgs(""));11 assertNull( InteractiveWidget.parseArgs(" "));9 assertNull(Widget.parseArgs(null)); 10 assertNull(Widget.parseArgs("")); 11 assertNull(Widget.parseArgs(" ")); 12 12 13 String[] args = InteractiveWidget.parseArgs("arg1");13 String[] args = Widget.parseArgs("arg1"); 14 14 assertEquals(1, args.length); 15 15 assertEquals("arg1", args[0]); 16 16 17 args = InteractiveWidget.parseArgs("arg1 arg2");17 args = Widget.parseArgs("arg1 arg2"); 18 18 assertEquals(2, args.length); 19 19 assertEquals("arg1", args[0]); 20 20 assertEquals("arg2", args[1]); 21 21 22 args = InteractiveWidget.parseArgs(" )*^*$^ 24224 5775 13 : ");22 args = Widget.parseArgs(" )*^*$^ 24224 5775 13 : "); 23 23 assertEquals(5, args.length); 24 24 assertEquals(")*^*$^", args[0]); … … 31 31 public void testParseArgs2() { 32 32 33 String[] args = InteractiveWidget.parseArgs("\"");33 String[] args = Widget.parseArgs("\""); 34 34 assertNull(args); 35 35 36 args = InteractiveWidget.parseArgs("\"\"");36 args = Widget.parseArgs("\"\""); 37 37 assertEquals(1, args.length); 38 38 assertEquals("\"", args[0]); 39 39 40 args = InteractiveWidget.parseArgs("\"\"\"\"\"\"\"");40 args = Widget.parseArgs("\"\"\"\"\"\"\""); 41 41 assertEquals(1, args.length); 42 42 assertEquals("\"\"\"", args[0]); 43 43 44 args = InteractiveWidget.parseArgs(" \" \" ");44 args = Widget.parseArgs(" \" \" "); 45 45 assertEquals(1, args.length); 46 46 assertEquals(" ", args[0]); 47 47 48 args = InteractiveWidget.parseArgs("arg1\" \"");48 args = Widget.parseArgs("arg1\" \""); 49 49 assertEquals(1, args.length); 50 50 assertEquals("arg1 ", args[0]); 51 51 52 args = InteractiveWidget.parseArgs("arg1\" \"+8");52 args = Widget.parseArgs("arg1\" \"+8"); 53 53 assertEquals(1, args.length); 54 54 assertEquals("arg1 +8", args[0]); 55 55 56 args = InteractiveWidget.parseArgs("abc\" \"de 123\" \"45");56 args = Widget.parseArgs("abc\" \"de 123\" \"45"); 57 57 assertEquals(2, args.length); 58 58 assertEquals("abc de", args[0]); 59 59 assertEquals("123 45", args[1]); 60 60 61 args = InteractiveWidget.parseArgs("adgdag\" adgdgadag");61 args = Widget.parseArgs("adgdag\" adgdgadag"); 62 62 assertEquals(1, args.length); 63 63 assertEquals("adgdag adgdgadag", args[0]); 64 64 65 args = InteractiveWidget.parseArgs("abc\"\"\" s \" ggg");65 args = Widget.parseArgs("abc\"\"\" s \" ggg"); 66 66 assertEquals(2, args.length); 67 67 assertEquals("abc\" s ", args[0]); 68 68 assertEquals("ggg", args[1]); 69 69 70 args = InteractiveWidget.parseArgs("abc\"\"123");70 args = Widget.parseArgs("abc\"\"123"); 71 71 assertEquals(1, args.length); 72 72 assertEquals("abc\"123", args[0]); 73 73 74 args = InteractiveWidget.parseArgs("file=\"a URL with spaces\" title=\"A title with spaces and \"\"quotes\"\"\"");74 args = Widget.parseArgs("file=\"a URL with spaces\" title=\"A title with spaces and \"\"quotes\"\"\""); 75 75 assertEquals(2, args.length); 76 76 assertEquals("file=a URL with spaces", args[0]); … … 101 101 private void AssertArgParsingAndFormatting(String str) { 102 102 103 String[] args1 = InteractiveWidget.parseArgs(str);103 String[] args1 = Widget.parseArgs(str); 104 104 105 String formatted = InteractiveWidget.formatArgs(args1);105 String formatted = Widget.formatArgs(args1); 106 106 107 String[] args2 = InteractiveWidget.parseArgs(formatted);107 String[] args2 = Widget.parseArgs(formatted); 108 108 109 109 if (args1 == null || args2 == null) assertEquals(args1, args2);
Note:
See TracChangeset
for help on using the changeset viewer.