コード例 #1
0
  public void propertyChange(PropertyChangeEvent e) {
    String prop = e.getPropertyName();

    if (isVisible()
        && (e.getSource() == optionPane)
        && (JOptionPane.VALUE_PROPERTY.equals(prop)
            || JOptionPane.INPUT_VALUE_PROPERTY.equals(prop))) {
      Object value = optionPane.getValue();

      if (value == JOptionPane.UNINITIALIZED_VALUE) return;
      optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);

      if (button1.equals(value)) {
        try {
          double a = Double.parseDouble(left.getText());
          double b = Double.parseDouble(right.getText());
          double err = Double.parseDouble(error.getText());

          if (a > b) {
            JOptionPane.showMessageDialog(this, "A < B!!!", null, JOptionPane.ERROR_MESSAGE);
          } else {
            hideIt();
            graphic.startApplyingMethod(parentFrame.getSelectedMethod(), err, a, b);
          }
        } catch (Exception ex) {
          JOptionPane.showMessageDialog(
              this, "Trebuie sa fie numar real!", null, JOptionPane.ERROR_MESSAGE);
        }
      } else if (button2.equals(value)) {
        hideIt();
      }
    }
  }
コード例 #2
0
    public void actionPerformed(ActionEvent e) {
      if (readOnly) {
        return;
      }
      JFileChooser fc = getFileChooser();
      File currentDirectory = fc.getCurrentDirectory();

      if (!currentDirectory.exists()) {
        JOptionPane.showMessageDialog(
            fc,
            newFolderParentDoesntExistText,
            newFolderParentDoesntExistTitleText,
            JOptionPane.WARNING_MESSAGE);
        return;
      }

      File newFolder;
      try {
        newFolder = fc.getFileSystemView().createNewFolder(currentDirectory);
        if (fc.isMultiSelectionEnabled()) {
          fc.setSelectedFiles(new File[] {newFolder});
        } else {
          fc.setSelectedFile(newFolder);
        }
      } catch (IOException exc) {
        JOptionPane.showMessageDialog(
            fc,
            newFolderErrorText + newFolderErrorSeparator + exc,
            newFolderErrorText,
            JOptionPane.ERROR_MESSAGE);
        return;
      }

      fc.rescanCurrentDirectory();
    }
コード例 #3
0
 /**
  * Let the caller of this dialog know whether the user connected or cancelled.
  *
  * @return true if the user cancelled or closed the window.
  */
 public boolean userCanceled() {
   if (options.getValue() instanceof Integer) {
     int status = ((Integer) options.getValue()).intValue();
     return status != JOptionPane.OK_OPTION;
   } else {
     return false;
   }
 }
コード例 #4
0
 /**
  * Common event handling code - can handle desirable actions (such as buttons being clicked) and
  * undesirable actions (the window being closed) all in a common location.
  *
  * @param command a String representing the action that occurred.
  */
 private void processCommand(String command) {
   dialog.setVisible(false);
   if (CONNECT.equals(command)) {
     options.setValue(JOptionPane.OK_OPTION);
   } else {
     options.setValue(JOptionPane.CANCEL_OPTION);
   }
 }
コード例 #5
0
ファイル: ContextEditor.java プロジェクト: sillsdev/silkin
 public void nameFocusLost(java.awt.event.FocusEvent evt) {
   ctxt.saveState = true;
   String newName = name.getText(), msg;
   while (!Library.validateFileName(newName, false)) {
     msg = "The name '" + newName + "' violates the rules for names:";
     msg += "\nIt must have 2 to 28 characters.";
     msg += "\nYou may not use BackSlash, ForwardSlash, Colon, DoubleQuote";
     msg += "\nAsterisk, QuestionMark, LeftAngleBracket, RightAngleBracket,";
     msg += "\nor the VerticalBar in a name. TRY AGAIN.";
     newName = JOptionPane.showInputDialog(msg);
   } //  end of harrass-em-until-they-give-a-good-name
   name.setText(newName);
   if (!newName.equals(ctxt.languageName)) { // Made a change
     msg = "Change this context's language name\nto" + newName + "?";
     String[] options = {newName, ctxt.languageName};
     int choice =
         JOptionPane.showOptionDialog(
             this,
             msg,
             "Confirm Changed Language Name",
             JOptionPane.YES_NO_OPTION,
             JOptionPane.QUESTION_MESSAGE,
             null,
             options,
             options[0]);
     if (choice == 0) { //  Change is confirmed
       ctxt.languageName = newName;
       msg =
           "Normally, the file name for a context is the same as the language name "
               + "\nfor that context.  Change this context's file name\n"
               + "to "
               + newName
               + "?";
       options[0] = "Change File Name";
       options[1] = "Do Not Change";
       choice =
           JOptionPane.showOptionDialog(
               this,
               msg,
               "Confirm Correct File Name",
               JOptionPane.YES_NO_OPTION,
               JOptionPane.QUESTION_MESSAGE,
               null,
               options,
               options[0]);
       if (choice == 0) {
         Library.userContextName = newName;
         if (SIL_Edit.edWin != null && ctxt == Library.contextUnderConstruction) {
           SIL_Edit.edWin.chart.changeFileName(newName);
         }
       }
     } //  end of Change-is-confirmed
   } //  end of change-was-made
 }
コード例 #6
0
  userDialog(ApplicationFrame frame, Graphic gr) {
    super(frame, "Precizati intervalul...", true);
    parentFrame = frame;
    graphic = gr;

    left = new JTextField(10);
    right = new JTextField(10);
    error = new JTextField(10);

    Object[] optionPaneComponent = {text1, left, text2, right, text3, error};
    Object[] optionPaneButtons = {button1, button2};

    optionPane =
        new JOptionPane(
            optionPaneComponent,
            JOptionPane.QUESTION_MESSAGE,
            JOptionPane.YES_NO_OPTION,
            null,
            optionPaneButtons,
            optionPaneButtons[0]);

    setContentPane(optionPane);
    pack();

    optionPane.addPropertyChangeListener(this);

    setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
    setResizable(false);
  }
コード例 #7
0
ファイル: Notepad.java プロジェクト: ArcherSys/ArcherSysRuby
    @Override
    public void actionPerformed(ActionEvent e) {
      Frame frame = getFrame();
      JFileChooser chooser = new JFileChooser();
      int ret = chooser.showOpenDialog(frame);

      if (ret != JFileChooser.APPROVE_OPTION) {
        return;
      }

      File f = chooser.getSelectedFile();
      if (f.isFile() && f.canRead()) {
        Document oldDoc = getEditor().getDocument();
        if (oldDoc != null) {
          oldDoc.removeUndoableEditListener(undoHandler);
        }
        if (elementTreePanel != null) {
          elementTreePanel.setEditor(null);
        }
        getEditor().setDocument(new PlainDocument());
        frame.setTitle(f.getName());
        Thread loader = new FileLoader(f, editor.getDocument());
        loader.start();
      } else {
        JOptionPane.showMessageDialog(
            getFrame(),
            "Could not open file: " + f,
            "Error opening file",
            JOptionPane.ERROR_MESSAGE);
      }
    }
コード例 #8
0
    /** handle the action event */
    protected void handleToDefaultFolderAction() throws Exception {
      if (!defaultFolderSpecified()) {
        String message =
            "A default folder has not been specified.  Would you like to specify one now?\n";
        if (_subfolderName != null) {
          message +=
              "Note that you will be specifying the parent folder of " + _subfolderName + ".\n";
          message += _subfolderName + " under the selected folder will hold your files.";
        }
        final int confirm =
            JOptionPane.showConfirmDialog(
                _view, message, "Specify Default Folder", JOptionPane.YES_NO_OPTION);

        try {
          switch (confirm) {
            case JOptionPane.YES_OPTION:
              if (!showDefaultFolderSelector()) return;
              break;
            default:
              return;
          }
        } catch (Exception exception) {
          exception.printStackTrace();
        }
      }

      applyDefaultFolder(_activeFileChooser);
    }
コード例 #9
0
  /**
   * Checks to see if the sketch has been modified, and if so, asks the user to save the sketch or
   * cancel the export. This prevents issues where an incomplete version of the sketch would be
   * exported, and is a fix for <A HREF="http://dev.processing.org/bugs/show_bug.cgi?id=157">Bug
   * 157</A>
   */
  protected boolean handleExportCheckModified() {
    if (sketch.isModified()) {
      Object[] options = {"OK", "Cancel"};
      int result =
          JOptionPane.showOptionDialog(
              this,
              "Save changes before export?",
              "Save",
              JOptionPane.OK_CANCEL_OPTION,
              JOptionPane.QUESTION_MESSAGE,
              null,
              options,
              options[0]);

      if (result == JOptionPane.OK_OPTION) {
        handleSave(true);

      } else {
        // why it's not CANCEL_OPTION is beyond me (at least on the mac)
        // but f-- it.. let's get this s***e done..
        // } else if (result == JOptionPane.CANCEL_OPTION) {
        statusNotice("Export canceled, changes must first be saved.");
        // toolbar.clear();
        return false;
      }
    }
    return true;
  }
コード例 #10
0
ファイル: Plotter.java プロジェクト: susotajuraj/jdk8u-jdk
  private void saveDataToFile(File file) {
    try {
      PrintStream out = new PrintStream(new FileOutputStream(file));

      // Print header line
      out.print("Time");
      for (Sequence seq : seqs) {
        out.print("," + seq.name);
      }
      out.println();

      // Print data lines
      if (seqs.size() > 0 && seqs.get(0).size > 0) {
        for (int i = 0; i < seqs.get(0).size; i++) {
          double excelTime = toExcelTime(times.time(i));
          out.print(String.format(Locale.ENGLISH, "%.6f", excelTime));
          for (Sequence seq : seqs) {
            out.print("," + getFormattedValue(seq.value(i), false));
          }
          out.println();
        }
      }

      out.close();
      JOptionPane.showMessageDialog(
          this,
          Resources.format(
              Messages.FILE_CHOOSER_SAVED_FILE, file.getAbsolutePath(), file.length()));
    } catch (IOException ex) {
      String msg = ex.getLocalizedMessage();
      String path = file.getAbsolutePath();
      if (msg.startsWith(path)) {
        msg = msg.substring(path.length()).trim();
      }
      JOptionPane.showMessageDialog(
          this,
          Resources.format(Messages.FILE_CHOOSER_SAVE_FAILED_MESSAGE, path, msg),
          Messages.FILE_CHOOSER_SAVE_FAILED_TITLE,
          JOptionPane.ERROR_MESSAGE);
    }
  }
コード例 #11
0
 public void save() {
   if (chooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
     try {
       File file = chooser.getSelectedFile();
       XMLEncoder encoder = new XMLEncoder(new FileOutputStream(file));
       encoder.writeObject(frame);
       encoder.close();
     } catch (IOException e) {
       JOptionPane.showMessageDialog(null, e);
     }
   }
 }
コード例 #12
0
  public void load() {
    // show file chooser dialog
    int r = chooser.showOpenDialog(null);

    // if file selected, open
    if (r == JFileChooser.APPROVE_OPTION) {
      try {
        File file = chooser.getSelectedFile();
        XMLDecoder decoder = new XMLDecoder(new FileInputStream(file));
        decoder.readObject();
        decoder.close();
      } catch (IOException e) {
        JOptionPane.showMessageDialog(null, e);
      }
    }
  }
コード例 #13
0
ファイル: Plotter.java プロジェクト: susotajuraj/jdk8u-jdk
    @Override
    public void approveSelection() {
      File file = getSelectedFile();
      if (file != null) {
        FileFilter filter = getFileFilter();
        if (filter != null && filter instanceof FileNameExtensionFilter) {
          String[] extensions = ((FileNameExtensionFilter) filter).getExtensions();

          boolean goodExt = false;
          for (String ext : extensions) {
            if (file.getName().toLowerCase().endsWith("." + ext.toLowerCase())) {
              goodExt = true;
              break;
            }
          }
          if (!goodExt) {
            file = new File(file.getParent(), file.getName() + "." + extensions[0]);
          }
        }

        if (file.exists()) {
          String okStr = Messages.FILE_CHOOSER_FILE_EXISTS_OK_OPTION;
          String cancelStr = Messages.FILE_CHOOSER_FILE_EXISTS_CANCEL_OPTION;
          int ret =
              JOptionPane.showOptionDialog(
                  this,
                  Resources.format(Messages.FILE_CHOOSER_FILE_EXISTS_MESSAGE, file.getName()),
                  Messages.FILE_CHOOSER_FILE_EXISTS_TITLE,
                  JOptionPane.OK_CANCEL_OPTION,
                  JOptionPane.WARNING_MESSAGE,
                  null,
                  new Object[] {okStr, cancelStr},
                  okStr);
          if (ret != JOptionPane.OK_OPTION) {
            return;
          }
        }
        setSelectedFile(file);
      }
      super.approveSelection();
    }
コード例 #14
0
 public void init() {
   jop.addPropertyChangeListener(
       new PropertyChangeListener() {
         public void propertyChange(PropertyChangeEvent evt) {
           jta.append("用户改变了选择,老选项为:" + evt.getOldValue() + "\n新选项为:" + evt.getNewValue() + "!\n");
         }
       });
   bn.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           jop.createDialog(jf, "测试对话框").setVisible(true);
           jta.append(jop.getValue() + "\n");
         }
       });
   jf.add(new JScrollPane(jta));
   JPanel jp = new JPanel();
   jp.add(bn);
   jf.add(jp, BorderLayout.SOUTH);
   jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   jf.pack();
   jf.setVisible(true);
 }
コード例 #15
0
    protected void openFromURL() {
      Object input =
          JOptionPane.showInputDialog(
              this.getApp(),
              "Enter a URL: ",
              "Open Shapes from URL",
              JOptionPane.QUESTION_MESSAGE,
              null,
              null,
              null);
      if (input == null) return;

      URL url = null;
      try {
        url = new URL(input.toString());
      } catch (IOException e) {
        e.printStackTrace();
      }

      if (url != null) {
        this.openFromPath(url.toExternalForm());
      }
    }
コード例 #16
0
  /**
   * Creates a dialog where the user can specify the location of the database,including the type of
   * network connection (if this is a networked client)and IP address and port number; or search and
   * select the database on a local drive if this is a standalone client.
   *
   * @param parent Defines the Component that is to be the parent of this dialog box. For
   *     information on how this is used, see <code>JOptionPane</code>
   * @param connectionMode Specifies the type of connection (standalone or networked)
   * @see JOptionPane
   */
  public DatabaseLocationDialog(Frame parent, ApplicationMode connectionMode) {
    configOptions = (new ConfigOptions(connectionMode));
    configOptions.getObservable().addObserver(this);

    // load saved configuration
    SavedConfiguration config = SavedConfiguration.getSavedConfiguration();

    // the port and connection type are irrelevant in standalone mode
    if (connectionMode == ApplicationMode.STANDALONE_CLIENT) {
      validPort = true;
      validCnx = true;
      networkType = ConnectionType.DIRECT;
      location = config.getParameter(SavedConfiguration.DATABASE_LOCATION);
    } else {
      // there may not be a network connectivity type defined and, if
      // not, we do not set a default - force the user to make a choice
      // the at least for the first time they run this.
      String tmp = config.getParameter(SavedConfiguration.NETWORK_TYPE);
      if (tmp != null) {
        try {
          networkType = ConnectionType.valueOf(tmp);
          configOptions.setNetworkConnection(networkType);
          validCnx = true;
        } catch (IllegalArgumentException e) {
          log.warning("Unknown connection type: " + networkType);
        }
      }

      // there is always at least a default port number, so we don't have
      // to validate this.
      port = config.getParameter(SavedConfiguration.SERVER_PORT);
      configOptions.setPortNumberText(port);
      validPort = true;

      location = config.getParameter(SavedConfiguration.SERVER_ADDRESS);
    }

    // there may not be a default database location, so we had better
    // validate before using the returned value.
    if (location != null) {
      configOptions.setLocationFieldText(location);
      validDb = true;
    }

    options =
        new JOptionPane(configOptions, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);

    connectButton.setActionCommand(CONNECT);
    connectButton.addActionListener(this);

    boolean allValid = validDb && validPort && validCnx;
    connectButton.setEnabled(allValid);

    exitButton.setActionCommand(EXIT);
    exitButton.addActionListener(this);

    options.setOptions(new Object[] {connectButton, exitButton});

    dialog = options.createDialog(parent, TITLE);
    dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    dialog.addWindowListener(this);
    dialog.setVisible(true);
  }
コード例 #17
0
 public void showAboutBox() {
   JOptionPane.showMessageDialog(this, ABOUTMSG);
 }
コード例 #18
0
ファイル: ContextEditor.java プロジェクト: sillsdev/silkin
    public void actionPerformed(ActionEvent e) {
      if (rebuilding) {
        return;
      }
      if (e.getActionCommand().equals("polygamy yes")) {
        ctxt.saveState = true;
        ctxt.polygamyPermit = true;
        SIL_Edit.edWin.chart.dirty = true;
      }
      if (e.getActionCommand().equals("polygamy no")) {
        ctxt.saveState = true;
        ctxt.polygamyPermit = false;
        SIL_Edit.edWin.chart.dirty = true;
      }
      if (e.getActionCommand().equals("distinct yes")) {
        ctxt.saveState = true;
        ctxt.distinctAdrTerms = true;
        SIL_Edit.edWin.setDistinctAdrMenuItemSelected(true);
        SIL_Edit.edWin.distinctAdrItemActionPerformed(null);
        SIL_Edit.edWin.chart.dirty = true;
        MainPane.topPane.setVisible(true);
      }
      if (e.getActionCommand().equals("distinct no")) {
        ctxt.saveState = true;
        ctxt.distinctAdrTerms = false;
        SIL_Edit.edWin.setDistinctAdrMenuItemSelected(false);
        SIL_Edit.edWin.distinctAdrItemActionPerformed(null);
        SIL_Edit.edWin.chart.dirty = true;
        MainPane.topPane.setVisible(true);
      }
      if (e.getActionCommand().equals("edit matrix")) {
        JOptionPane.showMessageDialog(
            ed,
            "Editing the Kin Term Matrix as a table" + "\nwill be a feature of a future version.",
            "Action Not Availabe",
            JOptionPane.INFORMATION_MESSAGE);
      }
      if (e.getActionCommand().equals("view/edit person")) {
        ctxt.saveState = true;
        Individual edee = (Individual) peopleList.get(indPick.getSelectedIndex());
        PersonEditor pEd = new PersonEditor(ctxt, ed, "View or Edit a Person", edee, "census", 0);
        if (!pEd.dupEditor) {
          pEd.desktop = desktop;
          desktop.add(pEd);
          pEd.miViewMe = menuView.add(pEd.windowNum);
          pEd.miViewMe.addActionListener(pEd);
          pEd.menuView = menuView;
          pEd.show();
          pEd.moveToFront();
          try {
            pEd.setSelected(true);
          } catch (PropertyVetoException pv) {
          }
        } else {
          try {
            pEd.setClosed(true);
          } catch (PropertyVetoException pv) {
          }
        }
      }
      if (e.getActionCommand().equals("view/edit family")) {
        ctxt.saveState = true;
        int serial = famPick.getSelectedIndex();
        Family edee = (Family) famList.get(serial);
        FamilyEditor fEd = new FamilyEditor(ctxt, ed, "View or Edit a Family", edee, "census");
        if (!fEd.dupEditor) {
          fEd.desktop = desktop;
          fEd.setLocation(350, 100);
          desktop.add(fEd);
          fEd.miViewMe = menuView.add(fEd.windowNum);
          fEd.miViewMe.addActionListener(fEd);
          fEd.menuView = menuView;
          fEd.show();
          fEd.moveToFront();
          try {
            fEd.setSelected(true);
          } catch (PropertyVetoException pv) {
          }
        } else {
          try {
            fEd.setClosed(true);
          } catch (PropertyVetoException pv) {
          }
        }
      }
      if (e.getActionCommand().equals("add UDP")) {
        UserDefinedProperty newU = new UserDefinedProperty("*newUDP");
        UDPEditor eddy = new UDPEditor(ctxt, ed, "Create New UDP", true, newU);
        eddy.desktop = desktop;
        eddy.setLocation(250, 50);
        desktop.add(eddy);
        eddy.miViewMe = menuView.add(eddy.windowNum);
        eddy.miViewMe.addActionListener(eddy);
        eddy.menuView = menuView;
        eddy.show();
        eddy.moveToFront();
        try {
          eddy.setSelected(true);
        } catch (PropertyVetoException pv) {
        }
      }
      if (e.getActionCommand().equals("view/edit UDP")) {
        String victim = (String) UDPick.getSelectedItem();
        UserDefinedProperty theUDP = (UserDefinedProperty) ctxt.userDefinedProperties.get(victim);
        UDPEditor eddy = new UDPEditor(ctxt, ed, "Edit UDP " + victim, false, theUDP);
        eddy.desktop = desktop;
        eddy.setLocation(250, 50);
        desktop.add(eddy);
        eddy.miViewMe = menuView.add(eddy.windowNum);
        eddy.miViewMe.addActionListener(eddy);
        eddy.menuView = menuView;
        eddy.show();
        eddy.moveToFront();
        try {
          eddy.setSelected(true);
        } catch (PropertyVetoException pv) {
        }
      }

      if (e.getActionCommand().equals("edit dtRef")) {
        ctxt.saveState = true;
        try {
          EditTheoryFrame etf = EditTheoryFrame.getEditTheoryFrame(ctxt.domTheoryRef());
          etf.setVisible(true);
        } catch (Exception exc) {
          System.err.println("ERROR in creating Edit Frame.\n" + exc);
        }
      }
      if (e.getActionCommand().equals("edit dtAddr")) {
        ctxt.saveState = true;
        try {
          EditTheoryFrame etf = EditTheoryFrame.getEditTheoryFrame(ctxt.domTheoryAdr());
          etf.setVisible(true);
        } catch (Exception exc) {
          System.err.println("ERROR in creating Edit Frame.\n" + exc);
        }
      }
    } //  end of ActionListener method actionPerformed
コード例 #19
0
  protected boolean exportApplicationPrompt() throws IOException, SketchException {
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.add(Box.createVerticalStrut(6));

    // Box panel = Box.createVerticalBox();

    // Box labelBox = Box.createHorizontalBox();
    //    String msg = "<html>Click Export to Application to create a standalone, " +
    //      "double-clickable application for the selected plaforms.";

    //    String msg = "Export to Application creates a standalone, \n" +
    //      "double-clickable application for the selected plaforms.";
    String line1 = "Export to Application creates double-clickable,";
    String line2 = "standalone applications for the selected plaforms.";
    JLabel label1 = new JLabel(line1, SwingConstants.CENTER);
    JLabel label2 = new JLabel(line2, SwingConstants.CENTER);
    label1.setAlignmentX(Component.LEFT_ALIGNMENT);
    label2.setAlignmentX(Component.LEFT_ALIGNMENT);
    //    label1.setAlignmentX();
    //    label2.setAlignmentX(0);
    panel.add(label1);
    panel.add(label2);
    int wide = label2.getPreferredSize().width;
    panel.add(Box.createVerticalStrut(12));

    final JCheckBox windowsButton = new JCheckBox("Windows");
    // windowsButton.setMnemonic(KeyEvent.VK_W);
    windowsButton.setSelected(Preferences.getBoolean("export.application.platform.windows"));
    windowsButton.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            Preferences.setBoolean(
                "export.application.platform.windows", windowsButton.isSelected());
          }
        });

    final JCheckBox macosxButton = new JCheckBox("Mac OS X");
    // macosxButton.setMnemonic(KeyEvent.VK_M);
    macosxButton.setSelected(Preferences.getBoolean("export.application.platform.macosx"));
    macosxButton.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            Preferences.setBoolean("export.application.platform.macosx", macosxButton.isSelected());
          }
        });

    final JCheckBox linuxButton = new JCheckBox("Linux");
    // linuxButton.setMnemonic(KeyEvent.VK_L);
    linuxButton.setSelected(Preferences.getBoolean("export.application.platform.linux"));
    linuxButton.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            Preferences.setBoolean("export.application.platform.linux", linuxButton.isSelected());
          }
        });

    JPanel platformPanel = new JPanel();
    // platformPanel.setLayout(new BoxLayout(platformPanel, BoxLayout.X_AXIS));
    platformPanel.add(windowsButton);
    platformPanel.add(Box.createHorizontalStrut(6));
    platformPanel.add(macosxButton);
    platformPanel.add(Box.createHorizontalStrut(6));
    platformPanel.add(linuxButton);
    platformPanel.setBorder(new TitledBorder("Platforms"));
    // Dimension goodIdea = new Dimension(wide, platformPanel.getPreferredSize().height);
    // platformPanel.setMaximumSize(goodIdea);
    wide = Math.max(wide, platformPanel.getPreferredSize().width);
    platformPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    panel.add(platformPanel);

    //  Box indentPanel = Box.createHorizontalBox();
    //  indentPanel.add(Box.createHorizontalStrut(new JCheckBox().getPreferredSize().width));
    final JCheckBox showStopButton = new JCheckBox("Show a Stop button");
    // showStopButton.setMnemonic(KeyEvent.VK_S);
    showStopButton.setSelected(Preferences.getBoolean("export.application.stop"));
    showStopButton.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            Preferences.setBoolean("export.application.stop", showStopButton.isSelected());
          }
        });
    showStopButton.setEnabled(Preferences.getBoolean("export.application.fullscreen"));
    showStopButton.setBorder(new EmptyBorder(3, 13, 6, 13));
    //  indentPanel.add(showStopButton);
    //  indentPanel.setAlignmentX(Component.LEFT_ALIGNMENT);

    final JCheckBox fullScreenButton = new JCheckBox("Full Screen (Present mode)");
    // fullscreenButton.setMnemonic(KeyEvent.VK_F);
    fullScreenButton.setSelected(Preferences.getBoolean("export.application.fullscreen"));
    fullScreenButton.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            boolean sal = fullScreenButton.isSelected();
            Preferences.setBoolean("export.application.fullscreen", sal);
            showStopButton.setEnabled(sal);
          }
        });
    fullScreenButton.setBorder(new EmptyBorder(3, 13, 3, 13));

    JPanel optionPanel = new JPanel();
    optionPanel.setLayout(new BoxLayout(optionPanel, BoxLayout.Y_AXIS));
    optionPanel.add(fullScreenButton);
    optionPanel.add(showStopButton);
    //    optionPanel.add(indentPanel);
    optionPanel.setBorder(new TitledBorder("Options"));
    wide = Math.max(wide, platformPanel.getPreferredSize().width);
    // goodIdea = new Dimension(wide, optionPanel.getPreferredSize().height);
    optionPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    // optionPanel.setMaximumSize(goodIdea);
    panel.add(optionPanel);

    Dimension good;
    // label1, label2, platformPanel, optionPanel
    good = new Dimension(wide, label1.getPreferredSize().height);
    label1.setMaximumSize(good);
    good = new Dimension(wide, label2.getPreferredSize().height);
    label2.setMaximumSize(good);
    good = new Dimension(wide, platformPanel.getPreferredSize().height);
    platformPanel.setMaximumSize(good);
    good = new Dimension(wide, optionPanel.getPreferredSize().height);
    optionPanel.setMaximumSize(good);

    //    JPanel actionPanel = new JPanel();
    //    optionPanel.setLayout(new BoxLayout(optionPanel, BoxLayout.X_AXIS));
    //    optionPanel.add(Box.createHorizontalGlue());

    //    final JDialog frame = new JDialog(editor, "Export to Application");

    //    JButton cancelButton = new JButton("Cancel");
    //    cancelButton.addActionListener(new ActionListener() {
    //      public void actionPerformed(ActionEvent e) {
    //        frame.dispose();
    //        return false;
    //      }
    //    });

    // Add the buttons in platform-specific order
    //    if (PApplet.platform == PConstants.MACOSX) {
    //      optionPanel.add(cancelButton);
    //      optionPanel.add(exportButton);
    //    } else {
    //      optionPanel.add(exportButton);
    //      optionPanel.add(cancelButton);
    //    }
    String[] options = {"Export", "Cancel"};
    final JOptionPane optionPane =
        new JOptionPane(
            panel,
            JOptionPane.PLAIN_MESSAGE,
            // JOptionPane.QUESTION_MESSAGE,
            JOptionPane.YES_NO_OPTION,
            null,
            options,
            options[0]);

    final JDialog dialog = new JDialog(this, "Export Options", true);
    dialog.setContentPane(optionPane);

    optionPane.addPropertyChangeListener(
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent e) {
            String prop = e.getPropertyName();

            if (dialog.isVisible()
                && (e.getSource() == optionPane)
                && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
              // If you were going to check something
              // before closing the window, you'd do
              // it here.
              dialog.setVisible(false);
            }
          }
        });
    dialog.pack();
    dialog.setResizable(false);

    Rectangle bounds = getBounds();
    dialog.setLocation(
        bounds.x + (bounds.width - dialog.getSize().width) / 2,
        bounds.y + (bounds.height - dialog.getSize().height) / 2);
    dialog.setVisible(true);

    Object value = optionPane.getValue();
    if (value.equals(options[0])) {
      return jmode.handleExportApplication(sketch);
    } else if (value.equals(options[1]) || value.equals(new Integer(-1))) {
      // closed window by hitting Cancel or ESC
      statusNotice("Export to Application canceled.");
    }
    return false;
  }
コード例 #20
0
 /** report exceptions */
 protected void reportException(final Exception exception) {
   final String message = exception.getMessage();
   JOptionPane.showMessageDialog(
       _view, message, "Default Folder Error", JOptionPane.ERROR_MESSAGE);
 }