Example usage for javax.swing JOptionPane WARNING_MESSAGE

List of usage examples for javax.swing JOptionPane WARNING_MESSAGE

Introduction

In this page you can find the example usage for javax.swing JOptionPane WARNING_MESSAGE.

Prototype

int WARNING_MESSAGE

To view the source code for javax.swing JOptionPane WARNING_MESSAGE.

Click Source Link

Document

Used for warning messages.

Usage

From source file:biz.wolschon.finance.jgnucash.actions.ImportPluginMenuAction.java

@Override
public void actionPerformed(final ActionEvent e) {
    try {//www .j  a va 2  s  .c  o  m
        GnucashWritableFile wModel = myJGnucashEditor.getWritableModel();
        if (wModel == null) {
            JOptionPane.showMessageDialog(myJGnucashEditor, "No open file.",
                    "Please open a gnucash-file first!", JOptionPane.WARNING_MESSAGE);
            return;
        }

        // Activate plug-in that declares extension.
        myJGnucashEditor.getPluginManager().activatePlugin(ext.getDeclaringPluginDescriptor().getId());
        // Get plug-in class loader.
        ClassLoader classLoader = myJGnucashEditor.getPluginManager()
                .getPluginClassLoader(ext.getDeclaringPluginDescriptor());
        // Load Tool class.
        Class toolCls = classLoader.loadClass(ext.getParameter("class").valueAsString());
        // Create Tool instance.
        Object o = toolCls.newInstance();
        if (!(o instanceof ImporterPlugin)) {
            LOGGER.error("Plugin '" + pluginName + "' does not implement ImporterPlugin-interface.");
            JOptionPane.showMessageDialog(myJGnucashEditor, "Error",
                    "Plugin '" + pluginName + "' does not implement ImporterPlugin-interface.",
                    JOptionPane.ERROR_MESSAGE);
            return;

        }
        ImporterPlugin importer = (ImporterPlugin) o;
        try {
            myJGnucashEditor.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            GnucashWritableAccount selectedAccount = (GnucashWritableAccount) myJGnucashEditor
                    .getSelectedAccount();
            String message = importer.runImport(wModel, selectedAccount);
            if (message != null && message.length() > 0) {
                JOptionPane.showMessageDialog(myJGnucashEditor, "Import OK",
                        "The import was a success:\n" + message, JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception e1) {
            LOGGER.error("Import via Plugin '" + pluginName + "' failed.", e1);
            JOptionPane
                    .showMessageDialog(
                            myJGnucashEditor, "Error", "Import via Plugin '" + pluginName + "' failed.\n" + "["
                                    + e1.getClass().getName() + "]: " + e1.getMessage(),
                            JOptionPane.ERROR_MESSAGE);
        } finally {
            myJGnucashEditor.setCursor(Cursor.getDefaultCursor());
        }
    } catch (Exception e1) {
        LOGGER.error("Could not activate requested import-plugin '" + pluginName + "'.", e1);
        JOptionPane
                .showMessageDialog(
                        myJGnucashEditor, "Error", "Could not activate requested import-plugin '" + pluginName
                                + "'.\n" + "[" + e1.getClass().getName() + "]: " + e1.getMessage(),
                        JOptionPane.ERROR_MESSAGE);
    }
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopComponentsHelper.java

public static int convertMessageType(Frame.MessageMode messageType) {
    switch (messageType) {
    case CONFIRMATION:
    case CONFIRMATION_HTML:
        return JOptionPane.QUESTION_MESSAGE;
    case WARNING:
    case WARNING_HTML:
        return JOptionPane.WARNING_MESSAGE;
    default:/*from w ww .  j  a  v  a 2s . c  o  m*/
        return JOptionPane.INFORMATION_MESSAGE;
    }
}

From source file:Splash.java

public Splash(JFrame f, String progName, String fileName) {
    super();/*from w  w w. j a  v a 2 s  . co m*/
    // Can't use Swing border on JWindow: not a JComponent.
    // setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
    im = new ImageIcon(fileName);
    if (im.getImageLoadStatus() != MediaTracker.COMPLETE)
        JOptionPane.showMessageDialog(f, "Warning: can't load image " + fileName + "\n"
                + "Please be sure you have installed " + progName + " correctly", "Warning",
                JOptionPane.WARNING_MESSAGE);
    int w = im.getIconWidth(), h = im.getIconHeight();
    setSize(w, h);
    UtilGUI.center(this);
    addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            dispose();
        }
    });
    addKeyListener(new KeyAdapter() {
        public void keyTyped(KeyEvent e) {
            dispose();
        }
    });
}

From source file:sistemacontrole.LeituraEscritaCanais.java

LeituraEscritaCanais(LoginWindow loginWindow, MainWindow mainWindow) {
    //setar views
    this.loginWindow = loginWindow;
    this.mainWindow = mainWindow;
    this.plantaSimulacao = new Simulacao();

    //checar se foi login offline
    this.isOffline = this.loginWindow.isOffline();

    //cria a conexo com a planta caso no seja offline
    if (!this.isOffline) {
        try {/* w  w w  .j  a v  a  2s .c  o  m*/
            this.quanserClient = new QuanserClient(this.loginWindow.GetIP(), this.loginWindow.GetPorta());
        } catch (QuanserClientException ex) {
            JOptionPane.showMessageDialog(this.loginWindow, "Erro ao se conectar a planta!", "Erro!",
                    JOptionPane.ERROR_MESSAGE);
            System.out.println("Erro ao se conectar a planta!");
        }
    } else {
        JOptionPane.showMessageDialog(this.loginWindow, "Planta no conectada! \nModo de simulao ativado.",
                "Ateno!", JOptionPane.WARNING_MESSAGE);
        this.mainWindow.setTitle(this.mainWindow.getTitle() + " (Offline)");
    }

    //varivel de tempo global para grfico
    this.tempoGlobal = 0;

    //inicializar curvas dos grficos
    this.sinal_calculado = new XYSeries("Saida 0 - Calculado");
    this.sinal_tratado = new XYSeries("Saida 0 - Tratada");
    this.sinal_entrada = new XYSeries[7];
    this.valor_P = new XYSeries("Parametro P");
    this.valor_I = new XYSeries("Parametro I");
    this.valor_D = new XYSeries("Parametro D");
    this.erro_PID = new XYSeries("Erro calculado");
    this.setPointCurva = new XYSeries("Set Point");

    for (int i = 0; i < 7; ++i) {
        this.sinal_entrada[i] = new XYSeries("Canal " + i);
    }

    //iniciar tempo global
    tempoInicial = System.nanoTime();

    //inicializao de threads
    this.relogio = new Thread(new atualizarTempoGlobal());//inicializar contador de tempo

    new Thread(new atualizarGraficos()).start();//inicializar atualizao dos grficos

    new Thread(new getCanaisValores()).start();//inicializar leitura dos canais

    //objetos de sincronizao de leitura e escrita de canal
    leituraEscrita = new leituraEscritaSync();
}

From source file:latexstudio.editor.DbxFileActions.java

/**
 * Saves progress to dropbox and updates file history (DropboxRevisions)
 *
 * @param drtc to be updated with a new entry (file history)
 *//*www  . jav a2 s  .co m*/
public void saveProgress(DbxClient client, DropboxRevisionsTopComponent drtc) {
    DbxState dbxState = etc.getDbxState();

    if (client == null) {
        return;
    }

    File file = new File(ApplicationUtils.getTempSourceFile());

    try (FileInputStream inputStream = new FileInputStream(file)) {
        if (dbxState != null) {
            try {
                DbxEntry.File uploadedFile = client.uploadFile(dbxState.getPath(),
                        DbxWriteMode.update(dbxState.getRevision()), file.length(), inputStream);
                JOptionPane.showMessageDialog(null,
                        "Successfuly updated file " + uploadedFile.name + " (" + uploadedFile.humanSize + ")",
                        "File updated in Dropbox", JOptionPane.INFORMATION_MESSAGE);
                drtc.updateRevisionsList(uploadedFile.path);
                etc.setDbxState(new DbxState(uploadedFile.path, uploadedFile.rev));
            } catch (DbxException ex) {
                DbxUtil.showDbxAccessDeniedPrompt();
            } catch (IOException ex) {
                Exceptions.printStackTrace(ex);
            } finally {
                IOUtils.closeQuietly(inputStream);
                etc.setModified(false);
            }
        } else {
            JOptionPane.showMessageDialog(null,
                    "No Dropbox file has been loaded.\n" + "You must open Dropbox file, before you save it.",
                    "Cannot save progress", JOptionPane.WARNING_MESSAGE);
        }
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopComponentsHelper.java

public static int convertNotificationType(com.haulmont.cuba.gui.components.Frame.NotificationType type) {
    switch (type) {
    case WARNING:
    case WARNING_HTML:
        return JOptionPane.WARNING_MESSAGE;
    case ERROR:/*from w  w  w .ja va2 s .co  m*/
    case ERROR_HTML:
        return JOptionPane.ERROR_MESSAGE;
    case HUMANIZED:
    case HUMANIZED_HTML:
        return JOptionPane.INFORMATION_MESSAGE;
    case TRAY:
    case TRAY_HTML:
        return JOptionPane.WARNING_MESSAGE;
    default:
        return JOptionPane.PLAIN_MESSAGE;
    }
}

From source file:edu.smc.mediacommons.panels.SecurityPanel.java

public SecurityPanel() {
    setLayout(null);//  ww w .j av a 2 s  . c o m

    FILE_CHOOSER = new JFileChooser();

    JButton openFile = Utils.createButton("Open File", 10, 20, 100, 30, null);
    add(openFile);

    JButton saveFile = Utils.createButton("Save File", 110, 20, 100, 30, null);
    add(saveFile);

    JButton decrypt = Utils.createButton("Decrypt", 210, 20, 100, 30, null);
    add(decrypt);

    JButton encrypt = Utils.createButton("Encrypt", 310, 20, 100, 30, null);
    add(encrypt);

    JTextField path = Utils.createTextField(10, 30, 300, 20);
    path.setText("No file selected");

    final JTextArea viewer = new JTextArea();
    JScrollPane pastePane = new JScrollPane(viewer);
    pastePane.setBounds(15, 60, 400, 200);
    add(pastePane);

    openFile.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (FILE_CHOOSER.showOpenDialog(getParent()) == JFileChooser.APPROVE_OPTION) {
                File toRead = FILE_CHOOSER.getSelectedFile();

                if (toRead == null) {
                    JOptionPane.showMessageDialog(getParent(), "The input file does not exist!",
                            "Opening Failed...", JOptionPane.WARNING_MESSAGE);
                } else {
                    try {
                        List<String> lines = IOUtils.readLines(new FileInputStream(toRead), "UTF-8");

                        viewer.setText("");

                        for (String line : lines) {
                            viewer.append(line);
                        }
                    } catch (IOException ex) {

                    }
                }
            }
        }
    });

    saveFile.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (FILE_CHOOSER.showSaveDialog(getParent()) == JFileChooser.APPROVE_OPTION) {
                File toWrite = FILE_CHOOSER.getSelectedFile();

                Utils.writeToFile(viewer.getText(), toWrite);
                JOptionPane.showMessageDialog(getParent(),
                        "The file has now been saved to\n" + toWrite.getPath());
            }
        }
    });

    encrypt.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String password = Utils.getPasswordInput(getParent());

            if (password != null) {
                try {
                    BasicTextEncryptor basicTextEncryptor = new BasicTextEncryptor();
                    basicTextEncryptor.setPassword(password);

                    String text = basicTextEncryptor.encrypt(viewer.getText());
                    viewer.setText(text);
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(getParent(),
                            "Could not encrypt the text, an unexpected error occurred.", "Encryption Failed...",
                            JOptionPane.WARNING_MESSAGE);
                }
            } else {
                JOptionPane.showMessageDialog(getParent(),
                        "Could not encrypt the text, as no\npassword has been specified.",
                        "Encryption Failed...", JOptionPane.WARNING_MESSAGE);
            }
        }
    });

    decrypt.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String password = Utils.getPasswordInput(getParent());

            if (password != null) {
                try {
                    BasicTextEncryptor basicTextEncryptor = new BasicTextEncryptor();
                    basicTextEncryptor.setPassword(password);

                    String text = basicTextEncryptor.decrypt(viewer.getText());
                    viewer.setText(text);
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(getParent(),
                            "Could not decrypt the text, an unexpected error occurred.", "Decryption Failed...",
                            JOptionPane.WARNING_MESSAGE);
                }
            } else {
                JOptionPane.showMessageDialog(getParent(),
                        "Could not decrypt the text, as no\npassword has been specified.",
                        "Decryption Failed...", JOptionPane.WARNING_MESSAGE);
            }
        }
    });
}

From source file:latexstudio.editor.remote.SaveProgress.java

@Override
public void actionPerformed(ActionEvent e) {
    DbxClient client = DbxUtil.getDbxClient();

    if (client == null) {
        return;//from w w w .  ja va2s.c  o m
    }

    String sourceFileName = ApplicationUtils.getTempSourceFile();
    File file = new File(sourceFileName);

    FileInputStream inputStream = null;
    try {
        inputStream = new FileInputStream(file);
    } catch (FileNotFoundException ex) {
        Exceptions.printStackTrace(ex);
    }

    DbxState dbxState = etc.getDbxState();

    if (dbxState != null) {
        try {
            DbxEntry.File uploadedFile = client.uploadFile(dbxState.getPath(),
                    DbxWriteMode.update(dbxState.getRevision()), file.length(), inputStream);
            JOptionPane.showMessageDialog(null,
                    "Successfuly updated file " + uploadedFile.name + " (" + uploadedFile.humanSize + ")",
                    "File updated in Dropbox", JOptionPane.INFORMATION_MESSAGE);
            drtc.updateRevisionsList(uploadedFile.path);
            etc.setDbxState(new DbxState(uploadedFile.path, uploadedFile.rev));
        } catch (DbxException ex) {
            DbxUtil.showDbxAccessDeniedPrompt();
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        } finally {
            IOUtils.closeQuietly(inputStream);
        }
    } else {
        JOptionPane.showMessageDialog(null,
                "No Dropbox file has been loaded.\n" + "You must open Dropbox file, before you save it.",
                "Cannot save progress", JOptionPane.WARNING_MESSAGE);
    }
}

From source file:BeanContainer.java

  protected JMenuBar createMenuBar() {
  JMenuBar menuBar = new JMenuBar();
    //from w w  w.  j  a  v  a  2s .co  m
  JMenu mFile = new JMenu("File");

  JMenuItem mItem = new JMenuItem("New...");
  ActionListener lst = new ActionListener() { 
    public void actionPerformed(ActionEvent e) {  
      Thread newthread = new Thread() {
        public void run() {
          String result = (String)JOptionPane.showInputDialog(
            BeanContainer.this, 
            "Please enter class name to create a new bean", 
            "Input", JOptionPane.INFORMATION_MESSAGE, null, 
            null, m_className);
          repaint();
          if (result==null)
            return;
          try {
            m_className = result;
            Class cls = Class.forName(result);
            Object obj = cls.newInstance();
            if (obj instanceof Component) {
              m_activeBean = (Component)obj;
              m_activeBean.addFocusListener(
                BeanContainer.this);
              m_activeBean.requestFocus();
              getContentPane().add(m_activeBean);
            }
            validate();
          }
          catch (Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(
              BeanContainer.this, "Error: "+ex.toString(),
              "Warning", JOptionPane.WARNING_MESSAGE);
          }
        }
      };
      newthread.start();
    }
  };
  mItem.addActionListener(lst);
  mFile.add(mItem);

  mItem = new JMenuItem("Load...");
  lst = new ActionListener() { 
    public void actionPerformed(ActionEvent e) {  
      Thread newthread = new Thread() {
        public void run() {
          m_chooser.setCurrentDirectory(m_currentDir);
          m_chooser.setDialogTitle(
            "Please select file with serialized bean");
          int result = m_chooser.showOpenDialog(
            BeanContainer.this);
          repaint();
          if (result != JFileChooser.APPROVE_OPTION)
            return;
          m_currentDir = m_chooser.getCurrentDirectory();
          File fChoosen = m_chooser.getSelectedFile();
          try {
            FileInputStream fStream = 
              new FileInputStream(fChoosen);
            ObjectInput  stream  =  
              new ObjectInputStream(fStream);
            Object obj = stream.readObject();
            if (obj instanceof Component) {
              m_activeBean = (Component)obj;
              m_activeBean.addFocusListener(
                BeanContainer.this);
              m_activeBean.requestFocus();
              getContentPane().add(m_activeBean);
            }
            stream.close();
            fStream.close();
            validate();
          }
          catch (Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(
              BeanContainer.this, "Error: "+ex.toString(),
              "Warning", JOptionPane.WARNING_MESSAGE);
          }
          repaint();
        }
      };
      newthread.start();
    }
  };
  mItem.addActionListener(lst);
  mFile.add(mItem);

  mItem = new JMenuItem("Save...");
  lst = new ActionListener() { 
    public void actionPerformed(ActionEvent e) {
      Thread newthread = new Thread() {
        public void run() {
          if (m_activeBean == null)
            return;
          m_chooser.setDialogTitle(
            "Please choose file to serialize bean");
          m_chooser.setCurrentDirectory(m_currentDir);
          int result = m_chooser.showSaveDialog(
            BeanContainer.this);
          repaint();
          if (result != JFileChooser.APPROVE_OPTION)
            return;
          m_currentDir = m_chooser.getCurrentDirectory();
          File fChoosen = m_chooser.getSelectedFile();
          try {
            FileOutputStream fStream = 
              new FileOutputStream(fChoosen);
            ObjectOutput stream  =  
              new ObjectOutputStream(fStream);
            stream.writeObject(m_activeBean);
            stream.close();
            fStream.close();
          }
          catch (Exception ex) {
            ex.printStackTrace();
          JOptionPane.showMessageDialog(
            BeanContainer.this, "Error: "+ex.toString(),
            "Warning", JOptionPane.WARNING_MESSAGE);
          }
        }
      };
      newthread.start();
    }
  };
  mItem.addActionListener(lst);
  mFile.add(mItem);

  mFile.addSeparator();

  mItem = new JMenuItem("Exit");
  lst = new ActionListener() { 
    public void actionPerformed(ActionEvent e) {
      System.exit(0);
    }
  };
  mItem.addActionListener(lst);
  mFile.add(mItem);
  menuBar.add(mFile);
    
  JMenu mEdit = new JMenu("Edit");

  mItem = new JMenuItem("Delete");
  lst = new ActionListener() { 
    public void actionPerformed(ActionEvent e) {
      if (m_activeBean == null)
        return;
      Object obj = m_editors.get(m_activeBean);
      if (obj != null) {
        BeanEditor editor = (BeanEditor)obj;
        editor.dispose();
        m_editors.remove(m_activeBean);
      }
      getContentPane().remove(m_activeBean);
      m_activeBean = null;
      validate();
      repaint();
    }
  };
  mItem.addActionListener(lst);
  mEdit.add(mItem);

  mItem = new JMenuItem("Properties...");
  lst = new ActionListener() { 
    public void actionPerformed(ActionEvent e) {
      if (m_activeBean == null)
        return;
      Object obj = m_editors.get(m_activeBean);
      if (obj != null) {
        BeanEditor editor = (BeanEditor)obj;
        editor.setVisible(true);
        editor.toFront();
      }
      else {
        BeanEditor editor = new BeanEditor(m_activeBean);
        m_editors.put(m_activeBean, editor);
      }
    }
  };
  mItem.addActionListener(lst);
  mEdit.add(mItem);
  menuBar.add(mEdit);

  JMenu mLayout = new JMenu("Layout");
  ButtonGroup group = new ButtonGroup();

  mItem = new JRadioButtonMenuItem("FlowLayout");
  mItem.setSelected(true);
  lst = new ActionListener() { 
    public void actionPerformed(ActionEvent e){
      getContentPane().setLayout(new FlowLayout());
      validate();
      repaint();
    }
  };
  mItem.addActionListener(lst);
  group.add(mItem);
  mLayout.add(mItem);

  mItem = new JRadioButtonMenuItem("GridLayout");
  lst = new ActionListener() { 
    public void actionPerformed(ActionEvent e){
      int col = 3;
      int row = (int)Math.ceil(getContentPane().
        getComponentCount()/(double)col);
      getContentPane().setLayout(new GridLayout(row, col, 10, 10));
      validate();
      repaint();
    }
  };
  mItem.addActionListener(lst);
  group.add(mItem);
  mLayout.add(mItem);
    
  mItem = new JRadioButtonMenuItem("BoxLayout - X");
  lst = new ActionListener() { 
    public void actionPerformed(ActionEvent e) {
      getContentPane().setLayout(new BoxLayout(
        getContentPane(), BoxLayout.X_AXIS));
      validate();
      repaint();
    }
  };
  mItem.addActionListener(lst);
  group.add(mItem);
  mLayout.add(mItem);
    
  mItem = new JRadioButtonMenuItem("BoxLayout - Y");
  lst = new ActionListener() { 
    public void actionPerformed(ActionEvent e) {
      getContentPane().setLayout(new BoxLayout(
        getContentPane(), BoxLayout.Y_AXIS));
      validate();
      repaint();
    }
  };
  mItem.addActionListener(lst);
  group.add(mItem);
  mLayout.add(mItem);
    
  mItem = new JRadioButtonMenuItem("DialogLayout");
  lst = new ActionListener() { 
    public void actionPerformed(ActionEvent e) {
      getContentPane().setLayout(new DialogLayout());
      validate();
      repaint();
    }
  };
  mItem.addActionListener(lst);
  group.add(mItem);
  mLayout.add(mItem);

  menuBar.add(mLayout);

  return menuBar;
}

From source file:edu.ku.brc.af.core.SpecialMsgNotifier.java

public void checkForMessages() {
    if (blockMsg.get()) {
        return;/*from   w w w .j  av a2  s  . c o  m*/
    }

    SwingWorker<Integer, Integer> msgCheckWorker = new SwingWorker<Integer, Integer>() {
        protected String msg = null;

        /* (non-Javadoc)
         * @see javax.swing.SwingWorker#doInBackground()
         */
        @Override
        protected Integer doInBackground() throws Exception {
            if (!blockMsg.get()) {
                try {
                    Thread.sleep(15000); // 15 seconds

                    String url = UIRegistry.getResourceString("CGI_BASE_URL") + "/getmsg2.php";
                    String installID = UsageTracker.getInstallId();

                    msg = send(url, installID);
                    msg = StringUtils.deleteWhitespace(msg);

                } catch (Exception ex) {
                    // die silently
                }
            }
            return null;
        }

        @Override
        protected void done() {
            super.done();

            if (msg != null) {
                //System.out.println("["+msg+"]");

                if (StringUtils.isNotEmpty(msg) && !StringUtils.contains(msg, "NOMSG")) {
                    String header = msg.length() > 6 ? msg.substring(0, 7).toUpperCase() : "";
                    if (header.startsWith("<HTML>")) {
                        UIRegistry.showLocalizedError("NO_INTERNET");
                    } else {
                        UIRegistry.showError(JOptionPane.WARNING_MESSAGE, msg);
                    }
                }
            }

        }
    };

    msgCheckWorker.execute();
}