Search in sources :

Example 6 with DialogFileFilter

use of org.gephi.ui.utils.DialogFileFilter in project gephi by gephi.

the class DataTableTopComponent method exportTableAsCSV.

/**
     * <p>Exports a AttributeTable to a CSV file showing first a dialog to select the
     * file to write.</p>
     *
     * @param parent Parent window
     * @param visibleOnly Show only visible graph
     * @param table Table to export
     * @param separator Separator to use for separating values of a row in the
     * CSV file. If null ',' will be used.
     * @param charset Charset encoding for the file
     * @param columnsToExport Indicates the indexes of the columns to export.
     * All columns will be exported if null
     */
public static void exportTableAsCSV(JComponent parent, boolean visibleOnly, Table table, boolean edgesTable, Character separator, Charset charset, Integer[] columnsToExport, String fileName) {
    //Validate that at least 1 column is selected:
    if (columnsToExport.length < 1) {
        return;
    }
    String lastPath = NbPreferences.forModule(JTableCSVExporter.class).get(LAST_PATH, null);
    final JFileChooser chooser = new JFileChooser(lastPath);
    chooser.setAcceptAllFileFilterUsed(false);
    DialogFileFilter dialogFileFilter = new DialogFileFilter(NbBundle.getMessage(DataTableTopComponent.class, "TableCSVExporter.filechooser.csvDescription"));
    dialogFileFilter.addExtension("csv");
    chooser.addChoosableFileFilter(dialogFileFilter);
    File selectedFile = new File(chooser.getCurrentDirectory(), fileName);
    chooser.setSelectedFile(selectedFile);
    int returnFile = chooser.showSaveDialog(null);
    if (returnFile != JFileChooser.APPROVE_OPTION) {
        return;
    }
    File file = chooser.getSelectedFile();
    if (!file.getPath().endsWith(".csv")) {
        file = new File(file.getPath() + ".csv");
    }
    //Save last path
    String defaultDirectory = file.getParentFile().getAbsolutePath();
    NbPreferences.forModule(JTableCSVExporter.class).put(LAST_PATH, defaultDirectory);
    try {
        Element[] rows;
        Graph graph;
        if (visibleOnly) {
            graph = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getGraphVisible();
        } else {
            graph = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getGraph();
        }
        if (edgesTable) {
            rows = graph.getEdges().toArray();
        } else {
            rows = graph.getNodes().toArray();
        }
        AttributeTableCSVExporter.writeCSVFile(graph, table, file, separator, charset, columnsToExport, rows);
        JOptionPane.showMessageDialog(parent, NbBundle.getMessage(DataTableTopComponent.class, "TableCSVExporter.dialog.success"));
    } catch (Exception ex) {
        Logger.getLogger("").log(Level.SEVERE, null, ex);
        JOptionPane.showMessageDialog(parent, NbBundle.getMessage(DataTableTopComponent.class, "TableCSVExporter.dialog.error"), NbBundle.getMessage(DataTableTopComponent.class, "TableCSVExporter.dialog.error.title"), JOptionPane.ERROR_MESSAGE);
    }
}
Also used : JTableCSVExporter(org.gephi.utils.JTableCSVExporter) Graph(org.gephi.graph.api.Graph) JFileChooser(javax.swing.JFileChooser) Element(org.gephi.graph.api.Element) DialogFileFilter(org.gephi.ui.utils.DialogFileFilter) File(java.io.File) GraphController(org.gephi.graph.api.GraphController)

Example 7 with DialogFileFilter

use of org.gephi.ui.utils.DialogFileFilter in project gephi by gephi.

the class GraphFileExporterUI method getExporter.

private GraphFileExporterBuilder getExporter(DialogFileFilter fileFilter) {
    //Find fileFilter
    for (GraphFileExporterBuilder graphFileExporter : Lookup.getDefault().lookupAll(GraphFileExporterBuilder.class)) {
        for (FileType fileType : graphFileExporter.getFileTypes()) {
            DialogFileFilter tempFilter = new DialogFileFilter(fileType.getName());
            tempFilter.addExtensions(fileType.getExtensions());
            if (tempFilter.equals(fileFilter)) {
                return graphFileExporter;
            }
        }
    }
    return null;
}
Also used : GraphFileExporterBuilder(org.gephi.io.exporter.spi.GraphFileExporterBuilder) FileType(org.gephi.io.exporter.api.FileType) DialogFileFilter(org.gephi.ui.utils.DialogFileFilter)

Example 8 with DialogFileFilter

use of org.gephi.ui.utils.DialogFileFilter in project gephi by gephi.

the class ImportCSVUIVisualPanel1 method fileButtonActionPerformed.

// </editor-fold>//GEN-END:initComponents
private void fileButtonActionPerformed(java.awt.event.ActionEvent evt) {
    //GEN-FIRST:event_fileButtonActionPerformed
    String lastPath = NbPreferences.forModule(ImportCSVUIVisualPanel1.class).get(LAST_PATH, null);
    final JFileChooser chooser = new JFileChooser(lastPath);
    chooser.setAcceptAllFileFilterUsed(true);
    DialogFileFilter dialogFileFilter = new DialogFileFilter(NbBundle.getMessage(ImportCSVUIVisualPanel1.class, "ImportCSVUIVisualPanel1.filechooser.csvDescription"));
    dialogFileFilter.addExtension("csv");
    chooser.addChoosableFileFilter(dialogFileFilter);
    chooser.setSelectedFile(selectedFile);
    int returnFile = chooser.showOpenDialog(null);
    if (returnFile != JFileChooser.APPROVE_OPTION) {
        return;
    }
    selectedFile = chooser.getSelectedFile();
    String path = selectedFile.getAbsolutePath();
    pathTextField.setText(path);
    //Save last path
    String defaultDirectory = selectedFile.getParentFile().getAbsolutePath();
    NbPreferences.forModule(ImportCSVUIVisualPanel1.class).put(LAST_PATH, defaultDirectory);
    refreshPreviewTable();
}
Also used : JFileChooser(javax.swing.JFileChooser) DialogFileFilter(org.gephi.ui.utils.DialogFileFilter)

Example 9 with DialogFileFilter

use of org.gephi.ui.utils.DialogFileFilter in project gephi by gephi.

the class ScreenshotMaker method run.

@Override
public void run() {
    beforeTaking();
    try {
        // Stop display
        engine.stopDisplay();
        // Start progress
        Progress.start(progressTicket);
        Thread.sleep(100);
        final OffscreenCanvas drawable = new OffscreenCanvas(tileWidth, tileHeight, transparentBackground, antiAliasing);
        GLAutoDrawable autoDrawable = drawable.getGLAutoDrawable();
        //Tile rendering
        final TileRenderer renderer = new TileRenderer();
        renderer.setImageSize(width, height);
        renderer.setTileSize(tileWidth, tileHeight, 0);
        renderer.attachAutoDrawable(autoDrawable);
        final GLPixelBuffer.GLPixelBufferProvider pixelBufferProvider = GLPixelBuffer.defaultProviderWithRowStride;
        final boolean[] flipVertically = { false };
        final GLEventListener preTileGLEL = new GLEventListener() {

            @Override
            public void init(final GLAutoDrawable drawable) {
                final GL2 gl = drawable.getGL().getGL2();
                final GLPixelAttributes pixelAttribs = pixelBufferProvider.getAttributes(gl, transparentBackground ? 4 : 3, true);
                final GLPixelBuffer imageBuffer = pixelBufferProvider.allocate(gl, null, pixelAttribs, true, width, height, 1, 0);
                renderer.setImageBuffer(imageBuffer);
                flipVertically[0] = !drawable.isGLOriented();
            }

            @Override
            public void dispose(final GLAutoDrawable drawable) {
            }

            @Override
            public void display(final GLAutoDrawable drawable) {
            }

            @Override
            public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
            }
        };
        renderer.setGLEventListener(preTileGLEL, null);
        vizConfig.setDisableLOD(true);
        engine.updateLOD();
        // Render tiles
        int tiles = renderer.getParam(TileRenderer.TR_COLUMNS) * renderer.getParam(TileRenderer.TR_ROWS);
        Progress.switchToDeterminate(progressTicket, tiles);
        while (!renderer.eot() && !cancel) {
            renderer.display();
            Progress.progress(progressTicket);
        }
        Progress.switchToIndeterminate(progressTicket);
        renderer.detachAutoDrawable();
        autoDrawable.invoke(true, new GLRunnable() {

            @Override
            public boolean run(final GLAutoDrawable drawable) {
                drawable.getGL().glViewport(0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
                //                drawable.reshape(drawable, 0, 0, drawable.getSurfaceWidth(), drawable.getSurfaceHeight());
                return false;
            }
        });
        vizConfig.setDisableLOD(false);
        engine.updateLOD();
        if (!cancel) {
            final GLPixelBuffer imageBuffer = renderer.getImageBuffer();
            final TextureData textureData = new TextureData(autoDrawable.getChosenGLCapabilities().getGLProfile(), transparentBackground ? GL.GL_RGBA : GL.GL_RGB, width, height, 0, imageBuffer.pixelAttributes, false, false, flipVertically[0], imageBuffer.buffer, null);
            // Get File
            SwingUtilities.invokeAndWait(new Runnable() {

                @Override
                public void run() {
                    if (!autoSave) {
                        //Get last directory
                        String lastPathDefault = NbPreferences.forModule(ScreenshotMaker.class).get(LAST_PATH_DEFAULT, null);
                        String lastPath = NbPreferences.forModule(ScreenshotMaker.class).get(LAST_PATH, lastPathDefault);
                        final JFileChooser chooser = new JFileChooser(lastPath);
                        chooser.setAcceptAllFileFilterUsed(false);
                        chooser.setDialogTitle(NbBundle.getMessage(ScreenshotMaker.class, "ScreenshotMaker.filechooser.title"));
                        DialogFileFilter dialogFileFilter = new DialogFileFilter(NbBundle.getMessage(ScreenshotMaker.class, "ScreenshotMaker.filechooser.pngDescription"));
                        dialogFileFilter.addExtension("png");
                        chooser.addChoosableFileFilter(dialogFileFilter);
                        File selectedFile = new File(chooser.getCurrentDirectory(), getDefaultFileName() + ".png");
                        chooser.setSelectedFile(selectedFile);
                        int returnFile = chooser.showSaveDialog(null);
                        if (returnFile == JFileChooser.APPROVE_OPTION) {
                            ScreenshotMaker.this.file = chooser.getSelectedFile();
                            if (!ScreenshotMaker.this.file.getPath().endsWith(".png")) {
                                ScreenshotMaker.this.file = new File(ScreenshotMaker.this.file.getPath() + ".png");
                            }
                            //Save last path
                            defaultDirectory = ScreenshotMaker.this.file.getParentFile().getAbsolutePath();
                            NbPreferences.forModule(ScreenshotMaker.class).put(LAST_PATH, defaultDirectory);
                        } else {
                            ScreenshotMaker.this.file = null;
                        }
                    } else {
                        ScreenshotMaker.this.file = new File(defaultDirectory, getDefaultFileName() + ".png");
                    }
                }
            });
            // Write file
            if (file != null) {
                TextureIO.write(textureData, file);
            }
        }
        autoDrawable.destroy();
        //Reinit text renderer
        textManager.reinitRenderers();
        engine.startDisplay();
        //Progress finish
        Progress.finish(progressTicket);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    // After taking
    afterTaking();
}
Also used : GLAutoDrawable(com.jogamp.opengl.GLAutoDrawable) GL2(com.jogamp.opengl.GL2) GLEventListener(com.jogamp.opengl.GLEventListener) TextureData(com.jogamp.opengl.util.texture.TextureData) JFileChooser(javax.swing.JFileChooser) GLPixelBuffer(com.jogamp.opengl.util.GLPixelBuffer) GLPixelAttributes(com.jogamp.opengl.util.GLPixelBuffer.GLPixelAttributes) GLRunnable(com.jogamp.opengl.GLRunnable) GLRunnable(com.jogamp.opengl.GLRunnable) DialogFileFilter(org.gephi.ui.utils.DialogFileFilter) File(java.io.File) TileRenderer(com.jogamp.opengl.util.TileRenderer)

Aggregations

DialogFileFilter (org.gephi.ui.utils.DialogFileFilter)9 JFileChooser (javax.swing.JFileChooser)7 File (java.io.File)6 FileType (org.gephi.io.exporter.api.FileType)4 FileObject (org.openide.filesystems.FileObject)3 BorderLayout (java.awt.BorderLayout)2 Component (java.awt.Component)2 FlowLayout (java.awt.FlowLayout)2 Insets (java.awt.Insets)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 JButton (javax.swing.JButton)2 JComponent (javax.swing.JComponent)2 JPanel (javax.swing.JPanel)2 ExportControllerUI (org.gephi.desktop.io.export.ExportControllerUI)2 ExporterUI (org.gephi.io.exporter.spi.ExporterUI)2 GraphFileExporterBuilder (org.gephi.io.exporter.spi.GraphFileExporterBuilder)2 VectorFileExporterBuilder (org.gephi.io.exporter.spi.VectorFileExporterBuilder)2