Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 1.

Similar presentations


Presentation on theme: "Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 1."— Presentation transcript:

1 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 1

2 Swing 2 JavaFX Steve Northover (Oracle) Anton Taraov (Oracle)

3 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 3 The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.

4 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 4 Program Agenda  New and Exciting: SwingNode and Unified Threading!  Old and not so Exciting: Where we are Today  Discussion Topics: What should we do next?

5 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 5 SwingNode  JFXPanel (JavaFX 2.0) – augments existing Swing based apps with FX features – the basis of an incremental migration strategy  SwingNode (JavaFX 8.0) – a reverse direction bridge to Swing – takes in legacy/commercial Swing components to modern FX apps

6 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 6 API  As simple as: package javafx.embed.swing; public class SwingNode extends Node { public void setContent(final JComponent content); public JComponent getContent(); }  Thread safe  JComponent : no hw components in the hierarchy, please

7 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 7 Threading Restrictions  Invoke a UI related method on the right event thread: – Swing on Event Dispatch thread:SwingUtilities.invokeLater(Runnable r); – FX on JavaFX Application thread:Platform.runLater(Runnable r);  SwingNode belongs to FX!  Exclusion: SwingNode.setContent/getContent are thread safe methods

8 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 8 Code Sample public class SwingInFx extends Application public void start(Stage stage) { final SwingNode swingNode = new SwingNode(); createSwingContent(swingNode); Group group = new Group(); group.getChildren().add(swingNode); stage.setScene(new Scene(group, 100, 50)); stage.show(); } private void createSwingContent(final SwingNode swingNode) { SwingUtilities.invokeLater(() -> swingNode.setContent(new JButton("Click me!"))); }

9 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 9 Approach  Symmetrical to JFXPanel: – lightweight embedding – events are forwarded from FX to Swing  SwingNode is a first class FX node: – transforms, effects, translucency

10 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 10 Architecture

11 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 11 Notifications  sun.swing.LightweightContent ‑ implemented in SwingNode: – paint lock/unlock – image buffer update – focus grab/ungrab – preferred size update – cursor change

12 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 12 Limitations  JViewPort: BLIT_SCROLL_MODE → BACKINGSTORE_SCROLL_MODE – Why? Bypassing paint() call, overridden by JLF's content pane – Looking for a better solution (getting somehow into RepaintManager)  Mac OS X: -Dswing.volatileImageBufferEnabled=false – Otherwise, performance drops significantly – Why? Bliting bits from VolatileImage to the shared memory

13 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 13

14 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 14 Supported/planned functionality  Platforms: Windows/Mac/Linux  Key/Mouse/Wheel events  Popups auto-hiding  Custom Cursor change  Dirty Regions  Retina→ JFX8 *  Focus traverse-out→ JFX8 *  * Not a commitment. The targeted release number may be revised.

15 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 15 Future improvements  Performance  DnD  Input methods  A11y  Modality / Z-order

16 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 16 More Information:  “Embedding Swing Content in JavaFX Applications” –  Relevant JavaOne talks (Swing and JavaFX): – Practical Pros and Cons of Replacing Swing with JavaFX in Existing Applications [CON3530] – Tuesday 11:30 – Moving from Swing to JavaFX [CON7852] – Thurs 12:30

17 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 17 Unified Threading  Threading: the single biggest problem with Swing interop – Forces asynchronous programming on the desktop  Long considered to be “impossible to solve” – AWT/Swing threading is complex – Not dispatching events is equivalent to locking – “Two locks, two threads? You can deadlock …” General Rule of Thumb: Never wait, runLater()

18 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 18 Threading: The Old Way Operating System Event Queue JavaFX Event Queue AWT Swing

19 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 19 Threads in JavaFX and AWT/Swing  JavaFX is apartment threaded – The JavaFX platform GUI thread runs application code – If application code waits, it correctly blocks the UI  AWT is “free threaded” (not really …) – The Event Dispatch Thread (EDT) runs application code  The EDT is not the platform GUI thread – The AWT platform GUI thread cross posts events to EDT  Doesn’t wait (except for the next event from the operating system)  Application code doesn’t run in the platform GUI thread

20 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 20 Threads in JavaFX and AWT/Swing  Swing is “apartment threaded” (not enforced) – The EDT runs application code (recall, it is not the GUI thread) – Waiting in the EDT correctly block the Swing UI “So both JavaFX and Swing are apartment threaded and neither one should wait while running application code. In fact, applications are often coded not to wait by using workers etc. Hmmm …”

21 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 21 The Idea: Marry the Threads “Why not make the JavaFX platform GUI thread be the EDT thread for AWT/Swing? It is required that the EDT be non-GUI for AWT/Swing, but there is nothing that says it can’t be a GUI thread for someone else”

22 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 22 Unified Threading: The New Way Operating System Event Queue JavaFX Event Queue AWT Swing

23 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 23 Unified Threading  Still under construction for JavaFX 8.0  Early experiments are looking good – Threading is complex so there may be dragons  Enabled using a property – Djavafx.embed.singleThread=true – Disabled by default Try it out and let us know how you get on!

24 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 24 Old and not so Exciting: Where we are today To fill a shape with an image. 1.Use existing picture box, DO NOT delete and create new picture box. 2.Right click on the shape. 3.At the bottom of the submenu select “Format Shape” 4.Select “Fill” at the top of the “Format Shape” dialog box. 5.Select “Picture or Texture fill” from the options. 6.And select “File” under the “Insert from” option. 7.Navigate to the file you want to use and select “Insert” 8.On the “Format” tab, in the Size group, click on “Crop to Fill” in the Crop tool and drag the image bounding box to the desired size 9.DELETE THIS INSTRUCTION NOTE WHEN NOT IN USE

25 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 25 JFXPanel: State of the Union  Code is stable and functionality is reasonable  Areas that need work: – Opacity, Exit on Close, – Performance, – Modality, DnD, – Layout, Popups auto-hiding, – Focus Traversal

26 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 26 Opacity  [P3] RT Opacity is ignored for scene contained in a JFXPanel (Since b94)  [P3] JDK JLightweightFrame: the content pane should be transparent  Note: use -Dswing.jlf.contentPaneTransparent=true to make the SwingNode’s background transparent

27 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 27 Exit on Close  [P3] RT IllegalStateException using JFXPanel in a netbeans window.  [P4] RT JFXPanels are not reusable  WORK AROUND: Platform.setImplictExit(false) and call Platform.exit()

28 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 28 Performance  [P3] RT JFXPanel with simple animation consumes entire CPU core (see PERF-326)  [P3] RT Minor tweaks to FX/Swing painting  Just need to get to these, we have lots of ideas

29 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 29 Modalilty  [P4] RT FileChooser: cannot show modal when using jfxpanel.scene.window as owner window  WORK AROUND: Wrap JFXPanel in a JDialog. No work around for FileChooser

30 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 30 DnD  [P3] RT Drag and drop window operations result in AssertionError with embedded JFXPanel components in NetBeans Platform Applications  [P2] RT Mac: Dragboard don't work correctly with JFXPane  [P3] RT Memory leak in EmbeddedScene.scenePaintListener or QuantumToolkit.dragSourceScene  [P3] RT DRAG_DONE event doesn't come

31 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 31 Layout  [P4] RT JavaFX in Swing: no autosize on Propertychanges in Controls  [P4] RT JFXPanel: race condition when setting scene  Hoping to get to these for FX8

32 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 32 Popups auto-hiding  [P4] RT PopupWindow.autoHide does not work in Swing application (includes ContextMenu etc)  Should be fixed in FX8. Work around in the JIRA

33 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 33 Focus traversal  [P4] RT Provide possibility to traverse focus out of FX scene  This one is bad but we aren’t able to get to this for FX8

34 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 34 Discussion Topics: What should we do next? To fill a shape with an image. 1.Use existing picture box, DO NOT delete and create new picture box. 2.Right click on the shape. 3.At the bottom of the submenu select “Format Shape” 4.Select “Fill” at the top of the “Format Shape” dialog box. 5.Select “Picture or Texture fill” from the options. 6.And select “File” under the “Insert from” option. 7.Navigate to the file you want to use and select “Insert” 8.On the “Format” tab, in the Size group, click on “Crop to Fill” in the Crop tool and drag the image bounding box to the desired size 9.DELETE THIS INSTRUCTION NOTE WHEN NOT IN USE

35 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 35 Discussion: What should we do next?  Areas that need work: – Retina support, – Accessibility, – Multi-touch, – More conversion methods (SwingFXUtils, Color, Font etc.) – … your input here …

36 Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 36


Download ppt "Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 1."

Similar presentations


Ads by Google