/**
  * 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);
   }
 }
Example #2
0
  public void setVisible(boolean bShow) {
    if (bShow) {
      if (CSH_Util.haveTopic(dialogTitle)) setHelpEnabled(true);
      else setHelpEnabled(false);

      enableControlPanel();
    }
    VPopupManager.addRemovePopup(this, bShow);
    super.setVisible(bShow);
  }
  /**
   * 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);
  }
  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;
  }
 /** Destroy this object */
 public void destroy() {
   if (viewDialog != null) {
     viewDialog.dispose();
     viewDialog = null;
   }
 }
 /** Popup the Manager Dialog */
 public void show() {
   if (viewDialog != null) {
     viewDialog.setVisible(true);
   }
 }
 /** Close this widget */
 public void close() {
   if (viewDialog != null) {
     viewDialog.setVisible(false);
   }
 }
  /**
   * Create a new ProjectionManager.
   *
   * @param parent JFrame (application) or JApplet (applet)
   * @param projections list of initial projections
   * @param makeDialog true to make this a dialog
   * @param helpId help id if dialog
   * @param maps List of MapData
   */
  public ProjectionManager(
      RootPaneContainer parent, List projections, boolean makeDialog, String helpId, List maps) {

    this.helpId = helpId;
    this.maps = maps;
    this.parent = parent;

    // manage NewProjectionListeners
    lm =
        new ListenerManager(
            "java.beans.PropertyChangeListener",
            "java.beans.PropertyChangeEvent",
            "propertyChange");

    // here's where the map will be drawn: but cant be changed/edited
    npViewControl = new NPController();
    if (maps == null) {
      maps = getDefaultMaps(); // we use the system default
    }
    for (int mapIdx = 0; mapIdx < maps.size(); mapIdx++) {
      MapData mapData = (MapData) maps.get(mapIdx);
      if (mapData.getVisible()) {
        npViewControl.addMap(mapData.getSource(), mapData.getColor());
      }
    }
    mapViewPanel = npViewControl.getNavigatedPanel();
    mapViewPanel.setPreferredSize(new Dimension(250, 250));
    mapViewPanel.setToolTipText("Shows the default zoom of the current projection");
    mapViewPanel.setChangeable(false);

    if ((projections == null) || (projections.size() == 0)) {
      projections = makeDefaultProjections();
    }

    // the actual list is a JTable subclass
    projTable = new JTableProjection(this, projections);

    JComponent listContents = new JScrollPane(projTable);

    JComponent buttons =
        GuiUtils.hbox(
            GuiUtils.makeButton("Edit", this, "doEdit"),
            GuiUtils.makeButton("New", this, "doNew"),
            GuiUtils.makeButton("Export", this, "doExport"),
            GuiUtils.makeButton("Delete", this, "doDelete"));

    mapLabel = new JLabel(" ");
    JComponent leftPanel = GuiUtils.inset(GuiUtils.topCenter(mapLabel, mapViewPanel), 5);

    JComponent rightPanel = GuiUtils.topCenter(buttons, listContents);
    rightPanel = GuiUtils.inset(rightPanel, 5);
    contents = GuiUtils.inset(GuiUtils.hbox(leftPanel, rightPanel), 5);

    // default current and working projection
    if (null != (current = projTable.getSelected())) {
      setWorkingProjection(current);
      projTable.setCurrentProjection(current);
      mapLabel.setText(current.getName());
    }

    /* listen for new working Projections from projTable */
    projTable.addNewProjectionListener(
        new NewProjectionListener() {
          public void actionPerformed(NewProjectionEvent e) {
            if (e.getProjection() != null) {
              setWorkingProjection(e.getProjection());
            }
          }
        });

    eventsOK = true;

    // put it together in the viewDialog
    if (makeDialog) {
      Container buttPanel = GuiUtils.makeApplyOkHelpCancelButtons(this);
      contents = GuiUtils.centerBottom(contents, buttPanel);
      viewDialog =
          GuiUtils.createDialog(GuiUtils.getApplicationTitle() + "Projection Manager", false);
      viewDialog.getContentPane().add(contents);
      viewDialog.pack();
      ucar.unidata.util.Msg.translateTree(viewDialog);
      viewDialog.setLocation(100, 100);
    }
  }