juanotto commented on code in PR #23:
URL:
https://github.com/apache/netbeans-antora-tutorials/pull/23#discussion_r2479303299
##########
modules/ROOT/pages/tutorials/nbm-selection-1.adoc:
##########
@@ -315,82 +318,81 @@ You now have a skeleton `TopComponent` - a singleton
component called `MyViewerT
=== Creating a Context Sensitive TopComponent
-Click its Design tab of the open `MyViewerTopComponent` to access the
"Matisse" GUI Builder (also known as the "form editor").
-
-You will add two labels to the component, which will display some information
about the selected `Event` if there is one.
-
-
-[start=1]
-1. Drag two Labels (javax.swing.JLabel) to the form from the Palette
(kbd:[Ctrl+Shift+8]), one below the other, as shown below:
-
-image::tutorials/selection-1_viewer6.png[]
+Click the Design tab to open the "Matisse" GUI Builder (the form editor).
You'll add two labels to display information
+about the selected `Event`.
-Press F2 on the first label and then change the text as shown above, so that
by default it displays "[Nothing selected]".
-image::tutorials/selection-1_viewer7.png[]
+1. Drag two Labels (javax.swing.JLabel) from the Palette to the form, one
below the other:
++
+image::tutorials/selection-1_nb27_viewer6.png[]
++
+Select the first label and press F2, change the text to `[Nothing selected]`
as shown above.
-[start=2]
-1. Click the Source button in the editor toolbar to switch to the code editor.
Modify the signature of the class, so that `MyViewerTopComponent` implements
`LookupListener`:
-
+2. Click the Source button to switch to the code editor. Change the class
signature so `MyViewerTopComponent` implements
+`LookupListener`:
++
[source,java]
----
-public final class MyViewerTopComponent extends TopComponent implements
LookupListener {
-----
-
-Right-click in the editor and choose Fix Imports, so that `LookupListener` is
imported.
-
-Put the cursor over the lightbulb icon should appear in the editor margin. A
popup hint should appear, as shown below:
-
-image::tutorials/selection-1_viewer8.png[]
-
-Left click on the lightbulb icon in the editor margin, and when the popup
appears, select the text "Implement all abstract methods".
-
-image::tutorials/selection-1_viewer9.png[]
-
-You now have a class that implements `LookupListener` (i.e. the
`resultChanged` method). Now it needs something to listen to.
-
-There is a convenient global `Lookup` object, which proxies the Lookup of
whatever component has focus - it can be obtained from the call
`Utilities.actionsGlobalContext()`. So rather than tracking what component has
focus yourself, you can listen to this one global selection `Lookup`, which
will fire appropriate changes whenever focus changes.
-
-
-[start=3]
-1. Edit the source code of the `MyViewerTopComponent` to add a lookup result
member, and so that its `componentOpened`, `componentClosed`, and
`resultChanged` methods are as follows:
-
-
+public final class MyViewerTopComponent extends TopComponent implements
LookupListener
+----
++
+Right-click in the editor and choose Fix Imports to import `LookupListener`.
++
+A lightbulb icon will appear in the editor margin. Click it to see the popup:
++
+image::tutorials/selection-1_nb27_viewer8.png[]
++
+Select the text "Implement all abstract methods" on the context menu that
appears. Now you have a class that implements
+`LookupListener` (it implements the `resultChanged` method). You need
something to listen to.
++
+There's a global `Lookup` object that proxies the Lookup of whatever component
has focus - you can get it by calling
+`Utilities.actionsGlobalContext()`. Instead of tracking focus yourself, you
can listen to this global selection
+`Lookup`, which fires changes whenever focus changes.
+
+
+3. Edit the `MyViewerTopComponent` source to add a lookup result member and
implement the `componentOpened`,
+`componentClosed`, and `resultChanged` methods:
++
[source,java]
----
- private Lookup.Result<Event> result = null;
+private Lookup.Result<Event> result = null;
- @Override
- public void componentOpened() {
- result = Utilities.actionsGlobalContext().lookupResult(Event.class);
- result.addLookupListener (this);
- }
+@Override
+public void componentOpened() {
+ result = Utilities.actionsGlobalContext().lookupResult(Event.class);
+ result.addLookupListener (this);
+}
- @Override
- public void componentClosed() {
- result.removeLookupListener(this);
- }
+@Override
+public void componentClosed() {
+ result.removeLookupListener(this);
+}
- @Override
- public void resultChanged(LookupEvent lookupEvent) {
- Collection<? extends Event> allEvents = result.allInstances();
- if (!allEvents.isEmpty()) {
- Event event = allEvents.iterator().next();
- jLabel1.setText(Integer.toString(event.getIndex()));
- jLabel2.setText(event.getDate().toString());
- } else {
- jLabel1.setText("[Nothing selected]");
- jLabel2.setText("");
- }
+@Override
+public void resultChanged(LookupEvent lookupEvent) {
+ Collection<? extends Event> allEvents = result.allInstances();
+ if (!allEvents.isEmpty()) {
+ Event event = allEvents.iterator().next();
+ jLabel1.setText(Integer.toString(event.getIndex()));
+ jLabel2.setText(event.getDate().toString());
+ } else {
+ jLabel1.setText("[Nothing selected]");
+ jLabel2.setText("");
}
+}
----
++
+* `componentOpened()` is called whenever the component is made visible by the
window system; `componentClosed()` is
+called whenever the user clicks the X button on its tab to close it. So
whenever the component is showing, you want it
+to be tracking the selection - which is what the above code does.
+* The `resultChanged()` method is your implementation of `LookupListener`.
Whenever the selected `Event` changes, it
+will update the two `JLabel`s you put on the form.
-* `componentOpened()` is called whenever the component is made visible by the
window system; `componentClosed()` is called whenever the user clicks the X
button on its tab to close it. So whenever the component is showing, you want
it to be tracking the selection - which is what the above code does.
-* The `resultChanged()` method is your implementation of `LookupListener`.
Whenever the selected `Event` changes, it will update the two `JLabel`s you put
on the form.
-
++
The required import statements for the `MyViewerTopComponent` are as follows:
Review Comment:
I don't know how! I thought white line then + took you one level up but it
didn't work. I'll check some options, getting familiar with asciidoc slowly
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists