Exemple #1
0
    AccessLogPanel(PreferencesExt p) {
      super(p, true);
      logTable = new AccessLogTable(startDateField, endDateField, p, dnsCache);
      logTable.addPropertyChangeListener(
          new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent e) {
              if (e.getPropertyName().equals("UrlDump")) {
                String path = (String) e.getNewValue();
                gotoUrlDump(path);
              }
            }
          });

      AbstractAction allAction =
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              resetLogs();
            }
          };
      BAMutil.setActionProperties(allAction, "Refresh", "show All Logs", false, 'A', -1);
      BAMutil.addActionToContainer(topPanel, allAction);

      AbstractAction dnsAction =
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              showDNS();
            }
          };
      BAMutil.setActionProperties(dnsAction, "Dataset", "lookup DNS", false, 'D', -1);
      BAMutil.addActionToContainer(topPanel, dnsAction);

      add(logTable, BorderLayout.CENTER);
    }
Exemple #2
0
  private void makeActionsToolbars() {

    navToolbarAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            Boolean state = (Boolean) getValue(BAMutil.STATE);
            if (state.booleanValue()) toolPanel.add(navToolbar);
            else toolPanel.remove(navToolbar);
          }
        };
    BAMutil.setActionProperties(
        navToolbarAction, "MagnifyPlus", "show Navigate toolbar", true, 'M', 0);
    navToolbarAction.putValue(
        BAMutil.STATE, new Boolean(store.getBoolean("navToolbarAction", true)));

    moveToolbarAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            Boolean state = (Boolean) getValue(BAMutil.STATE);
            if (state.booleanValue()) toolPanel.add(moveToolbar);
            else toolPanel.remove(moveToolbar);
          }
        };
    BAMutil.setActionProperties(moveToolbarAction, "Up", "show Move toolbar", true, 'M', 0);
    moveToolbarAction.putValue(
        BAMutil.STATE, new Boolean(store.getBoolean("moveToolbarAction", true)));
  }
  private void makeDscanPanel() {
    dscanPP = new PrefPanel("dscan", null);
    int row = 0;
    dscanPP.addCheckBoxField(DSCAN_ADDSIZE, "Add File Size", false, 0, row++);
    // dscanPP.addCheckBoxField(DSCAN_ADDLATEST, "Add Latest", false, 0, row++);
    dscanPP.addTextField(DSCAN_PATH, "Path", "", 0, row++, null);
    dscanPP.addTextField(DSCAN_DIR, "Directory Location", "", 0, row++, null);
    // dscanPP.addTextField(DSCAN_FILTER, "Filter", "", 0, row++, null);

    dscanPP.addEmptyRow(row++, 2);
    dscanPP.addHeading("Time Coverage", row++);

    exampleButton = makeButton("Example filename");
    exampleButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            InvDataset leaf = findLeafDataset(dataset);
            exampleButton.setText((leaf == null) ? "ERR" : leaf.getName());
          }
        });
    dscanPP.addComponent(exampleButton, 0, row, null);

    // dscanPP.addTextField(DSCAN_TC_MATCH, "Dataset Name Match", "", 0, row++, null);
    // dscanPP.addTextField(DSCAN_TC_SUBS, "Substituton Pattern", "$1-$2-$3T$4:00:00", 0, row++,
    // null);
    // dscanPP.addTextField(DSCAN_TC_DURATOPN, "Duration", "", 0, row++, null);

    dscanPP.finish(false);

    IndependentWindow dscanWindow =
        new IndependentWindow("DatasetScan " + "options", BAMutil.getImage("thredds"), dscanPP);
    dscanWindow.setBounds(new Rectangle(150, 50, 700, 300));
  }
  public void showAtts() {
    if (ds == null) return;
    if (attTable == null) {
      // global attributes
      attTable =
          new BeanTable(AttributeBean.class, (PreferencesExt) prefs.node("AttributeBeans"), false);
      PopupMenu varPopup = new ucar.nc2.ui.widget.PopupMenu(attTable.getJTable(), "Options");
      varPopup.addAction(
          "Show Attribute",
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              AttributeBean bean = (AttributeBean) attTable.getSelectedBean();
              if (bean != null) {
                infoTA.setText(bean.att.toString());
                infoTA.gotoTop();
                infoWindow.show();
              }
            }
          });
      attWindow =
          new IndependentWindow("Global Attributes", BAMutil.getImage("netcdfUI"), attTable);
      attWindow.setBounds(
          (Rectangle) prefs.getBean("AttWindowBounds", new Rectangle(300, 100, 500, 800)));
    }

    List<AttributeBean> attlist = new ArrayList<>();
    for (Attribute att : ds.getGlobalAttributes()) {
      attlist.add(new AttributeBean(att));
    }
    attTable.setBeans(attlist);
    attWindow.show();
  }
  public DatasetViewer(PreferencesExt prefs, FileManager fileChooser) {
    this.prefs = prefs;
    this.fileChooser = fileChooser;

    // create the variable table(s)
    tablePanel = new JPanel(new BorderLayout());
    setNestedTable(0, null);

    // the tree view
    datasetTree = new DatasetTreeView();
    datasetTree.addPropertyChangeListener(
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent e) {
            setSelected((Variable) e.getNewValue());
          }
        });

    // layout
    mainSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, datasetTree, tablePanel);
    mainSplit.setDividerLocation(prefs.getInt("mainSplit", 100));

    setLayout(new BorderLayout());
    add(mainSplit, BorderLayout.CENTER);

    // the info window
    infoTA = new TextHistoryPane();
    infoWindow =
        new IndependentWindow("Variable Information", BAMutil.getImage("netcdfUI"), infoTA);
    infoWindow.setBounds(
        (Rectangle) prefs.getBean("InfoWindowBounds", new Rectangle(300, 300, 500, 300)));

    // the data Table
    dataTable = new StructureTable((PreferencesExt) prefs.node("structTable"));
    dataWindow = new IndependentWindow("Data Table", BAMutil.getImage("netcdfUI"), dataTable);
    dataWindow.setBounds(
        (Rectangle) prefs.getBean("dataWindow", new Rectangle(50, 300, 1000, 600)));

    // the ncdump Pane
    dumpPane = new NCdumpPane((PreferencesExt) prefs.node("dumpPane"));
    dumpWindow =
        new IndependentWindow("NCDump Variable Data", BAMutil.getImage("netcdfUI"), dumpPane);
    dumpWindow.setBounds(
        (Rectangle) prefs.getBean("DumpWindowBounds", new Rectangle(300, 300, 300, 200)));
  }
  public void addActions(JPanel buttPanel) {

    AbstractAction netcdfAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            String location = ds.getLocation();
            if (location == null) location = "test";
            int pos = location.lastIndexOf(".");
            if (pos > 0) location = location.substring(0, pos);

            String filename = fileChooser.chooseFilenameToSave(location + ".nc");
            if (filename == null) return;
            writeNetCDF(filename);
          }
        };
    BAMutil.setActionProperties(netcdfAction, "netcdf", "Write netCDF-3 file", false, 'S', -1);
    BAMutil.addActionToContainer(buttPanel, netcdfAction);

    AbstractAction ncstreamAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            String location = ds.getLocation();
            if (location == null) location = "test";
            int pos = location.lastIndexOf(".");
            if (pos > 0) location = location.substring(0, pos);

            String filename = fileChooser.chooseFilenameToSave(location + ".ncs");
            if (filename == null) return;
            writeNcstream(filename);
          }
        };
    BAMutil.setActionProperties(ncstreamAction, "netcdf", "Write ncstream file", false, 'S', -1);
    BAMutil.addActionToContainer(buttPanel, ncstreamAction);

    AbstractButton compareButton = BAMutil.makeButtcon("Select", "Compare to another file", false);
    compareButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            compareDataset();
          }
        });
    buttPanel.add(compareButton);

    AbstractAction attAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            showAtts();
          }
        };
    BAMutil.setActionProperties(attAction, "FontDecr", "global attributes", false, 'A', -1);
    BAMutil.addActionToContainer(buttPanel, attAction);
  }
Exemple #7
0
  public static void main(String args[]) throws HTTPException {

    // prefs storage
    try {
      String prefStore =
          ucar.util.prefs.XMLStore.makeStandardFilename(".unidata", "TdsMonitor.xml");
      store = ucar.util.prefs.XMLStore.createFromFile(prefStore, null);
      prefs = store.getPreferences();
      Debug.setStore(prefs.node("Debug"));
    } catch (IOException e) {
      System.out.println("XMLStore Creation failed " + e);
    }

    // initializations
    BAMutil.setResourcePath("/resources/nj22/ui/icons/");

    // put UI in a JFrame
    frame = new JFrame("TDS Monitor");
    ui = new TdsMonitor(prefs, frame);

    frame.setIconImage(BAMutil.getImage("netcdfUI"));
    frame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            if (!done) ui.exit();
          }
        });

    frame.getContentPane().add(ui);
    Rectangle bounds = (Rectangle) prefs.getBean(FRAME_SIZE, new Rectangle(50, 50, 800, 450));
    frame.setBounds(bounds);

    frame.pack();
    frame.setBounds(bounds);
    frame.setVisible(true);
  }
Exemple #8
0
  public GridUI(
      PreferencesExt pstore, RootPaneContainer root, FileManager fileChooser, int defaultHeight) {
    // this.topUI = topUI;
    this.store = pstore;
    this.fileChooser = fileChooser;

    try {
      choosers = new ArrayList();
      fieldChooser = new SuperComboBox(root, "field", true, null);
      choosers.add(new Chooser("field", fieldChooser, true));
      levelChooser = new SuperComboBox(root, "level", false, null);
      choosers.add(new Chooser("level", levelChooser, false));
      timeChooser = new SuperComboBox(root, "time", false, null);
      choosers.add(new Chooser("time", timeChooser, false));
      ensembleChooser = new SuperComboBox(root, "ensemble", false, null);
      choosers.add(new Chooser("ensemble", ensembleChooser, false));
      runtimeChooser = new SuperComboBox(root, "runtime", false, null);
      choosers.add(new Chooser("runtime", runtimeChooser, false));

      makeActionsDataset();
      makeActionsToolbars();

      gridTable = new GridTable("field");
      gtWindow =
          new IndependentWindow(
              "Grid Table Information", BAMutil.getImage("GDVs"), gridTable.getPanel());

      PreferencesExt dsNode = (PreferencesExt) pstore.node("DatasetTable");
      dsTable = new GeoGridTable(dsNode, true);
      dsDialog = dsTable.makeDialog(root, "NetcdfDataset Info", false);
      // dsDialog.setIconImage( BAMutil.getImage( "GDVs"));
      Rectangle bounds =
          (Rectangle) dsNode.getBean("DialogBounds", new Rectangle(50, 50, 800, 450));
      dsDialog.setBounds(bounds);

      controller = new GridController(this, store);
      makeUI(defaultHeight);
      controller.finishInit();

      // other components
      geotiffFileChooser = new FileManager(parent);
      geotiffFileChooser.setCurrentDirectory(store.get(GEOTIFF_FILECHOOSER_DEFAULTDIR, "."));

    } catch (Exception e) {
      System.out.println("UI creation failed");
      e.printStackTrace();
    }
  }
Exemple #9
0
    OpPanel(PreferencesExt prefs, boolean isAccess) {
      this.prefs = prefs;
      this.isAccess = isAccess;
      ta = new TextHistoryPane(true);
      infoWindow =
          new IndependentWindow("Details", BAMutil.getImage("netcdfUI"), new JScrollPane(ta));
      Rectangle bounds = (Rectangle) prefs.getBean(FRAME_SIZE, new Rectangle(200, 50, 500, 700));
      infoWindow.setBounds(bounds);

      topPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0));

      // which server
      serverCB = new JComboBox();
      serverCB.setModel(manage.getServersCB().getModel());
      serverCB.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              String server = (String) serverCB.getSelectedItem();
              setServer(server);
            }
          });

      // serverCB.setModel(manage.getServers().getModel());
      topPanel.add(new JLabel("server:"));
      topPanel.add(serverCB);

      // the date selectors
      startDateField = new JTextArea("                    ");
      endDateField = new JTextArea("                    ");

      topPanel.add(new JLabel("Start Date:"));
      topPanel.add(startDateField);
      topPanel.add(new JLabel("End Date:"));
      topPanel.add(endDateField);

      AbstractAction showAction =
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              showLogs();
            }
          };
      BAMutil.setActionProperties(showAction, "Import", "get logs", false, 'G', -1);
      BAMutil.addActionToContainer(topPanel, showAction);

      AbstractAction filterAction =
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              Boolean state = (Boolean) getValue(BAMutil.STATE);
              removeTestReq = state.booleanValue();
            }
          };
      BAMutil.setActionProperties(filterAction, "time", "remove test Requests", true, 'F', -1);
      BAMutil.addActionToContainer(topPanel, filterAction);

      AbstractAction filter2Action =
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              Boolean state = (Boolean) getValue(BAMutil.STATE);
              problemsOnly = state.booleanValue();
            }
          };
      BAMutil.setActionProperties(filter2Action, "time", "only show problems", true, 'F', -1);
      BAMutil.addActionToContainer(topPanel, filter2Action);

      AbstractAction infoAction =
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              Formatter f = new Formatter();
              showInfo(f);
              ta.setText(f.toString());
              infoWindow.show();
            }
          };
      BAMutil.setActionProperties(
          infoAction, "Information", "info on selected logs", false, 'I', -1);
      BAMutil.addActionToContainer(topPanel, infoAction);

      setLayout(new BorderLayout());
      add(topPanel, BorderLayout.NORTH);
    }
 public MyTreeCellRenderer() {
   structIcon = BAMutil.getIcon("Structure", true);
   dimIcon = BAMutil.getIcon("Dimension", true);
 }
Exemple #11
0
 LoopControlAction(SuperComboBox cbox) {
   this.scbox = cbox;
   BAMutil.setActionProperties(this, null, cbox.getName(), false, 0, 0);
 }
Exemple #12
0
  void addActionsToMenus(JMenu datasetMenu, JMenu configMenu, JMenu toolMenu) {
    // Info
    BAMutil.addActionToMenu(datasetMenu, showGridTableAction);
    BAMutil.addActionToMenu(datasetMenu, showDatasetInfoAction);
    BAMutil.addActionToMenu(datasetMenu, showNcMLAction);
    BAMutil.addActionToMenu(datasetMenu, showGridDatasetInfoAction);
    BAMutil.addActionToMenu(datasetMenu, showNetcdfDatasetAction);
    // BAMutil.addActionToMenu( datasetMenu, geotiffAction);
    // BAMutil.addActionToMenu( infoMenu, showNetcdfXMLAction);

    /// Configure
    JMenu toolbarMenu = new JMenu("Toolbars");
    toolbarMenu.setMnemonic('T');
    configMenu.add(toolbarMenu);
    BAMutil.addActionToMenu(toolbarMenu, navToolbarAction);
    BAMutil.addActionToMenu(toolbarMenu, moveToolbarAction);

    BAMutil.addActionToMenu(configMenu, chooseProjectionAction);
    BAMutil.addActionToMenu(configMenu, saveCurrentProjectionAction);

    /* BAMutil.addActionToMenu( configMenu, chooseColorScaleAction);
    BAMutil.addActionToMenu( configMenu, controller.dataProjectionAction);
    */

    //// tools menu
    JMenu displayMenu = new JMenu("Display control");
    displayMenu.setMnemonic('D');

    BAMutil.addActionToMenu(displayMenu, controller.showGridAction);
    BAMutil.addActionToMenu(displayMenu, controller.showContoursAction);
    BAMutil.addActionToMenu(displayMenu, controller.showContourLabelsAction);
    BAMutil.addActionToMenu(displayMenu, redrawAction);
    toolMenu.add(displayMenu);

    // Loop Control
    JMenu loopMenu = new JMenu("Loop control");
    loopMenu.setMnemonic('L');

    BAMutil.addActionToMenu(loopMenu, fieldLoopAction);
    BAMutil.addActionToMenu(loopMenu, levelLoopAction);
    BAMutil.addActionToMenu(loopMenu, timeLoopAction);
    toolMenu.add(loopMenu);

    // MinMax Control
    JMenu mmMenu = new JMenu("ColorScale min/max");
    mmMenu.setMnemonic('C');
    BAMutil.addActionToMenu(mmMenu, minmaxHorizAction);
    BAMutil.addActionToMenu(mmMenu, minmaxLogAction);
    BAMutil.addActionToMenu(mmMenu, minmaxHoldAction);
    toolMenu.add(mmMenu);

    // Zoom/Pan
    JMenu zoomMenu = new JMenu("Zoom/Pan");
    zoomMenu.setMnemonic('Z');
    panz.addActionsToMenu(zoomMenu); // items are added by NavigatedPanelToolbar
    toolMenu.add(zoomMenu);
  }
Exemple #13
0
  // actions that control the dataset
  private void makeActionsDataset() {

    // choose local dataset
    AbstractAction chooseLocalDatasetAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            String filename = fileChooser.chooseFilename();
            if (filename == null) return;

            InvDataset invDs;
            try {
              invDs = new InvDatasetImpl(filename, FeatureType.GRID, ServiceType.NETCDF);
            } catch (Exception ue) {
              JOptionPane.showMessageDialog(
                  GridUI.this, "Invalid filename = <" + filename + ">\n" + ue.getMessage());
              ue.printStackTrace();
              return;
            }
            setDataset(invDs);
          }
        };
    BAMutil.setActionProperties(
        chooseLocalDatasetAction, "FileChooser", "open Local dataset...", false, 'L', -1);

    /* saveDatasetAction = new AbstractAction() {
      public void actionPerformed(ActionEvent e) {
        String fname = controller.getDatasetName();
        if (fname != null) {
          savedDatasetList.add( fname);
          BAMutil.addActionToMenu( savedDatasetMenu, new DatasetAction( fname), 0);
        }
      }
    };
    BAMutil.setActionProperties( saveDatasetAction, null, "save dataset", false, 'S', 0);
    */

    // Configure
    chooseProjectionAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            getProjectionManager().setVisible();
          }
        };
    BAMutil.setActionProperties(
        chooseProjectionAction, null, "Projection Manager...", false, 'P', 0);

    saveCurrentProjectionAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            getProjectionManager();
            // set the bounding box
            ProjectionImpl proj = panz.getProjectionImpl().constructCopy();
            proj.setDefaultMapArea(panz.getMapArea());
            // if (debug) System.out.println(" GV save projection "+ proj);

            // projManage.setMap(renderAll.get("Map"));   LOOK!
            // projManager.saveProjection( proj);
          }
        };
    BAMutil.setActionProperties(
        saveCurrentProjectionAction, null, "save Current Projection", false, 'S', 0);

    /* chooseColorScaleAction = new AbstractAction() {
      public void actionPerformed(ActionEvent e) {
        if (null == csManager) // lazy instantiation
          makeColorScaleManager();
        csManager.show();
      }
    };
    BAMutil.setActionProperties( chooseColorScaleAction, null, "ColorScale Manager...", false, 'C', 0);

    */
    // redraw
    redrawAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            repaint();
            controller.start(true);
            controller.draw(true);
          }
        };
    BAMutil.setActionProperties(redrawAction, "alien", "RedRaw", false, 'W', 0);

    showDatasetInfoAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            if (infoWindow == null) {
              datasetInfoTA = new TextHistoryPane();
              infoWindow =
                  new IndependentWindow(
                      "Dataset Information", BAMutil.getImage("GDVs"), datasetInfoTA);
              infoWindow.setSize(700, 700);
              infoWindow.setLocation(100, 100);
            }

            datasetInfoTA.clear();
            datasetInfoTA.appendLine(controller.getDatasetInfo());
            datasetInfoTA.gotoTop();
            infoWindow.show();
          }
        };
    BAMutil.setActionProperties(
        showDatasetInfoAction, "Information", "Show info...", false, 'S', -1);

    showNcMLAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            if (ncmlWindow == null) {
              ncmlTA = new TextHistoryPane();
              ncmlWindow = new IndependentWindow("Dataset NcML", BAMutil.getImage("GDVs"), ncmlTA);
              ncmlWindow.setSize(700, 700);
              ncmlWindow.setLocation(200, 70);
            }

            ncmlTA.clear();
            // datasetInfoTA.appendLine( "GeoGrid XML for "+ controller.getDatasetName()+"\n");
            ncmlTA.appendLine(controller.getNcML());
            ncmlTA.gotoTop();
            ncmlWindow.show();
          }
        };
    BAMutil.setActionProperties(showNcMLAction, null, "Show NcML...", false, 'X', -1);

    showGridDatasetInfoAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            if (ncmlWindow == null) {
              ncmlTA = new TextHistoryPane();
              ncmlWindow = new IndependentWindow("Dataset NcML", BAMutil.getImage("GDVs"), ncmlTA);
              ncmlWindow.setSize(700, 700);
              ncmlWindow.setLocation(200, 70);
            }

            ncmlTA.clear();
            // datasetInfoTA.appendLine( "GeoGrid XML for "+ controller.getDatasetName()+"\n");
            ncmlTA.appendLine(controller.getDatasetXML());
            ncmlTA.gotoTop();
            ncmlWindow.show();
          }
        };
    BAMutil.setActionProperties(
        showGridDatasetInfoAction, null, "Show GridDataset Info XML...", false, 'X', -1);

    // show gridTable
    showGridTableAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            gtWindow.show();
          }
        };
    BAMutil.setActionProperties(showGridTableAction, "Table", "grid Table...", false, 'T', -1);

    // show netcdf dataset Table
    showNetcdfDatasetAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            NetcdfDataset netcdfDataset = controller.getNetcdfDataset();
            if (null != netcdfDataset) {
              try {
                dsTable.setDataset(netcdfDataset, null);
              } catch (IOException e1) {
                e1.printStackTrace();
                return;
              }
              dsDialog.show();
            }
          }
        };
    BAMutil.setActionProperties(
        showNetcdfDatasetAction, "netcdf", "NetcdfDataset Table Info...", false, 'D', -1);

    /* write geotiff file
    geotiffAction = new AbstractAction() {
      public void actionPerformed(ActionEvent e) {
        GeoGrid grid = controller.getCurrentField();
        ucar.ma2.Array data = controller.getCurrentHorizDataSlice();
        if ((grid == null) || (data == null)) return;

        String filename = geotiffFileChooser.chooseFilename();
        if (filename == null) return;

        GeoTiff geotiff = null;
        try {
          /* System.out.println("write to= "+filename);
          ucar.nc2.geotiff.Writer.write2D(grid, data, filename+".tfw");
          geotiff = new GeoTiff(filename); // read back in
          geotiff.read();
          System.out.println( geotiff.showInfo());
          //geotiff.testReadData();
          geotiff.close(); * /

          // write two
          ucar.nc2.geotiff.GeotiffWriter writer = new ucar.nc2.geotiff.GeotiffWriter(filename);
          writer.writeGrid(grid, data, false);
          geotiff = new GeoTiff(filename); // read back in
          geotiff.read();
          System.out.println( "*************************************");
          System.out.println( geotiff.showInfo());
          //geotiff.testReadData();
          geotiff.close();


        } catch (IOException ioe) {
          ioe.printStackTrace();

        } finally {
          try {
            if (geotiff != null) geotiff.close();
          } catch (IOException ioe) { }
        }

      }
    };
    BAMutil.setActionProperties( geotiffAction, "Geotiff", "Write Geotiff file", false, 'G', -1);
    */

    minmaxHorizAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            csDataMinMax.setSelectedItem(GridRenderer.MinMaxType.horiz);
            controller.setDataMinMaxType(GridRenderer.MinMaxType.horiz);
          }
        };
    BAMutil.setActionProperties(minmaxHorizAction, null, "Horizontal plane", false, 'H', 0);

    minmaxLogAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            csDataMinMax.setSelectedItem(GridRenderer.MinMaxType.log);
            controller.setDataMinMaxType(GridRenderer.MinMaxType.log);
          }
        };
    BAMutil.setActionProperties(minmaxLogAction, null, "log horiz plane", false, 'V', 0);

    /* minmaxVolAction =  new AbstractAction() {
      public void actionPerformed(ActionEvent e) {
        csDataMinMax.setSelectedIndex(GridRenderer.VOL_MinMaxType);
        controller.setDataMinMaxType(GridRenderer.MinMaxType.vert;
      }
    };
    BAMutil.setActionProperties( minmaxVolAction, null, "Grid volume", false, 'G', 0); */

    minmaxHoldAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            csDataMinMax.setSelectedItem(GridRenderer.MinMaxType.hold);
            controller.setDataMinMaxType(GridRenderer.MinMaxType.hold);
          }
        };
    BAMutil.setActionProperties(minmaxHoldAction, null, "Hold scale constant", false, 'C', 0);

    fieldLoopAction = new LoopControlAction(fieldChooser);
    levelLoopAction = new LoopControlAction(levelChooser);
    timeLoopAction = new LoopControlAction(timeChooser);
  }
/**
 * JTreeTableSorted adds sorting functionality to a JTreeTable. JTreeTable is a class that combines
 * a JTable with a JTree. Note that JTreeTableSorted is a JPanel, and has-a JTreeTable. It throws
 * ListSelectionEvent events when the selection changes. It throws a UIChangeEvent, property =
 * "sort" just before a sort is going to happen.
 */
public class JTreeTableSorted extends JPanel {
  // for HeaderRenderer
  private static Icon sortDownIcon = BAMutil.getIcon("SortDown", true);
  private static Icon sortUpIcon = BAMutil.getIcon("SortUp", true);
  private static Icon threadSortIcon = BAMutil.getIcon("ThreadSorted", true);
  private static Icon threadUnSortIcon = BAMutil.getIcon("ThreadUnsorted", true);

  // main stuff
  private JTreeTable table;
  private TreeTableModelSorted model;

  private ThreadHeaderRenderer threadHeaderRenderer = null;
  private int threadCol = -1;
  private TableRow selectedRow;

  private JScrollPane scrollPane;
  private PopupMenu popupMenu = null;
  private PopupAction[] acts;

  private boolean treeSort;
  private boolean useThreads;

  private ListenerManager lm;
  private ListSelectionEvent listSelectionEvent = null;

  private MouseAdapter allowSortColChangeMouseListener;
  private boolean allowSortColChange = false;

  private boolean debug = false, debugSetPath = false, debugEvent = false;

  /**
   * Constructor.
   *
   * @param m TreeTableModelSorted m
   */
  public JTreeTableSorted(TreeTableModelSorted m, boolean allowSortColChange) {

    this.model = m;
    this.useThreads = model.useThreads();
    this.treeSort = model.isTreeSort();

    // create the ui
    table = new JTreeTable(model);
    setLayout(new BorderLayout());
    scrollPane = new JScrollPane(table);
    add(scrollPane, BorderLayout.CENTER);

    // table.setSelectionMode( ListSelectionModel.SINGLE_SELECTION);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
    // table.setFont( table.getFont().deriveFont( Font.BOLD));

    // now set the header renderers
    TableColumnModel tcm = table.getColumnModel();
    int ncolwt = useThreads ? table.getColumnCount() - 1 : table.getColumnCount();
    for (int i = 0; i < ncolwt; i++) {
      TableColumn tc = tcm.getColumn(i);
      tc.setHeaderRenderer(new SortedHeaderRenderer(model.getColumnName(i), i));
    }
    if (useThreads) {
      threadCol = ncolwt;
      threadHeaderRenderer = new ThreadHeaderRenderer(threadCol);
      tcm.getColumn(threadCol).setHeaderRenderer(threadHeaderRenderer);
    }

    // popupMenu
    popupMenu = new ucar.nc2.ui.widget.PopupMenu(table.getTableHeader(), "Visible");
    int ncols = model.getColumnCount();
    acts = new PopupAction[ncols];
    for (int i = 0; i < ncols; i++) {
      acts[i] = new PopupAction(model.getColumnName(i));
      popupMenu.addActionCheckBox(model.getColumnName(i), acts[i], true);
    }

    // listen for list selection
    table
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting() && lm.hasListeners() && (listSelectionEvent == null)) {
                  listSelectionEvent = e;
                  if (debugEvent) System.out.println(" JTreeTableSorted message selected = " + e);
                  SwingUtilities.invokeLater(
                      new Runnable() { // gotta do this after the dust settles

                        public void run() {
                          lm.sendEvent(listSelectionEvent);
                          listSelectionEvent = null; // dont like this
                        }
                      }); // new Runnable
                }
              }
            }); // new ListSelectionListener

    // listen for mouse clicks on the column header
    allowSortColChangeMouseListener =
        new MyMouseAdapter() {
          public void click(MouseEvent e) {
            TableColumnModel tcm2 = table.getColumnModel();
            int colIdx = tcm2.getColumnIndexAtX(e.getX());
            int colNo = table.convertColumnIndexToModel(colIdx);

            // keep track of selection
            selectedRow = getSelectedRow();
            if (debug) System.out.println("----selectedRow = " + selectedRow);

            if (colNo == threadCol) { // toggle threads
              threadHeaderRenderer.setOn(!threadHeaderRenderer.isOn);
              model.setThreadsOn(threadHeaderRenderer.isOn);
              model.sort();
            } else {
              boolean reverse = model.sort(colNo);
              setSortCol(colNo, reverse);
            }

            table.fireDataChanged();
            invokeSetPath();
          }
        };
    allowSortColChange(allowSortColChange);

    // event manager for ListSelection
    lm =
        new ListenerManager(
            "javax.swing.event.ListSelectionListener",
            "javax.swing.event.ListSelectionEvent",
            "valueChanged");

    // default sort
    setSortCol(model.getSortCol(), model.getReverse());
  }

  /** add ListSelectionEvent listener */
  public void addListSelectionListener(ListSelectionListener l) {
    lm.addListener(l);
  }

  /** remove ListSelectionEvent listener */
  public void removeListSelectionListener(ListSelectionListener l) {
    lm.removeListener(l);
  }

  public void allowSortColChange(boolean allow) {
    JTableHeader hdr = table.getTableHeader();
    if (allow && !allowSortColChange) hdr.addMouseListener(allowSortColChangeMouseListener);
    else if (!allow && allowSortColChange) hdr.removeMouseListener(allowSortColChangeMouseListener);
    allowSortColChange = allow;
  }

  public TreeTableModelSorted getModel() {
    return model;
  }

  public JTable getTable() {
    return table;
  }

  public TableRow getRow(int row) {
    return model.getRow(table.getPathForRow(row));
  }

  /**
   * Set the state from the last saved in the PreferencesExt.
   *
   * @param store ok if null or empty
   */
  public void restoreState(PreferencesExt store) {
    if (store == null) return;

    int ncols = table.getColumnCount();

    // stored column order
    int[] modelIndex = (int[]) store.getBean("ColumnOrder", null);

    if ((modelIndex != null) && (modelIndex.length == ncols)) { // what about invisible ??

      // make invisible any not stored
      boolean[] visible = new boolean[ncols];
      for (int i = 0; i < modelIndex.length; i++)
        if (modelIndex[i] < ncols) visible[modelIndex[i]] = true;

      // modify popup menu
      for (int i = 0; i < ncols; i++)
        if (!visible[i]) {
          // System.out.println( colName[i]+" hide "+i);
          acts[i].hideColumn();
          acts[i].putValue(BAMutil.STATE, new Boolean(false));
        }

      // now set the header order
      TableColumnModel tcm = table.getColumnModel();
      int n = Math.min(modelIndex.length, table.getColumnCount());
      for (int i = 0; i < n; i++) {
        TableColumn tc = tcm.getColumn(i);
        tc.setModelIndex(modelIndex[i]);
        String name = model.getColumnName(modelIndex[i]);
        tc.setHeaderValue(name);
        tc.setIdentifier(name);
        if (useThreads && (modelIndex[i] == threadCol)) {
          threadHeaderRenderer = new ThreadHeaderRenderer(threadCol);
          tc.setHeaderRenderer(threadHeaderRenderer);
        } else tc.setHeaderRenderer(new SortedHeaderRenderer(name, modelIndex[i]));
      }
    }

    // set the column widths
    Object colWidths = store.getBean("ColumnWidths", null);
    if (colWidths == null) return;
    int[] size = (int[]) colWidths;

    if (size != null) setColumnWidths(size);
    if (debug) {
      System.out.println(" read widths = ");
      for (int i = 0; i < size.length; i++) System.out.print(" " + size[i]);
      System.out.println();
    }

    boolean isThreadsOn = store.getBoolean("isThreadsOn", false);
    if (useThreads) {
      model.setThreadsOn(isThreadsOn);
      threadHeaderRenderer.setOn(isThreadsOn);
    }

    int colNo = store.getInt("SortOnCol", 0);
    boolean reverse = store.getBoolean("SortReverse", false);
    model.setSortCol(colNo);
    model.setReverse(reverse);
    setSortCol(colNo, reverse);

    model.sort();
    table.fireDataChanged();
  }

  private void setColumnWidths(int[] sizes) {
    TableColumnModel tcm = table.getColumnModel();
    for (int i = 0; i < table.getColumnCount(); i++) {
      TableColumn tc = tcm.getColumn(i);
      int maxw = ((sizes == null) || (i >= sizes.length)) ? 10 : sizes[i];
      //     model.getPreferredWidthForColumn(tc) : sizes[i];
      tc.setPreferredWidth(maxw);
    }
    // table.sizeColumnsToFit(0);     //  must be called due to a JTable bug
  }

  public void setColOn(int colno, boolean state, int pos) {
    // System.out.println("setColOn "+colno+" "+state+" "+pos);
    acts[colno].putValue(BAMutil.STATE, new Boolean(state));
    if (state) acts[colno].addAtPos(pos);
    else acts[colno].hideColumn();
  }

  public void registerKeyboardAction(ActionListener act, KeyStroke key, int when) {
    table.registerKeyboardAction(act, key, when);
  }

  public void setFontSize(int size) {
    table.setFont(table.getFont().deriveFont((float) size));
  }

  /** Save state to the PreferencesExt. */
  public void saveState(PreferencesExt store) {
    if (store == null) return;

    int ncols = table.getColumnCount();
    int[] size = new int[ncols];
    int[] modelIndex = new int[ncols];

    TableColumnModel tcm = table.getColumnModel();
    for (int i = 0; i < ncols; i++) {
      TableColumn tc = tcm.getColumn(i);
      size[i] = tc.getWidth();
      modelIndex[i] = tc.getModelIndex();
    }
    store.putBeanObject("ColumnWidths", size);
    store.putBeanObject("ColumnOrder", modelIndex);

    store.putInt("SortOnCol", model.getSortCol());
    store.putBoolean("SortReverse", model.getReverse());
    store.putBoolean("isThreadsOn", model.isThreadsOn());

    if (debug) {
      System.out.println(" store widths = ");
      for (int i = 0; i < size.length; i++) System.out.print(" " + size[i]);
      System.out.println();
    }
  }

  public ArrayList getRows() {
    return model.getRows();
  }

  /**
   * Replace the rowList with this one.
   *
   * @param rows list of rows
   */
  public void setRows(ArrayList rows) {
    model.setRows(rows);

    /*    if (rowList.size() > 0)
      table.setRowSelectionInterval(0, 0);
    else
      table.clearSelection(); */

    // table.clearSelection();
    table.fireDataChanged();
  }

  /**
   * Remove elem from rowList, update the table. Searches for match using object identity (==)
   *
   * @param Object elem
   *     <p>public void removeRow ( Object elem) { Iterator iter = rowList.iterator(); while
   *     (iter.hasNext()) { Object row = iter.next(); if (row == elem) { iter.remove(); break; } }
   *     table.revalidate(); }
   */

  // public int getRowCount() { return table.getRowCount(); }
  // int getSelectedRowIndex() { return table.getSelectedRow(); }   // for SuperComboBox
  // void setSortOK(boolean sortOK) { this.sortOK = sortOK; }       // for SuperComboBox

  /**
   * Get the currently selected row.
   *
   * @return selected TableRow
   */
  public TableRow getSelectedRow() {
    return model.getRow(table.getSelectionPath());
  }

  /**
   * Get the currently selected rows.
   *
   * @return an Iterator whose objects are TableRow
   */
  public Iterator getSelectedRows() {
    TreePath[] paths = table.getSelectionPaths();
    if ((paths == null) || (paths.length < 1)) return null;

    HashSet set = new HashSet(2 * paths.length);
    for (int i = 0; i < paths.length; i++) {
      model.addRowsToSetFromPath(table.getTree(), paths[i], set);
    }

    return set.iterator();
  }

  /**
   * Set the current selection to this row.
   *
   * @param rowno index into rowList
   */
  public void setSelectedRow(int rowno) {
    if ((rowno < 0) || (rowno >= model.getRowCount())) return;
    if (debugSetPath) System.out.println("TreeTableSorted setSelected " + rowno);

    selectedRow = model.getRow(rowno);
    TreePath path = model.getPath(selectedRow);
    if (path != null) table.setSelectionPath(path);

    // for mysterious reasons, gotta do it again later
    invokeSetPath();
    ensureRowIsVisible(rowno);
  }

  private void invokeSetPath() {
    // gotta do this after the dust settles
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            TreePath path = model.getPath(selectedRow);
            if (path != null) {
              int rowno = table.setSelectionPath(path);
              if (rowno >= 0) ensureRowIsVisible(rowno);
              if (debugSetPath) System.out.println("----reset selectedRow = " + rowno + " " + path);
            }
          }
        });
  }

  /**
   * Increment or decrement the current selection by one row.
   *
   * @param increment true=increment, false=decrement
   */
  public void incrSelected(boolean increment) {
    int rowno = table.incrSelected(increment);
    if (rowno > 0) ensureRowIsVisible(rowno);
  }

  // Get the JTable delegate so you can do nasty things to it

  public void setDefaultRenderer(Class columnClass, TableCellRenderer renderer) {
    table.setDefaultRenderer(columnClass, renderer);
  }

  /** this array translates the column index to the model index */
  public int[] getModelIndex() {
    int[] modelIndex = new int[model.getColumnCount()];

    try {
      TableColumnModel tcm = table.getColumnModel();
      for (int i = 0; i < model.getColumnCount(); i++) {
        TableColumn tc = tcm.getColumn(i);
        modelIndex[i] = tc.getModelIndex();
      }
    } catch (java.lang.ArrayIndexOutOfBoundsException e) {
      // can happen when model size increases
    }

    return modelIndex;
  }

  /////////////////////////////////////////////////////////////////////////////////

  private void ensureRowIsVisible(int nRow) {
    Rectangle visibleRect = table.getCellRect(nRow, 0, true);
    if (debugSetPath) System.out.println("----ensureRowIsVisible = " + visibleRect);
    if (visibleRect != null) {
      visibleRect.x = scrollPane.getViewport().getViewPosition().x;
      table.scrollRectToVisible(visibleRect);
      table.repaint();
    }
  }

  public void setSortCol(int sortCol, boolean reverse) {
    TableColumnModel tcm = table.getColumnModel();
    for (int i = 0; i < table.getColumnCount(); i++) {
      TableColumn tc = tcm.getColumn(i);
      SortedHeaderRenderer shr = (SortedHeaderRenderer) tc.getHeaderRenderer();
      shr.setSortCol(sortCol, reverse);
    }
  }

  private class PopupAction extends AbstractAction {
    private String id;
    private TableColumn tc = null;

    PopupAction(String id) {
      this.id = id;
    }

    public void actionPerformed(ActionEvent e) {
      boolean state = ((Boolean) getValue(BAMutil.STATE)).booleanValue();
      TableColumnModel tcm = table.getColumnModel();

      if (state) {
        if (tc != null) tcm.addColumn(tc);
      } else hideColumn();

      JTreeTableSorted.this.revalidate();
      // System.out.println(id+" "+state);
    }

    public void addAtPos(int pos) {
      if (tc == null) return;

      TableColumnModel tcm = table.getColumnModel();

      // make sure it doesnt already exist
      try {
        tcm.addColumn(tc);
        int idx = tcm.getColumnIndex(id);
        tcm.moveColumn(idx, 0);
      } catch (Exception e) {
        System.out.println("addAtPos failed" + e);
      }
    }

    public void hideColumn() {
      // System.out.println("hideColumn "+id);
      TableColumnModel tcm = table.getColumnModel();
      try {
        int idx = tcm.getColumnIndex(id);
        tc = tcm.getColumn(idx);
        tcm.removeColumn(tc);
      } catch (Exception e) {
        // System.out.println("hideColumn didnt find"+id);
      }
    }
  }

  private class SortedHeaderRenderer implements TableCellRenderer {
    int modelCol;
    Component comp;

    JPanel compPanel;
    JLabel upLabel, downLabel;
    boolean hasSortIndicator = false;
    boolean reverse = false;

    protected SortedHeaderRenderer(int modelCol) {
      this.modelCol = modelCol;
    }

    SortedHeaderRenderer(String name, int modelCol) {
      this.modelCol = modelCol;
      upLabel = new JLabel(sortUpIcon);
      downLabel = new JLabel(sortDownIcon);

      compPanel = new JPanel(new BorderLayout());
      compPanel.setBorder(new BevelBorder(BevelBorder.RAISED));
      compPanel.add(new JLabel(name), BorderLayout.CENTER);
      comp = compPanel;
    }

    void setSortCol(int sortCol, boolean reverse) {
      if (sortCol == modelCol) {

        if (!hasSortIndicator) compPanel.add(reverse ? upLabel : downLabel, BorderLayout.EAST);
        else if (reverse != this.reverse) {
          compPanel.remove(1);
          compPanel.add(reverse ? upLabel : downLabel, BorderLayout.EAST);
        }

        this.reverse = reverse;
        hasSortIndicator = true;

        // System.out.println("setSortCol on "+modelCol+" "+sortCol+" "+reverse);
      } else if (hasSortIndicator) {
        compPanel.remove(1);
        hasSortIndicator = false;
        // System.out.println("setSortCol off "+modelCol+" "+sortCol+" "+reverse);
      }
    }

    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

      return comp;
    }
  }

  private class ThreadHeaderRenderer extends SortedHeaderRenderer {
    JLabel threadHead;
    JPanel sort, unsort;
    boolean isOn = false;

    ThreadHeaderRenderer(int modelCol) {
      super(modelCol);

      sort = new JPanel(new BorderLayout());
      sort.setBorder(new BevelBorder(BevelBorder.RAISED));
      sort.add(new JLabel(threadSortIcon), BorderLayout.CENTER);

      unsort = new JPanel(new BorderLayout());
      unsort.setBorder(new BevelBorder(BevelBorder.RAISED));
      unsort.add(new JLabel(threadUnSortIcon), BorderLayout.CENTER);

      comp = unsort;
    }

    void setOn(boolean setOn) {
      isOn = setOn;
      comp = (isOn) ? sort : unsort;
    }

    void setSortCol(int sortCol, boolean reverse) {}
  }
}
Exemple #15
0
  private void makeUI(int defaultHeight) {

    datasetNameLabel = new JLabel();
    /* gridPP = new PrefPanel("GridView", (PreferencesExt) store.node("GridViewPrefs"));
    gridUrlIF = gridPP.addTextComboField("url", "Gridded Data URL", null, 10, false);
    gridPP.addButton( BAMutil.makeButtconFromAction( chooseLocalDatasetAction ));
    gridPP.finish(true, BorderLayout.EAST);
    gridPP.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        InvDatasetImpl ds = new InvDatasetImpl( gridUrlIF.getText(), thredds.catalog.DataType.GRID, ServiceType.NETCDF);
        setDataset( ds);
      }
    }); */

    // top tool panel
    toolPanel = new JPanel();
    toolPanel.setBorder(new EtchedBorder());
    toolPanel.setLayout(new MFlowLayout(FlowLayout.LEFT, 0, 0));

    // menus
    JMenu dataMenu = new JMenu("Dataset");
    dataMenu.setMnemonic('D');
    configMenu = new JMenu("Configure");
    configMenu.setMnemonic('C');
    JMenu toolMenu = new JMenu("Controls");
    toolMenu.setMnemonic('T');
    addActionsToMenus(dataMenu, configMenu, toolMenu);
    JMenuBar menuBar = new JMenuBar();
    menuBar.add(dataMenu);
    menuBar.add(configMenu);
    menuBar.add(toolMenu);
    toolPanel.add(menuBar);

    // field choosers
    fieldPanel = new JPanel();
    fieldPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
    toolPanel.add(fieldPanel);

    // stride
    toolPanel.add(controller.strideSpinner);

    // buttcons
    BAMutil.addActionToContainer(toolPanel, controller.drawHorizAction);
    BAMutil.addActionToContainer(toolPanel, controller.drawVertAction);
    mapBeanMenu = MapBean.makeMapSelectButton();
    toolPanel.add(mapBeanMenu.getParentComponent());

    // the Navigated panel and its toolbars
    panz.setLayout(new FlowLayout());
    navToolbar = panz.getNavToolBar();
    moveToolbar = panz.getMoveToolBar();
    if (((Boolean) navToolbarAction.getValue(BAMutil.STATE)).booleanValue())
      toolPanel.add(navToolbar);
    if (((Boolean) moveToolbarAction.getValue(BAMutil.STATE)).booleanValue())
      toolPanel.add(moveToolbar);

    BAMutil.addActionToContainer(toolPanel, panz.setReferenceAction);
    BAMutil.addActionToContainer(toolPanel, controller.dataProjectionAction);
    BAMutil.addActionToContainer(toolPanel, controller.showGridAction);
    BAMutil.addActionToContainer(toolPanel, controller.showContoursAction);
    BAMutil.addActionToContainer(toolPanel, controller.showContourLabelsAction);

    BAMutil.addActionToContainer(toolPanel, redrawAction);

    //  vertical split
    vertPanel = new VertPanel();
    splitDraw = new JSplitPane(JSplitPane.VERTICAL_SPLIT, panz, vertPanel);
    int divLoc = store.getInt("vertSplit", 2 * defaultHeight / 3);
    splitDraw.setDividerLocation(divLoc);
    drawingPanel = new JPanel(new BorderLayout()); // filled later

    // status panel
    JPanel statusPanel = new JPanel(new BorderLayout());
    statusPanel.setBorder(new EtchedBorder());
    positionLabel = new JLabel("position");
    positionLabel.setToolTipText("position at cursor");
    dataValueLabel = new JLabel("data value", SwingConstants.CENTER);
    dataValueLabel.setToolTipText("data value (double click on grid)");
    statusPanel.add(positionLabel, BorderLayout.WEST);
    statusPanel.add(dataValueLabel, BorderLayout.CENTER);
    panz.setPositionLabel(positionLabel);

    // colorscale panel
    colorScalePanel = new ColorScale.Panel(this, controller.getColorScale());
    csDataMinMax = new JComboBox(GridRenderer.MinMaxType.values());
    csDataMinMax.setToolTipText("ColorScale Min/Max setting");
    csDataMinMax.addActionListener(
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            controller.setDataMinMaxType((GridRenderer.MinMaxType) csDataMinMax.getSelectedItem());
          }
        });
    JPanel westPanel = new JPanel(new BorderLayout());
    westPanel.add(colorScalePanel, BorderLayout.CENTER);
    westPanel.add(csDataMinMax, BorderLayout.NORTH);

    // lay it out
    JPanel northPanel = new JPanel();
    // northPanel.setLayout( new BoxLayout(northPanel, BoxLayout.Y_AXIS));
    northPanel.setLayout(new BorderLayout());
    northPanel.add(datasetNameLabel, BorderLayout.NORTH);
    northPanel.add(toolPanel, BorderLayout.SOUTH);

    setLayout(new BorderLayout());
    add(northPanel, BorderLayout.NORTH);
    add(statusPanel, BorderLayout.SOUTH);
    add(westPanel, BorderLayout.WEST);
    add(drawingPanel, BorderLayout.CENTER);

    setDrawHorizAndVert(controller.drawHorizOn, controller.drawVertOn);
  }
  public CoordSysTable(PreferencesExt prefs, JPanel buttPanel) {
    this.prefs = prefs;

    if (buttPanel != null) {
      AbstractAction attAction =
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              showAtts();
            }
          };
      BAMutil.setActionProperties(attAction, "FontDecr", "global attributes", false, 'A', -1);
      BAMutil.addActionToContainer(buttPanel, attAction);
    }

    varTable =
        new BeanTable(VariableBean.class, (PreferencesExt) prefs.node("VariableBeans"), false);
    varTable.addListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {
            VariableBean vb = (VariableBean) varTable.getSelectedBean();
            if (null != vb.firstCoordSys) setSelectedCoordinateSystem(vb.firstCoordSys);
          }
        });

    csTable =
        new BeanTable(
            CoordinateSystemBean.class, (PreferencesExt) prefs.node("CoordinateSystemBean"), false);
    csTable.addListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {
            CoordinateSystemBean csb = (CoordinateSystemBean) csTable.getSelectedBean();
            setSelectedCoordinateAxes(csb.coordSys);
          }
        });

    axisTable =
        new BeanTable(AxisBean.class, (PreferencesExt) prefs.node("CoordinateAxisBean"), false);

    ucar.nc2.ui.widget.PopupMenu varPopup = new PopupMenu(varTable.getJTable(), "Options");
    varPopup.addAction(
        "Show Declaration",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            VariableBean vb = (VariableBean) varTable.getSelectedBean();
            Variable v = ds.findVariable(vb.getName());
            if (v == null) return;
            infoTA.clear();
            infoTA.appendLine(v.toString());
            infoTA.appendLine(showMissing(v));
            infoTA.gotoTop();
            infoWindow.show();
          }
        });

    varPopup.addAction(
        "Try as Grid",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            VariableBean vb = (VariableBean) varTable.getSelectedBean();
            VariableEnhanced v = (VariableEnhanced) ds.findVariable(vb.getName());
            if (v == null) return;
            infoTA.clear();
            infoTA.appendLine(tryGrid(v));
            infoTA.gotoTop();
            infoWindow.show();
          }
        });

    PopupMenu csPopup = new PopupMenu(csTable.getJTable(), "Options");
    csPopup.addAction(
        "Show CoordSys",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            CoordinateSystemBean csb = (CoordinateSystemBean) csTable.getSelectedBean();
            CoordinateSystem coordSys = csb.coordSys;
            infoTA.clear();
            infoTA.appendLine("Coordinate System = " + coordSys.getName());
            for (CoordinateAxis axis : coordSys.getCoordinateAxes()) {
              infoTA.appendLine("  " + axis.getAxisType() + " " + axis.writeCDL(true, false));
            }
            infoTA.appendLine(" Coordinate Transforms");
            for (CoordinateTransform ct : coordSys.getCoordinateTransforms()) {
              infoTA.appendLine("  " + ct.getName() + " type=" + ct.getTransformType());
              for (Parameter p : ct.getParameters()) {
                infoTA.appendLine("    " + p);
              }
              if (ct instanceof ProjectionCT) {
                ProjectionCT pct = (ProjectionCT) ct;
                if (pct.getProjection() != null) {
                  infoTA.appendLine("    impl.class= " + pct.getProjection().getClass().getName());
                  // pct.getProjection();
                }
              }
              if (ct instanceof VerticalCT) {
                VerticalCT vct = (VerticalCT) ct;
                infoTA.appendLine("  VerticalCT= " + vct);
              }
            }
            infoTA.gotoTop();
            infoWindow.show();
          }
        });

    PopupMenu axisPopup = new PopupMenu(axisTable.getJTable(), "Options");
    axisPopup.addAction(
        "Show Declaration",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            AxisBean bean = (AxisBean) axisTable.getSelectedBean();
            if (bean == null) return;
            VariableDS axis = (VariableDS) ds.findVariable(bean.getName());
            if (axis == null) return;
            infoTA.clear();
            infoTA.appendLine(axis.toString());
            infoTA.appendLine(showMissing(axis));
            infoTA.gotoTop();
            infoWindow.show();
          }
        });

    axisPopup.addAction(
        "Show Values",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            AxisBean bean = (AxisBean) axisTable.getSelectedBean();
            if (bean == null) return;
            infoTA.clear();
            showValues(bean.axis);
            infoTA.gotoTop();
            infoWindow.show();
          }
        });
    axisPopup.addAction(
        "Show Value Differences",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            AxisBean bean = (AxisBean) axisTable.getSelectedBean();
            if (bean == null) return;
            infoTA.clear();
            showValueDiffs(bean.axis);
            infoTA.gotoTop();
            infoWindow.show();
          }
        });

    axisPopup.addAction(
        "Show Values as Date",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            AxisBean bean = (AxisBean) axisTable.getSelectedBean();
            if (bean == null) return;
            infoTA.clear();
            showValuesAsDates(bean.axis);
            infoTA.gotoTop();
            infoWindow.show();
          }
        });

    // the info window
    infoTA = new TextHistoryPane();
    infoWindow = new IndependentWindow("Extra Information", BAMutil.getImage("netcdfUI"), infoTA);
    infoWindow.setBounds(
        (Rectangle) prefs.getBean("InfoWindowBounds", new Rectangle(300, 300, 500, 300)));

    split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, false, varTable, csTable);
    split.setDividerLocation(prefs.getInt("splitPos", 500));

    split2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, false, split, axisTable);
    split2.setDividerLocation(prefs.getInt("splitPos2", 500));

    setLayout(new BorderLayout());
    add(split2, BorderLayout.CENTER);
  }
Exemple #17
0
  public NcmlEditor(JPanel buttPanel, PreferencesExt prefs) {
    this.prefs = prefs;
    fileChooser = new FileManager(null, null, null, (PreferencesExt) prefs.node("FileManager"));

    AbstractAction coordAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            addCoords = (Boolean) getValue(BAMutil.STATE);
            String tooltip = addCoords ? "add Coordinates is ON" : "add Coordinates is OFF";
            coordButt.setToolTipText(tooltip);
          }
        };
    addCoords = prefs.getBoolean("coordState", false);
    String tooltip2 = addCoords ? "add Coordinates is ON" : "add Coordinates is OFF";
    BAMutil.setActionProperties(coordAction, "addCoords", tooltip2, true, 'C', -1);
    coordAction.putValue(BAMutil.STATE, Boolean.valueOf(addCoords));
    coordButt = BAMutil.addActionToContainer(buttPanel, coordAction);

    protoChooser = new ComboBox((PreferencesExt) prefs.node("protoChooser"));
    addProtoChoices();
    buttPanel.add(protoChooser);
    protoChooser.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String ptype = (String) protoChooser.getSelectedItem();
            String proto = protoMap.get(ptype);
            if (proto != null) {
              editor.setText(proto);
            }
          }
        });

    editor = new JEditorPane();

    // Instantiate a XMLEditorKit with wrapping enabled.
    XMLEditorKit kit = new XMLEditorKit(false);

    // Set the wrapping style.
    kit.setWrapStyleWord(true);

    editor.setEditorKit(kit);

    // Set the font style.
    editor.setFont(new Font("Monospaced", Font.PLAIN, 12));

    // Set the tab size
    editor.getDocument().putProperty(PlainDocument.tabSizeAttribute, 2);

    // Enable auto indentation.
    editor.getDocument().putProperty(XMLDocument.AUTO_INDENTATION_ATTRIBUTE, true);

    // Enable tag completion.
    editor.getDocument().putProperty(XMLDocument.TAG_COMPLETION_ATTRIBUTE, true);

    // Initialise the folding
    kit.setFolding(true);

    // Set a style
    kit.setStyle(XMLStyleConstants.ATTRIBUTE_NAME, Color.RED, Font.BOLD);

    // Put the editor in a panel that will force it to resize, when a different view is choosen.
    ScrollableEditorPanel editorPanel = new ScrollableEditorPanel(editor);

    JScrollPane scroller = new JScrollPane(editorPanel);

    // Add the number margin as a Row Header View
    scroller.setRowHeaderView(new LineNumberMargin(editor));

    AbstractAction wrapAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            XMLEditorKit kit = (XMLEditorKit) editor.getEditorKit();
            kit.setLineWrappingEnabled(!kit.isLineWrapping());
            editor.updateUI();
          }
        };
    BAMutil.setActionProperties(wrapAction, "Wrap", "Toggle Wrapping", false, 'W', -1);
    BAMutil.addActionToContainer(buttPanel, wrapAction);

    AbstractAction saveAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            String location = (ds == null) ? ncmlLocation : ds.getLocation();
            if (location == null) location = "test";
            int pos = location.lastIndexOf(".");
            if (pos > 0) location = location.substring(0, pos);
            String filename = fileChooser.chooseFilenameToSave(location + ".ncml");
            if (filename == null) return;
            if (doSaveNcml(editor.getText(), filename)) ncmlLocation = filename;
          }
        };
    BAMutil.setActionProperties(saveAction, "Save", "Save NcML", false, 'S', -1);
    BAMutil.addActionToContainer(buttPanel, saveAction);

    AbstractAction netcdfAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            if (outChooser == null) {
              outChooser = new NetcdfOutputChooser((Frame) null);
              outChooser.addPropertyChangeListener(
                  "OK",
                  new PropertyChangeListener() {
                    public void propertyChange(PropertyChangeEvent evt) {
                      writeNetcdf((NetcdfOutputChooser.Data) evt.getNewValue());
                    }
                  });
            }

            String location = (ds == null) ? ncmlLocation : ds.getLocation();
            if (location == null) location = "test";
            int pos = location.lastIndexOf(".");
            if (pos > 0) location = location.substring(0, pos);

            outChooser.setOutputFilename(location);
            outChooser.setVisible(true);
          }
        };
    BAMutil.setActionProperties(netcdfAction, "netcdf", "Write netCDF file", false, 'N', -1);
    BAMutil.addActionToContainer(buttPanel, netcdfAction);

    AbstractAction transAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            doTransform(editor.getText());
          }
        };
    BAMutil.setActionProperties(
        transAction,
        "Import",
        "read textArea through NcMLReader\n write NcML back out via resulting dataset",
        false,
        'T',
        -1);
    BAMutil.addActionToContainer(buttPanel, transAction);

    AbstractButton compareButton = BAMutil.makeButtcon("Select", "Check NcML", false);
    compareButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            Formatter f = new Formatter();
            checkNcml(f);

            infoTA.setText(f.toString());
            infoTA.gotoTop();
            infoWindow.show();
          }
        });
    buttPanel.add(compareButton);

    setLayout(new BorderLayout());
    add(scroller, BorderLayout.CENTER);

    // the info window
    infoTA = new TextHistoryPane();
    infoWindow = new IndependentWindow("Extra Information", BAMutil.getImage("netcdfUI"), infoTA);
    infoWindow.setBounds(
        (Rectangle) prefs.getBean("InfoWindowBounds", new Rectangle(300, 300, 500, 300)));
  }