Commits

Sven Reimers committed 7d6e16b

Initial add of FXML Library Top Component

Comments (0)

Files changed (2)

integration/src/org/netbeans/scenebuilder/embedded/FXMLLibraryTopComponent.form

+<?xml version="1.0" encoding="UTF-8" ?>
+
+<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
+  <AuxValues>
+    <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
+    <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
+    <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
+    <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
+    <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
+    <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
+    <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
+    <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
+    <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
+  </AuxValues>
+
+  <Layout>
+    <DimensionLayout dim="0">
+      <Group type="103" groupAlignment="0" attributes="0">
+          <EmptySpace min="0" pref="400" max="32767" attributes="0"/>
+      </Group>
+    </DimensionLayout>
+    <DimensionLayout dim="1">
+      <Group type="103" groupAlignment="0" attributes="0">
+          <EmptySpace min="0" pref="300" max="32767" attributes="0"/>
+      </Group>
+    </DimensionLayout>
+  </Layout>
+</Form>

integration/src/org/netbeans/scenebuilder/embedded/FXMLLibraryTopComponent.java

+/*
+ * The MIT License
+ *
+ * Copyright 2014 Sven Reimers
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package org.netbeans.scenebuilder.embedded;
+
+import com.oracle.javafx.scenebuilder.kit.editor.EditorController;
+import com.oracle.javafx.scenebuilder.kit.editor.panel.library.LibraryPanelController;
+import java.awt.BorderLayout;
+import java.util.Optional;
+import javafx.application.Platform;
+import javafx.embed.swing.JFXPanel;
+import javafx.scene.Scene;
+import javafx.scene.control.Label;
+import javafx.scene.layout.BorderPane;
+import org.netbeans.api.settings.ConvertAsProperties;
+import org.openide.awt.ActionID;
+import org.openide.awt.ActionReference;
+import org.openide.nodes.Node;
+import org.openide.util.Lookup;
+import org.openide.util.LookupEvent;
+import org.openide.util.LookupListener;
+import org.openide.windows.TopComponent;
+import org.openide.util.NbBundle.Messages;
+import org.openide.util.Utilities;
+
+/**
+ * Top component which displays something.
+ */
+@ConvertAsProperties(
+        dtd = "-//org.netbeans.scenebuilder.embedded//FXMLLibrary//EN",
+        autostore = false
+)
+@TopComponent.Description(
+        preferredID = "FXMLLibraryTopComponent",
+        //iconBase="SET/PATH/TO/ICON/HERE", 
+        persistenceType = TopComponent.PERSISTENCE_ALWAYS
+)
+@TopComponent.Registration(mode = "explorer", openAtStartup = false)
+@ActionID(category = "Window", id = "org.netbeans.scenebuilder.embedded.FXMLLibraryTopComponent")
+@ActionReference(path = "Menu/Window/SceneBuilder", position = 300)
+@TopComponent.OpenActionRegistration(
+        displayName = "#CTL_FXMLLibraryAction",
+        preferredID = "FXMLLibraryTopComponent"
+)
+@Messages({
+    "CTL_FXMLLibraryAction=FXMLLibrary",
+    "CTL_FXMLLibraryTopComponent=FXMLLibrary Window",
+    "HINT_FXMLLibraryTopComponent=This is a FXMLLibrary window"
+})
+public final class FXMLLibraryTopComponent extends TopComponent implements LookupListener {
+
+    private final JFXPanel jfxPanel = new JFXPanel();
+    private Lookup.Result<Node> nodeResult;
+    private Lookup.Result<EditorController> editorControllerResult;
+    
+    
+    public FXMLLibraryTopComponent() {
+        initComponents();
+        setName(Bundle.CTL_FXMLLibraryTopComponent());
+        setToolTipText(Bundle.HINT_FXMLLibraryTopComponent());
+        setLayout(new BorderLayout());
+        this.add(jfxPanel, BorderLayout.CENTER);        
+    }
+
+    /**
+     * This method is called from within the constructor to initialize the form.
+     * WARNING: Do NOT modify this code. The content of this method is always
+     * regenerated by the Form Editor.
+     */
+    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
+    private void initComponents() {
+
+        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
+        this.setLayout(layout);
+        layout.setHorizontalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGap(0, 400, Short.MAX_VALUE)
+        );
+        layout.setVerticalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGap(0, 300, Short.MAX_VALUE)
+        );
+    }// </editor-fold>//GEN-END:initComponents
+
+    // Variables declaration - do not modify//GEN-BEGIN:variables
+    // End of variables declaration//GEN-END:variables
+    @Override
+    public void componentOpened() {
+        nodeResult = Utilities.actionsGlobalContext().lookupResult(Node.class);
+        LookupListener nodeLkpL = (event) -> {
+            final Optional<? extends Node> optionalNode = nodeResult.allInstances().stream().findFirst();
+            if (optionalNode.isPresent()) {
+                editorControllerResult = optionalNode.get().getLookup().lookupResult(EditorController.class);
+                resultChanged(new LookupEvent(editorControllerResult));
+            }
+        };
+        nodeResult.addLookupListener(nodeLkpL);
+        nodeLkpL.resultChanged(new LookupEvent(nodeResult));
+    }
+
+    void writeProperties(java.util.Properties p) {
+        // better to version settings since initial version as advocated at
+        // http://wiki.apidesign.org/wiki/PropertyFiles
+        p.setProperty("version", "1.0");
+        // TODO store your settings
+    }
+
+    void readProperties(java.util.Properties p) {
+        String version = p.getProperty("version");
+        // TODO read your settings according to their version
+    }
+
+    @Override
+    public void resultChanged(LookupEvent le) {    
+        final Optional<? extends EditorController> optionalController = editorControllerResult.allInstances().stream().findFirst();
+        if (optionalController.isPresent()) {
+            Platform.runLater(() -> {
+                LibraryPanelController h = new LibraryPanelController(optionalController.get());
+                final BorderPane pane = new BorderPane();
+                pane.setCenter(h.getPanelRoot());
+                Scene scene = new Scene(pane);
+                jfxPanel.setScene(scene);
+            });
+        } else {
+            Platform.runLater(() -> {
+                Label label = new Label ("No Scene Builder Content");
+                BorderPane borderPane = new BorderPane();
+                borderPane.setCenter(label);
+                Scene scene = new Scene(borderPane);
+                jfxPanel.setScene(scene);
+            });
+        }
+    }
+}