Changeset 1102 for trunk/src/org/apollo/gui/ExpandedTrackManager.java
- Timestamp:
- 05/10/18 16:04:51 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.