Example usage for javax.swing JInternalFrame setLayout

List of usage examples for javax.swing JInternalFrame setLayout

Introduction

In this page you can find the example usage for javax.swing JInternalFrame setLayout.

Prototype

public void setLayout(LayoutManager manager) 

Source Link

Document

Ensures that, by default, the layout of this component cannot be set.

Usage

From source file:Main.java

/**
 * Creates (and displays) a JInternalFrame for a specified component. <br />
 * The size of the JInternalFrame will be <code>frameSize</code>. <br />
 * The frame is <i>just</i> closeable. <br />
 * //from w ww .ja  v  a  2 s.  co  m
 * @param desktop the JDesktopPane
 * @param comp the component to display in the created frame
 * @param title the title of the frame
 * @param frameSize the size of the frame
 * @return the created and displayed frame
 */
public static JInternalFrame showInternalFrame(JDesktopPane desktop, JComponent comp, String title,
        Dimension frameSize) {
    JInternalFrame frm = new JInternalFrame(title);
    frm.setClosable(true);
    frm.setLayout(new BorderLayout());
    frm.add(comp, BorderLayout.CENTER);
    frm.setSize(frameSize);
    frm.setVisible(true);

    Dimension size = frm.getSize();
    frm.setLocation(desktop.getWidth() / 2 - size.width / 2, desktop.getHeight() / 2 - size.height / 2);
    desktop.add(frm, 0);

    try {
        frm.setSelected(true);
    } catch (java.beans.PropertyVetoException e) {
    }

    return frm;
}

From source file:Main.java

/**
 * Creates (and displays) a JInternalFrame for a specified component. <br />
 * The size of the JInternalFrame will be setted with calling <code>pack()</code>. <br />
 * //from  w ww.  j av  a 2s.  co  m
 * @param desktop the JDesktopPane
 * @param comp the component to display in the created frame
 * @param title the title of the frame
 * @param frameSize the size of the frame
 * @return the created and displayed frame
 */
public static JInternalFrame showInternalFrame(JDesktopPane desktop, JComponent comp, String title) {
    JInternalFrame frm = new JInternalFrame(title);
    frm.setClosable(true);
    frm.setLayout(new BorderLayout());
    frm.add(comp, BorderLayout.CENTER);

    desktop.add(frm, 0);
    frm.pack();
    frm.setVisible(true);

    Dimension size = frm.getSize();
    frm.setLocation(desktop.getWidth() / 2 - size.width / 2, desktop.getHeight() / 2 - size.height / 2);

    try {
        frm.setSelected(true);
    } catch (java.beans.PropertyVetoException e) {
    }

    return frm;
}

From source file:Main.java

/**
 * Displays a specified <code>JFileChooser</code> in a JInternalFrame. <br />
 * The JInternalFrame will close when the dialog is closed. <br />
 * //from w w w.  j  a  va  2  s .c o  m
 * @param desktop the JDesktopPane on which to display the JFileChooser
 * @param ch the JFileChooser to display
 */
public static void showInternalFileChooser(JDesktopPane desktop, final JFileChooser ch) {
    final JInternalFrame frm = new JInternalFrame(ch.getDialogTitle());
    frm.setClosable(true);
    frm.setResizable(true);
    frm.setLayout(new BorderLayout());
    frm.add(ch, BorderLayout.CENTER);
    frm.setVisible(true);

    frm.pack();

    Dimension size = frm.getSize();
    frm.setLocation(desktop.getWidth() / 2 - size.width / 2, desktop.getHeight() / 2 - size.height / 2);
    desktop.add(frm, 0);

    ch.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            frm.dispose();
            ch.removeActionListener(this);
        }
    });

    try {
        frm.setSelected(true);
    } catch (java.beans.PropertyVetoException e) {
    }
}

From source file:Main.java

/**
 * Shows a specified JInternalFrame in the middle of the specified JDesktopPane. <br />
 * The size of the JInternalFrame will be <code>frameSize</code>. <br />
 * The frame is <i>just</i> closeable. <br />
 * // w ww.  ja  v  a 2  s. c  om
 * @param desktop the JDesktopPane
 * @param frm the JInternalFrame
 * @param content the component which will be added to the JInternalFrame
 * @param frameSize the size of the JInternalFrame
 */
public static void showInternalFrame(JDesktopPane desktop, JInternalFrame frm, JComponent content,
        Dimension frameSize) {
    frm.setClosable(true);
    frm.setLayout(new BorderLayout());
    frm.add(content, BorderLayout.CENTER);
    frm.setSize(frameSize);
    frm.setVisible(true);

    Dimension size = frm.getSize();
    frm.setLocation(desktop.getWidth() / 2 - size.width / 2, desktop.getHeight() / 2 - size.height / 2);
    desktop.add(frm, 0);

    try {
        frm.setSelected(true);
    } catch (java.beans.PropertyVetoException e) {
    }
}

From source file:org.sintef.thingml.ThingMLPanel.java

public ThingMLPanel(Boolean ArduinoPlugin, final ObservableString transferBuf) {
    try {/*from  ww  w  .j a  v  a 2  s .  c o  m*/
        this.setLayout(new BorderLayout());
        jsyntaxpane.DefaultSyntaxKit.initKit();
        jsyntaxpane.DefaultSyntaxKit.registerContentType("text/thingml",
                Class.forName("org.sintef.thingml.ThingMLJSyntaxKit").getName());
        JScrollPane scrPane = new JScrollPane(codeEditor);
        codeEditor.setContentType("text/thingml; charset=UTF-8");

        Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
        reg.getExtensionToFactoryMap().put("thingml", new ThingmlResourceFactory());

        //codeEditor.setBackground(Color.LIGHT_GRAY)

        JMenuBar menubar = new JMenuBar();
        JInternalFrame menuframe = new JInternalFrame();

        menuframe.setSize(getWidth(), getHeight());
        menuframe.setJMenuBar(menubar);

        menuframe.setLayout(new BorderLayout());
        menuframe.add(scrPane, BorderLayout.CENTER);

        if (!ArduinoPlugin) {
            try {
                this.transferBuf = transferBuf;
                EditorKit editorKit = codeEditor.getEditorKit();
                JToolBar toolPane = new JToolBar();
                ((ThingMLJSyntaxKit) editorKit).addToolBarActions(codeEditor, toolPane);
                menuframe.add(toolPane, BorderLayout.NORTH);
            } catch (Exception e) {
                if (ThingMLApp.debug)
                    e.printStackTrace();
            }
        }

        menuframe.setVisible(true);
        ((BasicInternalFrameUI) menuframe.getUI()).setNorthPane(null);
        menuframe.setBorder(BorderFactory.createEmptyBorder());
        add(menuframe, BorderLayout.CENTER);

        if (!ArduinoPlugin) {//FIXME: Nicolas, avoid code duplication
            final ThingMLCompilerRegistry registry = ThingMLCompilerRegistry.getInstance();

            JMenu newCompilersMenu = new JMenu("Compile to");
            for (final String id : registry.getCompilerIds()) {
                JMenuItem item = new JMenuItem(id);
                ThingMLCompiler c = registry.createCompilerInstanceByName(id);
                if (c.getConnectorCompilers().size() > 0) {
                    JMenu compilerMenu = new JMenu(c.getID());
                    newCompilersMenu.add(compilerMenu);
                    compilerMenu.add(item);
                    for (final Map.Entry<String, CfgExternalConnectorCompiler> connectorCompiler : c
                            .getConnectorCompilers().entrySet()) {
                        JMenuItem connectorMenu = new JMenuItem(connectorCompiler.getKey());
                        compilerMenu.add(connectorMenu);
                        connectorMenu.addActionListener(new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent e) {
                                ThingMLModel thingmlModel = ThingMLCompiler.loadModel(targetFile);
                                for (Configuration cfg : ThingMLHelpers.allConfigurations(thingmlModel)) {
                                    final ThingMLCompiler compiler = registry.createCompilerInstanceByName(id);
                                    for (NetworkPlugin np : loadedPlugins) {
                                        if (np.getTargetedLanguages().contains(compiler.getID())) {
                                            compiler.addNetworkPlugin(np);
                                        }
                                    }
                                    for (SerializationPlugin sp : loadedSerPlugins) {
                                        if (sp.getTargetedLanguages().contains(compiler.getID())) {
                                            compiler.addSerializationPlugin(sp);
                                        }
                                    }
                                    compiler.setOutputDirectory(new File(System.getProperty("java.io.tmpdir")
                                            + "/ThingML_temp/" + cfg.getName()));
                                    compiler.compileConnector(connectorCompiler.getKey(), cfg);
                                }
                            }
                        });
                    }
                } else {
                    newCompilersMenu.add(item);
                }

                item.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        System.out.println("Input file : " + targetFile);
                        if (targetFile == null)
                            return;
                        try {
                            ThingMLModel thingmlModel = ThingMLCompiler.loadModel(targetFile);
                            if (thingmlModel != null) {
                                for (Configuration cfg : ThingMLHelpers.allConfigurations(thingmlModel)) {
                                    final ThingMLCompiler compiler = registry.createCompilerInstanceByName(id);
                                    for (NetworkPlugin np : loadedPlugins) {
                                        if (np.getTargetedLanguages().contains(compiler.getID())) {
                                            compiler.addNetworkPlugin(np);
                                        }
                                    }
                                    for (SerializationPlugin sp : loadedSerPlugins) {
                                        if (sp.getTargetedLanguages().contains(compiler.getID())) {
                                            compiler.addSerializationPlugin(sp);
                                        }
                                    }
                                    compiler.setOutputDirectory(new File(System.getProperty("java.io.tmpdir")
                                            + "/ThingML_temp/" + cfg.getName()));
                                    compiler.compile(cfg);
                                }
                            }
                        } catch (Exception ex) {
                            if (ThingMLApp.debug)
                                ex.printStackTrace();
                        }
                    }
                });
                c = null;
            }

            menubar.add(newCompilersMenu);
        } else {

            final ThingMLCompilerRegistry registry = ThingMLCompilerRegistry.getInstance();

            JMenu newCompilersMenu = new JMenu("Compile to");
            for (final String id : registry.getCompilerIds()) {
                if (id.compareToIgnoreCase("arduino") == 0) {
                    JMenuItem item = new JMenuItem(id);
                    ThingMLCompiler c = registry.createCompilerInstanceByName(id);
                    if (c.getConnectorCompilers().size() > 0) {
                        JMenu compilerMenu = new JMenu(c.getID());
                        newCompilersMenu.add(compilerMenu);
                        compilerMenu.add(item);
                        for (final Map.Entry<String, CfgExternalConnectorCompiler> connectorCompiler : c
                                .getConnectorCompilers().entrySet()) {
                            JMenuItem connectorMenu = new JMenuItem(connectorCompiler.getKey());
                            compilerMenu.add(connectorMenu);
                            connectorMenu.addActionListener(new ActionListener() {
                                @Override
                                public void actionPerformed(ActionEvent e) {
                                    ThingMLModel thingmlModel = ThingMLCompiler.loadModel(targetFile);
                                    for (Configuration cfg : ThingMLHelpers.allConfigurations(thingmlModel)) {
                                        final ThingMLCompiler compiler = registry
                                                .createCompilerInstanceByName(id);
                                        for (NetworkPlugin np : loadedPlugins) {
                                            if (np.getTargetedLanguages().contains(compiler.getID())) {
                                                compiler.addNetworkPlugin(np);
                                            }
                                        }
                                        for (SerializationPlugin sp : loadedSerPlugins) {
                                            if (sp.getTargetedLanguages().contains(compiler.getID())) {
                                                compiler.addSerializationPlugin(sp);
                                            }
                                        }
                                        compiler.setOutputDirectory(
                                                new File(System.getProperty("java.io.tmpdir") + "/ThingML_temp/"
                                                        + cfg.getName()));
                                        compiler.compileConnector(connectorCompiler.getKey(), cfg);
                                    }
                                }
                            });
                        }
                    } else {
                        newCompilersMenu.add(item);
                    }

                    item.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            System.out.println("Input file : " + targetFile);
                            if (targetFile == null)
                                return;
                            try {
                                ThingMLModel thingmlModel = ThingMLCompiler.loadModel(targetFile);
                                for (Configuration cfg : ThingMLHelpers.allConfigurations(thingmlModel)) {
                                    final ThingMLCompiler compiler = registry.createCompilerInstanceByName(id);
                                    for (NetworkPlugin np : loadedPlugins) {
                                        if (np.getTargetedLanguages().contains(compiler.getID())) {
                                            compiler.addNetworkPlugin(np);
                                        }
                                    }
                                    for (SerializationPlugin sp : loadedSerPlugins) {
                                        if (sp.getTargetedLanguages().contains(compiler.getID())) {
                                            compiler.addSerializationPlugin(sp);
                                        }
                                    }

                                    File myFileBuf = new File(System.getProperty("java.io.tmpdir")
                                            + "/ThingML_temp/" + cfg.getName());
                                    compiler.setOutputDirectory(myFileBuf);
                                    compiler.compile(cfg);

                                    final InputStream input = new FileInputStream(myFileBuf.getAbsolutePath()
                                            + "/" + cfg.getName() + "/" + cfg.getName() + ".pde");

                                    //System.out.println("tmp file: " + myFileBuf.getAbsolutePath() + "/" + cfg.getName() + "/" + cfg.getName() + ".pde");

                                    //final InputStream input = new FileInputStream(myFileBuf);
                                    String result = null;
                                    try {
                                        if (input != null) {
                                            result = org.apache.commons.io.IOUtils.toString(input);
                                            input.close();
                                            transferBuf.setString(result);
                                            transferBuf.hasChanged();
                                            transferBuf.notifyObservers();
                                        } else {
                                            //System.out.println("WHY");
                                        }
                                    } catch (Exception exce) {
                                        if (ThingMLApp.debug)
                                            System.out.println("OH REALLY?");
                                    }

                                }
                            } catch (Exception ex) {
                                if (ThingMLApp.debug)
                                    ex.printStackTrace();
                            }
                        }
                    });
                    c = null;
                }
            }

            menubar.add(newCompilersMenu);
        }

        codeEditor.getDocument().addDocumentListener(new DocumentListener() {
            public void removeUpdate(DocumentEvent e) {
                lastUpdate.set(System.currentTimeMillis());
                checkNeeded.set(true);
            }

            public void insertUpdate(DocumentEvent e) {
                lastUpdate.set(System.currentTimeMillis());
                checkNeeded.set(true);
            }

            public void changedUpdate(DocumentEvent e) {
                lastUpdate.set(System.currentTimeMillis());
                checkNeeded.set(true);
            }
        });

        java.util.Timer timer = new Timer();
        timer.scheduleAtFixedRate(new SeamlessNotification(), 250, 250);

    } catch (Exception e) {
        if (ThingMLApp.debug)
            e.printStackTrace();
    }
}