Example #1
0
  /** Intialize me */
  private void init() {
    myTables = new ArrayList();
    tableTabbedPane = new JTabbedPane();
    tableTabbedPane.setPreferredSize(new Dimension(450, 200));
    JMenuBar menuBar = new JMenuBar();
    JMenu fileMenu = new JMenu("File");
    menuBar.add(fileMenu);
    fileMenu.add(GuiUtils.makeMenuItem("New Row", this, "addNewRow"));
    fileMenu.addSeparator();
    fileMenu.add(GuiUtils.makeMenuItem("Open", this, "doOpen"));
    fileMenu.add(GuiUtils.makeMenuItem("Import", this, "doImport"));
    fileMenu.addSeparator();
    fileMenu.add(GuiUtils.makeMenuItem("Export to File", this, "doSaveAs"));
    fileMenu.add(GuiUtils.makeMenuItem("Export to Plugin", this, "exportToPlugin"));
    fileMenu.add(
        GuiUtils.makeMenuItem("Export Selected to Plugin", this, "exportSelectedToPlugin"));
    fileMenu.addSeparator();
    fileMenu.add(GuiUtils.makeMenuItem("Close", this, "doClose"));

    JMenu helpMenu = new JMenu("Help");
    menuBar.add(helpMenu);
    helpMenu.add(GuiUtils.makeMenuItem("Parameter Defaults Help", this, "showHelp"));
    JComponent bottom = GuiUtils.wrap(GuiUtils.makeButton("Close", this, "doClose"));
    contents = GuiUtils.topCenterBottom(menuBar, GuiUtils.inset(tableTabbedPane, 2), bottom);
    setMenuBar(menuBar);
    loadResources(resources);
  }
  /**
   * 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);
    }
  }
Example #3
0
  /** _more_ */
  protected void createChart() {

    if (madeChart) {
      return;
    }
    madeChart = true;
    final JCheckBox chartDiffCbx = new JCheckBox("Use Difference", chartDifference);
    chartDiffCbx.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            chartDifference = chartDiffCbx.isSelected();
            updateChart();
          }
        });

    chartTimeBox = new JList();
    chartTimeBox.setVisibleRowCount(3);
    chartTimeBox.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    chartTimeBox.addListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {
            if (ignoreChartTimeChanges) {
              return;
            }

            updateChart();
          }
        });

    List<StormParam> params = getStormTrackParams();

    Insets inset = new Insets(3, 7, 7, 0);
    List chartComps = new ArrayList();

    List<Way> ways = Misc.sort(stormDisplayState.getTrackCollection().getWayList());
    List wayComps = new ArrayList();
    for (Way way : ways) {
      final Way theWay = way;
      if (way.isObservation() && !chartWays.contains(way)) {
        chartWays.add(way);
      }
      final JCheckBox cbx = new JCheckBox(way.toString(), chartWays.contains(theWay));
      cbx.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
              if (cbx.isSelected()) {
                addChartWay(theWay);
              } else {
                removeChartWay(theWay);
              }
            }
          });
      if (!way.isObservation()) {
        wayComps.add(cbx);
      } else {
        wayComps.add(0, cbx);
      }
    }

    chartComps.add(new JLabel(stormDisplayState.getStormTrackControl().getWaysName() + ":"));
    JComponent chartWayComp = GuiUtils.vbox(wayComps);
    if (wayComps.size() > 6) {
      chartWayComp = makeScroller(chartWayComp, 100, 150);
    }
    chartComps.add(GuiUtils.inset(chartWayComp, inset));
    chartComps.add(GuiUtils.lLabel((isHourly() ? "Forecast Hour:" : "Forecast Time:")));
    JScrollPane sp = new JScrollPane(chartTimeBox);
    chartComps.add(GuiUtils.inset(sp, inset));

    List paramComps = new ArrayList();
    for (StormParam param : params) {
      //   if (param.getIsChartParam() == false) {
      //       continue;
      //   }
      final StormParam theParam = param;
      boolean useChartParam = chartParams.contains(theParam);
      final JCheckBox cbx = new JCheckBox(param.toString(), useChartParam);
      cbx.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
              if (cbx.isSelected()) {
                addChartParam(theParam);
              } else {
                removeChartParam(theParam);
              }
            }
          });
      paramComps.add(cbx);
    }
    chartComps.add(new JLabel("Parameters:"));
    JComponent paramComp = GuiUtils.vbox(paramComps);
    if (paramComps.size() > 6) {
      paramComp = makeScroller(paramComp, 100, 150);
    }
    chartComps.add(GuiUtils.inset(paramComp, inset));
    chartComps.add(chartDiffCbx);

    JButton removeBtn = GuiUtils.makeButton("Remove Chart", this, "removeChart");
    chartComps.add(GuiUtils.filler(5, 10));
    chartComps.add(removeBtn);

    //        JComponent top = GuiUtils.left(GuiUtils.hbox(
    //                                                     GuiUtils.label("Forecast Time: ",
    // chartTimeBox),
    //                                                     chartDiffCbx));
    //        top = GuiUtils.inset(top,5);
    //        chartTop.add(BorderLayout.NORTH, top);
    JComponent left = GuiUtils.doLayout(chartComps, 1, GuiUtils.WT_N, new double[] {0, 1, 0, 1, 0});
    chartLeft.add(BorderLayout.CENTER, GuiUtils.inset(left, 5));

    chartLeft.invalidate();
    chartLeft.validate();
    chartLeft.repaint();
  }