Search in sources :

Example 21 with NotifyDescriptor

use of org.openide.NotifyDescriptor in project blue by kunstmusik.

the class BlueProjectManager method save.

public void save() {
    if (getCurrentProject().getDataFile() != null) {
        try (PrintWriter out = new PrintWriter(new FileWriter(getCurrentProject().getDataFile()))) {
            out.print(getCurrentProject().getData().saveAsXML().toString());
            out.flush();
        } catch (IOException ioe) {
            NotifyDescriptor descriptor = new NotifyDescriptor.Message("Could not save file:\n\n" + ioe.getLocalizedMessage(), NotifyDescriptor.ERROR_MESSAGE);
            DialogDisplayer.getDefault().notify(descriptor);
        } catch (Exception e) {
            e.printStackTrace();
        }
        StatusDisplayer.getDefault().setStatusText("File saved: " + getCurrentProject().getDataFile().getName());
    } else {
        saveAs();
    }
}
Also used : NotifyDescriptor(org.openide.NotifyDescriptor) FileWriter(java.io.FileWriter) IOException(java.io.IOException) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 22 with NotifyDescriptor

use of org.openide.NotifyDescriptor in project gephi by gephi.

the class CommandLineProcessor method process.

@Override
public void process(Env env, Map values) throws CommandException {
    List<String> filenameList = new ArrayList<>();
    Object obj = values.get(openOption);
    if (obj != null) {
        filenameList.addAll(Arrays.asList((String[]) obj));
    }
    obj = values.get(openOption2);
    if (obj != null) {
        filenameList.addAll(Arrays.asList((String[]) obj));
    }
    try {
        for (int i = 0; i < filenameList.size(); i++) {
            File file = new File(filenameList.get(i));
            if (!file.isAbsolute()) {
                file = new File(env.getCurrentDirectory(), filenameList.get(i));
            }
            FileObject fileObject = FileUtil.toFileObject(file);
            if (!file.exists()) {
                NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(CommandLineProcessor.class, "CommandLineProcessor.fileNotFound", file.getName()), NotifyDescriptor.WARNING_MESSAGE);
                DialogDisplayer.getDefault().notify(msg);
                return;
            }
            if (fileObject.hasExt(GEPHI_EXTENSION)) {
                ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
                try {
                    pc.openProject(file);
                } catch (Exception ew) {
                    Exceptions.printStackTrace(ew);
                    NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(CommandLineProcessor.class, "CommandLineProcessor.openGephiError"), NotifyDescriptor.WARNING_MESSAGE);
                    DialogDisplayer.getDefault().notify(msg);
                }
                return;
            } else {
                ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
                if (importController.getImportController().isFileSupported(FileUtil.toFile(fileObject))) {
                    importController.importFile(fileObject);
                } else {
                    NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(CommandLineProcessor.class, "CommandLineProcessor.fileNotSupported"), NotifyDescriptor.WARNING_MESSAGE);
                    DialogDisplayer.getDefault().notify(msg);
                }
            }
        }
    } catch (OutOfMemoryError ex) {
        System.gc();
        NotifyDescriptor nd = new NotifyDescriptor.Message(MEMORY_ERROR, NotifyDescriptor.ERROR_MESSAGE);
        DialogDisplayer.getDefault().notify(nd);
    } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
        NotifyDescriptor nd = new NotifyDescriptor.Message("CommandLineParsing " + ex.getMessage(), NotifyDescriptor.ERROR_MESSAGE);
        DialogDisplayer.getDefault().notify(nd);
    }
}
Also used : ArrayList(java.util.ArrayList) CommandException(org.netbeans.api.sendopts.CommandException) NotifyDescriptor(org.openide.NotifyDescriptor) ImportControllerUI(org.gephi.desktop.importer.api.ImportControllerUI) FileObject(org.openide.filesystems.FileObject) FileObject(org.openide.filesystems.FileObject) File(java.io.File) ProjectControllerUI(org.gephi.desktop.project.api.ProjectControllerUI)

Example 23 with NotifyDescriptor

use of org.openide.NotifyDescriptor in project gephi by gephi.

the class MemoryStarvationManager method handleNotification.

@Override
public void handleNotification(Notification n, Object o) {
    if (messageDelivered) {
        return;
    }
    CompositeData cd = (CompositeData) n.getUserData();
    MemoryNotificationInfo info = MemoryNotificationInfo.from(cd);
    suspendThreads();
    messageDelivered = true;
    // Dialog
    if (canIncreaseMemory()) {
        String messageBundle = NbBundle.getMessage(MemoryStarvationManager.class, "OutOfMemoryError.canIncreaseMemory.message", getMb(Runtime.getRuntime().maxMemory()) + " mb", getMb(getMaximumXmx()) + " mb");
        String titleBundle = NbBundle.getMessage(MemoryStarvationManager.class, "OutOfMemoryError.title");
        String increaseAndRestart = NbBundle.getMessage(MemoryStarvationManager.class, "OutOfMemoryError.canIncreaseMemory.button");
        String cancelBundle = NbBundle.getMessage(MemoryStarvationManager.class, "OutOfMemoryError.cancel");
        NotifyDescriptor msg = new NotifyDescriptor(messageBundle, titleBundle, NotifyDescriptor.YES_NO_CANCEL_OPTION, NotifyDescriptor.ERROR_MESSAGE, new Object[] { increaseAndRestart, cancelBundle }, increaseAndRestart);
        if (DialogDisplayer.getDefault().notify(msg) != increaseAndRestart) {
            resumeThreads();
            return;
        }
        String xmx = getMb(getMaximumXmx()) + "m";
        try {
            updateConfiguration(xmx);
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
    } else {
        String messageBundle = NbBundle.getMessage(MemoryStarvationManager.class, "OutOfMemoryError.canIncreaseMemory.message", getMb(Runtime.getRuntime().maxMemory()) + " mb");
        String titleBundle = NbBundle.getMessage(MemoryStarvationManager.class, "OutOfMemoryError.title");
        String saveAndRestart = NbBundle.getMessage(MemoryStarvationManager.class, "OutOfMemoryError.canIncreaseMemory.button");
        String cancelBundle = NbBundle.getMessage(MemoryStarvationManager.class, "OutOfMemoryError.cancel");
        NotifyDescriptor msg = new NotifyDescriptor(messageBundle, titleBundle, NotifyDescriptor.YES_NO_CANCEL_OPTION, NotifyDescriptor.ERROR_MESSAGE, new Object[] { saveAndRestart, cancelBundle }, saveAndRestart);
        if (DialogDisplayer.getDefault().notify(msg) != saveAndRestart) {
            resumeThreads();
            return;
        }
    }
    interruptThreads();
    freeSomeMemory();
    saveProject();
    restart();
}
Also used : NotifyDescriptor(org.openide.NotifyDescriptor) MemoryNotificationInfo(java.lang.management.MemoryNotificationInfo) CompositeData(javax.management.openmbean.CompositeData) IOException(java.io.IOException)

Example 24 with NotifyDescriptor

use of org.openide.NotifyDescriptor in project gephi by gephi.

the class Delete method execute.

@Override
public void execute() {
    NotifyDescriptor.Confirmation notifyDescriptor = new NotifyDescriptor.Confirmation(NbBundle.getMessage(Delete.class, "GraphContextMenu.Delete.message"), NbBundle.getMessage(Delete.class, "GraphContextMenu.Delete.message.title"), NotifyDescriptor.YES_NO_OPTION);
    if (DialogDisplayer.getDefault().notify(notifyDescriptor).equals(NotifyDescriptor.YES_OPTION)) {
        GraphElementsController gec = Lookup.getDefault().lookup(GraphElementsController.class);
        gec.deleteNodes(nodes);
    }
}
Also used : NotifyDescriptor(org.openide.NotifyDescriptor) GraphElementsController(org.gephi.datalab.api.GraphElementsController)

Example 25 with NotifyDescriptor

use of org.openide.NotifyDescriptor in project netbeans-mmd-plugin by raydac.

the class NbUtils method msgConfirmYesNoCancel.

@Nullable
public static Boolean msgConfirmYesNoCancel(@Nullable Component parentComponent, @Nonnull final String title, @Nonnull final String query) {
    final NotifyDescriptor desc = new NotifyDescriptor.Confirmation(query, title, NotifyDescriptor.YES_NO_CANCEL_OPTION);
    final Object obj = DialogDisplayer.getDefault().notify(desc);
    if (NotifyDescriptor.CANCEL_OPTION.equals(obj)) {
        return null;
    }
    return NotifyDescriptor.YES_OPTION.equals(obj);
}
Also used : NotifyDescriptor(org.openide.NotifyDescriptor) DataObject(org.openide.loaders.DataObject) FileObject(org.openide.filesystems.FileObject) Nullable(javax.annotation.Nullable)

Aggregations

NotifyDescriptor (org.openide.NotifyDescriptor)26 FileObject (org.openide.filesystems.FileObject)5 File (java.io.File)4 IOException (java.io.IOException)4 BlueData (blue.BlueData)3 PolyObject (blue.soundObject.PolyObject)3 Nullable (javax.annotation.Nullable)3 DataObject (org.openide.loaders.DataObject)3 ScoreObject (blue.score.ScoreObject)2 SoundObject (blue.soundObject.SoundObject)2 FileChooserManager (blue.ui.utilities.FileChooserManager)2 Dimension (java.awt.Dimension)2 FileWriter (java.io.FileWriter)2 PrintWriter (java.io.PrintWriter)2 AudioFile (blue.soundObject.AudioFile)1 FrozenSoundObject (blue.soundObject.FrozenSoundObject)1 Instance (blue.soundObject.Instance)1 ScoreObjectEditor (blue.soundObject.editor.ScoreObjectEditor)1 MMapURI (com.igormaznitsa.mindmap.model.MMapURI)1 FileEditPanel (com.igormaznitsa.nbmindmap.nb.swing.FileEditPanel)1