List of usage examples for javax.swing JInternalFrame add
public Component add(String name, Component comp)
From source file:InternalFrameTest.java
/** * Creates an internal frame on the desktop. * @param c the component to display in the internal frame * @param t the title of the internal frame. *//*from ww w . j ava 2s . com*/ public void createInternalFrame(Component c, String t) { final JInternalFrame iframe = new JInternalFrame(t, true, // resizable true, // closable true, // maximizable true); // iconifiable iframe.add(c, BorderLayout.CENTER); desktop.add(iframe); iframe.setFrameIcon(new ImageIcon("document.gif")); // add listener to confirm frame closing iframe.addVetoableChangeListener(new VetoableChangeListener() { public void vetoableChange(PropertyChangeEvent event) throws PropertyVetoException { String name = event.getPropertyName(); Object value = event.getNewValue(); // we only want to check attempts to close a frame if (name.equals("closed") && value.equals(true)) { // ask user if it is ok to close int result = JOptionPane.showInternalConfirmDialog(iframe, "OK to close?", "Select an Option", JOptionPane.YES_NO_OPTION); // if the user doesn't agree, veto the close if (result != JOptionPane.YES_OPTION) throw new PropertyVetoException("User canceled close", event); } } }); // position frame int width = desktop.getWidth() / 2; int height = desktop.getHeight() / 2; iframe.reshape(nextFrameX, nextFrameY, width, height); iframe.show(); // select the frame--might be vetoed try { iframe.setSelected(true); } catch (PropertyVetoException e) { } frameDistance = iframe.getHeight() - iframe.getContentPane().getHeight(); // compute placement for next frame nextFrameX += frameDistance; nextFrameY += frameDistance; if (nextFrameX + width > desktop.getWidth()) nextFrameX = 0; if (nextFrameY + height > desktop.getHeight()) nextFrameY = 0; }
From source file:guineu.modules.dataanalysis.PCA.PCADataset.java
public void run() { setStatus(TaskStatus.PROCESSING);/*from w w w . java 2 s . co m*/ logger.info("Computing projection plot"); double[][] rawData = new double[selectedSamples.length][selectedRows.length]; for (int rowIndex = 0; rowIndex < selectedRows.length; rowIndex++) { PeakListRow peakListRow = selectedRows[rowIndex]; for (int fileIndex = 0; fileIndex < selectedSamples.length; fileIndex++) { String rawDataFile = selectedSamples[fileIndex]; Object p = peakListRow.getPeak(rawDataFile); try { rawData[fileIndex][rowIndex] = (Double) p; } catch (Exception e) { // e.printStackTrace(); } } } this.progress = 0.25f; int numComponents = xAxisPC; if (yAxisPC > numComponents) { numComponents = yAxisPC; } PCA pca = new PCA(selectedSamples.length, selectedRows.length); Matrix X = new Matrix(rawData, selectedSamples.length, selectedRows.length); String[] rowNames = new String[selectedRows.length]; for (int j = 0; j < selectedRows.length; j++) { rowNames[j] = selectedRows[j].getName(); } X = pca.center(X); X = pca.scale(X); pca.nipals(X, this.selectedSamples, rowNames, this.components); mainComponents = pca.getPCs(); Collections.sort(mainComponents); if (status == TaskStatus.CANCELED) { return; } this.progress = 0.75f; for (PrincipleComponent comp : mainComponents) { this.totalVariation += comp.eigenValue; } if (mainComponents.size() > yAxisPC - 1) { component1Coords = mainComponents.get(xAxisPC - 1).eigenVector; component2Coords = mainComponents.get(yAxisPC - 1).eigenVector; Desktop desktop = GuineuCore.getDesktop(); ProjectionPlotWindow newFrame = new ProjectionPlotWindow(this.datasetTitle, this, parameters); desktop.addInternalFrame(newFrame); if (this.showLoadings) { ChartPanel loadings = pca.loadingsplot(this.getXLabel(), this.getYLabel()); JInternalFrame frame = new JInternalFrame(); frame.setTitle("Principal Components Analysis: Loadings"); frame.setResizable(true); frame.setClosable(true); frame.setMaximizable(true); frame.add(loadings, BorderLayout.CENTER); frame.setPreferredSize(new Dimension(700, 500)); frame.pack(); desktop.addInternalFrame(frame); } } this.progress = 1.0f; setStatus(TaskStatus.FINISHED); logger.info("Finished computing projection plot."); }
From source file:CSSDFarm.UserInterface.java
/** * Configure JxBrowser to be displayed. Load map.html from file to string data, load * this data into JxBrowser and add the browser to the panel. */// ww w. j a v a 2 s . c o m public void displayHeatmap() { LoggerProvider.getChromiumProcessLogger().setLevel(Level.OFF); LoggerProvider.getIPCLogger().setLevel(Level.OFF); LoggerProvider.getBrowserLogger().setLevel(Level.OFF); BrowserView view = new BrowserView(browser); JPanel toolBar = new JPanel(); Dimension dimension = panelHeatmap.getSize(); JInternalFrame internalFrame = new JInternalFrame(); internalFrame.add(view, BorderLayout.CENTER); internalFrame.add(toolBar, BorderLayout.NORTH); internalFrame.setSize(dimension); internalFrame.setLocation(0, 0); internalFrame.setBorder(null); internalFrame.setVisible(true); ((javax.swing.plaf.basic.BasicInternalFrameUI) internalFrame.getUI()).setNorthPane(null); URL url = getClass().getResource("map.html"); File html = new File(url.getPath()); String htmlString = null; try { htmlString = FileUtils.readFileToString(html); } catch (IOException ex) { Logger.getLogger(UserInterface.class.getName()).log(Level.SEVERE, null, ex); } browser.loadHTML(htmlString); panelHeatmap.add(internalFrame); }
From source file:org.renjin.desktop.MainFrame.java
public MainFrame() { super("Renjin"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JDesktopPane desktop = new JDesktopPane(); desktop.setBackground(new Color(171, 171, 171)); JInternalFrame internalFrame = new JInternalFrame("R Console", true, true, true, true); console = new JConsole(); internalFrame.add(console, BorderLayout.CENTER); internalFrame.setBounds(25, 25, 600, 300); internalFrame.setVisible(true);/* ww w .ja va2 s . c o m*/ desktop.add(internalFrame); add(desktop, BorderLayout.CENTER); setSize(650, 450); setVisible(true); }
From source file:org.sintef.thingml.ThingMLPanel.java
public ThingMLPanel(Boolean ArduinoPlugin, final ObservableString transferBuf) { try {/*from w w w. j av a2s. 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(); } }