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

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming
Advertisements

Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 of the corporate.
INTRODUCTION TO JAVAFX CS12420 – Software Development Andrei Stanica (modified ltt)
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | Your customer as a segment of one That changes every second! Hein Van Der Merwe Chief.
Computer Basics Hit List of Items to Talk About ● What and when to use left, right, middle, double and triple click? What and when to use left, right,
Exploring JavaFX 3D Jim Weaver Java Technology Ambassador
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | Oracle SQL Developer Tips & Tricks Jeff Smith
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Track the changes in your Apex application between releases: Yes you can Plsql.
1 Chapter 7 Graphics and Event Handling. 2 Overview The java.awt and javax.swing packages and their subpackages support graphics and event handling. Many.
6 Copyright © 2004, Oracle. All rights reserved. Working with Data Blocks and Frames.
Integrating Swing with JavaFX
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | Oracle SQL Developer What’s New in Version 4.1 Jeff Smith
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. |
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
First Programming Steps in Oracle ADF: Beyond Drag and Drop Grant Ronald Director of Product Management Mobility and Development Tools October, 2014 Copyright.
The Safe Harbor The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated.
Power Point Presentation - Advanced Julia J. Stahl Distributed System Specialist.
Chapter 2 Enhancing a Presentation with Pictures, Shapes, and WordArt
1Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8 Reporting from Contract.
Oracle E-Business Suite Order Management: Presenting the HTML and Mobile User Experience Durgaprasad Bodapati Director, Product Management Bhavana Sharma.
PowerPoint 1 The Basics 1. Save this file to your Apps Folder as YourLastName_PP1 2. Read each slide. 3. Complete each set of numbered directions.
IE 411/511: Visual Programming for Industrial Applications
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | Improving Agility in Product Development and Pricing to Gain a Competitive Edge.
1Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8 Contract Management.
3461A Readings from the Swing Tutorial. 3461A Overview  The follow is the Table of Contents from the trail “Creating a GUI with JFC/Swing” in the “The.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. JD Edwards Summit Really Cool Demo Stuff – 2015 Edition!!!!! For demo content, please.
Session 27 Swing vs. AWT. AWT (Abstract Window ToolKit) It is a portable GUI library for stand-alone applications and/or applets. The Abstract Window.
SWING IF YOU GET LOST - IMPORTANT LINKS  Swing articles:
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
1 What to do before class starts??? Download the sample database from the k: drive to the u: drive or to your flash drive. The database is named “FormBelmont.accdb”
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
Chapter 2 – Introduction to the Visual Studio .NET IDE
Model View Controller A Pattern that Many People Think They Understand, But Has A Couple Meanings.
Click your mouse to continue. The Office Shortcut Bar The Office Shortcut Bar contains program buttons that, when clicked, start new documents or start.
Keeping your Swing Applications Responsive using FoxTrot and Friends Rob Ratcliff.
COMPUTER APPLICATIONS COURSE LEARN HOW TO USE COMPUTERS.
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 1.
WebCenter in Education & Research A Transformation in Digital Business Session: CON7709 Golden Gate C3 Room, Marriott Marquis Moderator: Kevin Roebuck,
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to the Visual Studio.NET IDE Outline 2.1Introduction 2.2Visual Studio.NET Integrated.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 14 JavaFX Basics.
By: Ms. Fatima Shannag Ms. Essra Al-Mousa 1. PowerPoint web app 2 PowerPoint Web App is a limited version of PowerPoint, enabling you to display information.
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 1.
Java Threads 1 1 Threading and Concurrent Programming in Java Threads and Swing D.W. Denbo.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
POWERPOINT : GETTING STARTED WITH POWERPOINT 1.Ribbon: customize ribbon – right click on ribbon and customize ribbon opens 2.Quick access toolbar.
Lecture 7:Introduction to JavaFX Michael Hsu CSULA.
SIMPLE TEMPLATE ---- developed for kids ---- SIMPLE TEMPLATE ---- developed for kids ---- James Sager, Morgan Sager September 2016 James Sager, Morgan.
Slide 1. What's New in NetBeans IDE 7.1 Name Title.
Threads and Swing Multithreading. Contents I. Simulation on Inserting and Removing Items in a Combo Box II. Event Dispatch Thread III. Rules for Running.
Chapter 2 – Introduction to the Visual Studio .NET IDE
Java FX.
Lecture 28 Concurrent, Responsive GUIs
By: Ms. Fatima Shannag Ms. Essra Al-Mousa
Introduction to the Visual C# 2005 Express Edition IDE
Chapter 19 Java Never Ends
Shelly Cashman: Microsoft PowerPoint 2016
Microsoft Office PowerPoint 2010 INSERTING GRAPHIC OBJECTS
My Oracle Support (The next generation Metalink experience) lynn
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
#.
OpenWorld 2018 How to Combine Data from Source Sites
Charles Phillips screen
Confidential – Oracle Internal/Restricted/Highly Restricted
Chapter 2 – Introduction to the Visual Studio .NET IDE
1/10/2019 JavaFX Events COSC 330.
1.
9. Threads SE2811 Software Component Design
Oracle Java SE Subscriptions; Protect Your Investment in Java SE
Presentation transcript:

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

The following is intended to outline our general product direction 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.

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?

SwingNode JFXPanel (JavaFX 2.0) SwingNode (JavaFX 8.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

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

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

Code Sample public class SwingInFx extends Application { @Override 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!")));

Approach Symmetrical to JFXPanel: SwingNode is a first class FX node: lightweight embedding events are forwarded from FX to Swing SwingNode is a first class FX node: transforms, effects, translucency

Architecture

Notifications sun.swing.LightweightContent ‑ implemented in SwingNode: paint lock/unlock image buffer update focus grab/ungrab preferred size update cursor change

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

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.

Future improvements Performance DnD Input methods A11y Modality / Z-order

More Information: “Embedding Swing Content in JavaFX Applications” http://docs.oracle.com/javafx/8/embed_swing/jfxpub-embed_swing.htm 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 There is a new tutorial that describes SwingNode on the Oracle doc site. Also, here are a couple of talks that deal with Swing and JavaFX interop.

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 …” Probably the worst problem that FX and AWT/Swing interop has because it forces asynchronous programming. - it’s a hard problem because threads are hard - FX and AWT/Swing must talk to each other via runLater() and invokeLater() - note that there is no invokeAndWait() in FX not because one can’t be written, we just don’t want anyone waiting - if you wait, you can deadlock General Rule of Thumb: Never wait, runLater()

Threading: The Old Way JavaFX Operating System AWT Swing Event Queue This is a simple diagram of how threading works today. - each toolkit (FX and AWT/Swing) has their own event queue - each toolkit dispatches events to widgets from their own event thread - to talk to each other, the toolkits cross post messages in each other’s queues NOTE: This picture is a bit of a lie on the Mac where there is only a single operating system message queue per process but the principles are the same. The toolkits must cross post.

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 JavaFX is aparment threaded and application code runs in the platform GUI thread. AWT is “free threaded” (not really, it’s kind of apartment threaded too but it’s not enforced) - application code runs the EDT which is not the platform GUI thread - AWT cross posts message from platform GUI thread

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 …” Swing is apartment threaded but this is not enforced. - if you are not running the EDT thread, you need to use invokeLater() or invokeAndWait() - so both toolkits are apartment threaded (in different apartments) - both toolkits should not wait in their apartment thread

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” This is the big idea. Why can’t the AWT/Swing EDT thread be the FX GUI thread?

Unified Threading: The New Way Operating System JavaFX Event Queue Event Queue AWT Swing This is the new diagram. - rather than cross posting to each others thread - AWT/Swing posts events to the FX GUI thread and FX dispatches both FX events and AWT/Swing events - the EDT and the FX GUI thread are the same thread so the two toolkits can talk directly

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 Unified threading is very new and threading is complicated, especially between platforms. - it is available in the JDK8 time frame but is not the default - please try it out Try it out and let us know how you get on!

Old and not so Exciting: Where we are today To fill a shape with an image. Use existing picture box, DO NOT delete and create new picture box. Right click on the shape. At the bottom of the submenu select “Format Shape” Select “Fill” at the top of the “Format Shape” dialog box. Select “Picture or Texture fill” from the options. And select “File” under the “Insert from” option. Navigate to the file you want to use and select “Insert” 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 DELETE THIS INSTRUCTION NOTE WHEN NOT IN USE Old and not so Exciting: Where we are today

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 JFXPanel has been around since FX 2.0 and the code is stable, however there are always areas that need work.

Opacity [P3] RT-31361 Opacity is ignored for scene contained in a JFXPanel (Since b94) [P3] JDK-8022512 JLightweightFrame: the content pane should be transparent Note: use -Dswing.jlf.contentPaneTransparent=true to make the SwingNode’s background transparent An undocumented property is currently provided which makes JLF fully transparent: -Dswing.jlf.contentPaneTransparent=true The main problem with opacity is mouse events processing on transparent spots. What can we do with it? 1. Make a property which allows for fully transparent background, like for SwingNode. MouseEvents will be captured, though. 2. Don't support transparency. 3. Implement mouse events filtering. See the dedicated mail thread: http://mail.openjdk.java.net/pipermail/awt-dev/2013-September/005392.html

Exit on Close [P3] RT-29926 IllegalStateException using JFXPanel in a netbeans window. [P4] RT-30536 JFXPanels are not reusable WORK AROUND: Platform.setImplictExit(false) and call Platform.exit() When the last window is closed, FX terminates. Can't restart FX thread: https://javafx-jira.kenai.com/browse/RT-23752. No plans for JFX8. A workaround is to use: Platform.setImplicitExit(false) and the explicitly call Platform.exit().

Performance [P3] RT-24278 JFXPanel with simple animation consumes entire CPU core (see PERF-326) [P3] RT-22567 Minor tweaks to FX/Swing painting Just need to get to these, we have lots of ideas <<1. BufferedImage tweaks (format, "manageable" status, etc.)      2. Avoid extra pixels copy from EmbeddedScene to JFXPanel      3. Doesn't call to EmbeddedScene from paintComponent(), if FX scene has not changed      4. Respect JFXPanel dirty regions, so we don't repaint the whole scene every time>> No any progress here so far.

Modalilty [P4] RT-26080 FileChooser: cannot show modal when using jfxpanel.scene.window as owner window WORK AROUND: Wrap JFXPanel in a JDialog. No work around for FileChooser This is a hot topic. I saw people complaining on it on the alias. There're two separate, but related problems actually. Modality itself and z-order. For a custom FX dialog there's a known workaround which is to wrap its content into JFXPanel wrapped into JDialog set as an owned dialog of the original Swing toplevel. However, for built-in dialogs like FileChooser this doesn't fit. Petr has been experimenting with z-order. He has a more or less working solution for Mac, and is working on Windows part. Probably we can demonstrate it on the BOF with an "experimental functionality" sticker. Concerning modality, there's no progress so far.

DnD [P3] RT-24337 Drag and drop window operations result in AssertionError with embedded JFXPanel components in NetBeans Platform Applications [P2] RT-24273 Mac: Dragboard don't work correctly with JFXPane [P3] RT-27014 Memory leak in EmbeddedScene.scenePaintListener or QuantumToolkit.dragSourceScene [P3] RT-24890 DRAG_DONE event doesn't come Just a number of critical issues

Layout [P4] RT-13858 JavaFX in Swing: no autosize on Propertychanges in Controls [P4] RT-27053 JFXPanel: race condition when setting scene Hoping to get to these for FX8 Should be fixed in JFX8.

Popups auto-hiding [P4] RT-19953 PopupWindow.autoHide does not work in Swing application (includes ContextMenu etc) Should be fixed in FX8. Work around in the JIRA (This works in SwingNode, btw). Should be fixed in JFX8. Currently, there's a workaround (https://javafx-jira.kenai.com/browse/RT-19953?focusedCommentId=315222&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-315222)

Focus traversal [P4] RT-10919 Provide possibility to traverse focus out of FX scene This one is bad but we aren’t able to get to this for FX8 No traverse-out support yet. Requires new functionality on FX side. (I doubt it's resolved in JFX8).

Discussion Topics: What should we do next? To fill a shape with an image. Use existing picture box, DO NOT delete and create new picture box. Right click on the shape. At the bottom of the submenu select “Format Shape” Select “Fill” at the top of the “Format Shape” dialog box. Select “Picture or Texture fill” from the options. And select “File” under the “Insert from” option. Navigate to the file you want to use and select “Insert” 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 DELETE THIS INSTRUCTION NOTE WHEN NOT IN USE Discussion Topics: What should we do next?

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 … Multi-touch won't be supported. Need to document it.