コード例 #1
0
 /** Accept a change. */
 public void accept() {
   ProjectionRect bb = mapViewPanel.getMapArea();
   if ((bb == null) || (current == null)) {
     return;
   }
   current.setDefaultMapArea(new ProjectionRect(bb));
   lm.sendEvent(new java.beans.PropertyChangeEvent(this, PROPERTY_CHANGE, null, current));
 }
コード例 #2
0
    /** user has hit the "accept/save" button */
    private void accept() {
      ProjectionClass projClass = findProjectionClass(editProjection);
      if (null == projClass) {
        System.out.println(
            "Projection Manager accept: findProjectionClass failed" + editProjection);
        return;
      }
      setProjFromDialog(projClass, editProjection);
      ProjectionRect mapArea = mapEditPanel.getSelectedRegion();
      if (mapArea == null) {
        mapArea = mapEditPanel.getMapArea();
      }
      editProjection.setDefaultMapArea(mapArea);

      if (debug) {
        System.out.println("Projection Manager accept bb =" + editProjection.getDefaultMapArea());
      }
      ProjectionImpl newProj = (ProjectionImpl) editProjection.constructCopy(); // use a copy

      if (viewDialog != null) {
        //                if ( !viewDialog.checkSaveOK(startingName,
        //                                             newProj.getName())) {
        //                    return;
        //                }
      }

      if (ProjectionManager.this.contains(newProj.getName())) {
        projTable.replaceProjection(newProj);
      } else {
        projTable.addProjection(newProj);
      }

      // set new projection to working projection and exit this Dialog
      setWorkingProjection(newProj);
      NewProjectionDialog.this.setVisible(false);
    }
コード例 #3
0
    /** Create the UI for this editor */
    void makeUI() {

      JPanel mainPanel = new JPanel(new BorderLayout());
      mainPanel.setBorder(new LineBorder(Color.blue));
      getContentPane().add(mainPanel, BorderLayout.CENTER);

      // the map and associated toolbar
      npEditControl = new NPController();
      mapEditPanel = npEditControl.getNavigatedPanel(); // here's where the map will be drawn
      mapEditPanel.setPreferredSize(new Dimension(250, 250));
      mapEditPanel.setSelectRegionMode(true);
      JToolBar navToolbar = mapEditPanel.getNavToolBar();
      navToolbar.setFloatable(false);
      JToolBar moveToolbar = mapEditPanel.getMoveToolBar();
      moveToolbar.setFloatable(false);
      // toolbar.remove("setReference");

      JPanel toolbar = new JPanel();
      List localMaps = maps;
      if (localMaps == null) {
        localMaps = getDefaultMaps();
      }
      JMenu mapMenu = new JMenu("Maps");
      JMenuBar menuHolder = new JMenuBar();
      menuHolder.setBorder(null);
      menuHolder.add(mapMenu);
      toolbar.add(menuHolder);
      for (int mapIdx = 0; mapIdx < localMaps.size(); mapIdx++) {
        final MapData mapData = (MapData) localMaps.get(mapIdx);
        final JCheckBoxMenuItem cbx =
            new JCheckBoxMenuItem(mapData.getDescription(), mapData.getVisible());
        if (mapData.getVisible()) {
          toggleMap(mapData, true);
        }
        mapMenu.add(cbx);
        cbx.addItemListener(
            new ItemListener() {
              public void itemStateChanged(ItemEvent event) {
                toggleMap(mapData, cbx.isSelected());
              }
            });
      }
      GuiUtils.limitMenuSize(mapMenu, "Maps ", 20);

      toolbar.add(navToolbar);
      toolbar.add(moveToolbar);

      JPanel mapSide = new JPanel();
      mapSide.setLayout(new BorderLayout());
      TitledBorder mapBorder =
          new TitledBorder(
              standardBorder, "Edit Projection", TitledBorder.ABOVE_TOP, TitledBorder.CENTER);
      mapSide.setBorder(mapBorder);
      mapSide.add(toolbar, BorderLayout.NORTH);
      mapSide.add(mapEditPanel, BorderLayout.CENTER);
      mainPanel.add(mapSide, BorderLayout.WEST);

      // the projection parameters

      // the Projection name
      JLabel nameLabel = GuiUtils.rLabel("Name: ");
      nameTF = new JTextField(20);

      // the list of Projection classes is kept in a comboBox
      typeLabel = GuiUtils.rLabel("Type: ");
      projClassCB = new JComboBox();
      // standard list of projection classes
      List classNames = getDefaultProjections();
      for (int i = 0; i < classNames.size(); i++) {
        String className = (String) classNames.get(i);
        try {
          projClassCB.addItem(new ProjectionClass(className));
        } catch (ClassNotFoundException ee) {
          System.err.println("ProjectionManager failed on " + className + " " + ee);
        } catch (IntrospectionException ee) {
          System.err.println("ProjectionManager failed on " + className + " " + ee);
        }
      }
      GuiUtils.tmpInsets = new Insets(4, 4, 4, 4);
      JPanel topPanel =
          GuiUtils.doLayout(
              new Component[] {nameLabel, nameTF, typeLabel, projClassCB},
              2,
              GuiUtils.WT_N,
              GuiUtils.WT_N);

      // the Projection parameter area
      paramPanel = new JPanel();
      paramPanel.setLayout(new BorderLayout());
      paramPanel.setBorder(
          new TitledBorder(
              standardBorder,
              "Projection Parameters",
              TitledBorder.ABOVE_TOP,
              TitledBorder.CENTER));

      // the bottom button panel
      JPanel buttPanel = new JPanel();
      JButton acceptButton = new JButton("Save");
      JButton previewButton = new JButton("Preview");
      JButton cancelButton = new JButton("Cancel");
      buttPanel.add(acceptButton, null);
      buttPanel.add(previewButton, null);
      buttPanel.add(cancelButton, null);

      JPanel mainBox = GuiUtils.topCenterBottom(topPanel, paramPanel, buttPanel);
      mainPanel.add(mainBox, BorderLayout.CENTER);
      pack();

      // enable event listeners when we're done constructing the UI
      projClassCB.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              ProjectionClass selectClass = (ProjectionClass) projClassCB.getSelectedItem();
              setProjection(selectClass.makeDefaultProjection());
            }
          });

      acceptButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              accept();
            }
          });
      previewButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              ProjectionClass projClass = findProjectionClass(editProjection);
              if (null != projClass) {
                setProjFromDialog(projClass, editProjection);
                setProjection(editProjection);
              }
            }
          });
      cancelButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              NewProjectionDialog.this.setVisible(false);
            }
          });
    }
コード例 #4
0
  /**
   * 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);
    }
  }