Beispiel #1
0
  // enable all menu items/menus for operations that require
  // a Gist to work on, excluding the debugging functions
  private void enableIndexOpened() {
    DbgOutput.println(1, "enableIndexOpened()");
    setAllEnabled(true);
    // debugging operations only during operations
    stepAction.setEnabled(false);
    stopAction.setEnabled(false);
    cancelAction.setEnabled(false);
    nextAction.setEnabled(false);
    contAction.setEnabled(false);

    // no profile opened
    completeAnalysisItem.setEnabled(false);
    wkldStatsItem.setEnabled(false);
    splitStatsItem.setEnabled(false);
    penaltyStatsItem.setEnabled(false);
  }
Beispiel #2
0
  // enable/disable all menu items/actions
  private void setAllEnabled(boolean enabled) {
    DbgOutput.println(2, "enabled: " + enabled);
    fileMenu.setEnabled(enabled);
    newItem.setEnabled(enabled);
    openItem.setEnabled(enabled);
    closeItem.setEnabled(enabled);
    // dumpItem.setEnabled(enabled);
    flushItem.setEnabled(enabled);
    optionsItem.setEnabled(enabled);
    settingsItem.setEnabled(enabled);

    debugMenu.setEnabled(enabled);
    stepAction.setEnabled(enabled);
    stopAction.setEnabled(enabled);
    cancelAction.setEnabled(enabled);
    nextAction.setEnabled(enabled);
    contAction.setEnabled(enabled);
    breakpointsItem.setEnabled(enabled);

    opsMenu.setEnabled(enabled);
    insertItem.setEnabled(enabled);
    deleteItem.setEnabled(enabled);
    searchItem.setEnabled(enabled);
    executeItem.setEnabled(enabled);

    treeStatsMenu.setEnabled(enabled);
    utilItem.setEnabled(enabled);
    predSzItem.setEnabled(enabled);
    slotCntItem.setEnabled(enabled);

    analysisMenu.setEnabled(enabled);
    newAnalysisItem.setEnabled(enabled);
    openAnalysisItem.setEnabled(enabled);
    completeAnalysisItem.setEnabled(enabled);
    wkldStatsItem.setEnabled(enabled);
    splitStatsItem.setEnabled(enabled);
    penaltyStatsItem.setEnabled(enabled);

    // these are never disabled
    windowsMenu.setEnabled(true);
    showCmdsItem.setEnabled(true);
    showResultsItem.setEnabled(true);
    showTraceItem.setEnabled(true);
    tileItem.setEnabled(true);
  }
Beispiel #3
0
 // set all menu items related to debugging enabled, all else disabled;
 // for insert, remove and fetch: continue, step
 // additionally for scripts: next and sometimes cancel
 private void enableDebug(boolean isScript, boolean enableCancel) {
   setAllEnabled(false);
   debugMenu.setEnabled(true);
   stepAction.setEnabled(true);
   cancelAction.setEnabled(enableCancel);
   nextAction.setEnabled(isScript);
   contAction.setEnabled(true);
   breakpointsItem.setEnabled(true);
   treeStatsMenu.setEnabled(true);
   utilItem.setEnabled(true);
   predSzItem.setEnabled(true);
   slotCntItem.setEnabled(true);
 }
  public BufrMessageViewer(final PreferencesExt prefs, JPanel buttPanel) {
    this.prefs = prefs;

    AbstractAction useReaderAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            Boolean state = (Boolean) getValue(BAMutil.STATE);
            doRead = state.booleanValue();
          }
        };
    BAMutil.setActionProperties(useReaderAction, "addCoords", "read data", true, 'C', -1);
    useReaderAction.putValue(BAMutil.STATE, new Boolean(doRead));
    BAMutil.addActionToContainer(buttPanel, useReaderAction);

    AbstractAction seperateWindowAction =
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            Boolean state = (Boolean) getValue(BAMutil.STATE);
            seperateWindow = state.booleanValue();
          }
        };
    BAMutil.setActionProperties(
        seperateWindowAction, "addCoords", "seperate DDS window", true, 'C', -1);
    seperateWindowAction.putValue(BAMutil.STATE, new Boolean(seperateWindow));
    BAMutil.addActionToContainer(buttPanel, seperateWindowAction);

    messageTable =
        new BeanTableSorted(
            MessageBean.class, (PreferencesExt) prefs.node("GridRecordBean"), false);
    messageTable.addListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {
            ddsTable.setBeans(new ArrayList());
            obsTable.setBeans(new ArrayList());

            MessageBean mb = (MessageBean) messageTable.getSelectedBean();
            java.util.List<DdsBean> beanList = new ArrayList<DdsBean>();
            try {
              setDataDescriptors(beanList, mb.m.getRootDataDescriptor(), 0);
              setObs(mb.m);
            } catch (IOException e1) {
              JOptionPane.showMessageDialog(BufrMessageViewer.this, e1.getMessage());
              e1
                  .printStackTrace(); // To change body of catch statement use File | Settings |
                                      // File Templates.
            }
            ddsTable.setBeans(beanList);
          }
        });

    obsTable = new BeanTableSorted(ObsBean.class, (PreferencesExt) prefs.node("ObsBean"), false);
    obsTable.addListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {
            ObsBean csb = (ObsBean) obsTable.getSelectedBean();
          }
        });

    ddsTable = new BeanTableSorted(DdsBean.class, (PreferencesExt) prefs.node("DdsBean"), false);
    ddsTable.addListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent e) {
            DdsBean csb = (DdsBean) ddsTable.getSelectedBean();
          }
        });

    thredds.ui.PopupMenu varPopup = new thredds.ui.PopupMenu(messageTable.getJTable(), "Options");
    varPopup.addAction(
        "Show DDS",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            MessageBean vb = (MessageBean) messageTable.getSelectedBean();
            if (!seperateWindow) infoTA.clear();
            Formatter f = new Formatter();
            try {
              if (!vb.m.isTablesComplete()) {
                f.format(" MISSING DATA DESCRIPTORS= ");
                vb.m.showMissingFields(f);
                f.format("%n%n");
              }

              vb.m.dump(f);
            } catch (IOException e1) {
              JOptionPane.showMessageDialog(BufrMessageViewer.this, e1.getMessage());
              e1
                  .printStackTrace(); // To change body of catch statement use File | Settings |
                                      // File Templates.
            }
            if (seperateWindow) {
              TextHistoryPane ta = new TextHistoryPane();
              IndependentWindow info =
                  new IndependentWindow("Extra Information", BAMutil.getImage("netcdfUI"), ta);
              info.setBounds(
                  (Rectangle) prefs.getBean("InfoWindowBounds", new Rectangle(300, 300, 500, 300)));
              ta.appendLine(f.toString());
              ta.gotoTop();
              info.show();

            } else {
              infoTA.appendLine(f.toString());
              infoTA.gotoTop();
              infoWindow.show();
            }
          }
        });
    varPopup.addAction(
        "Data Table",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            MessageBean mb = (MessageBean) messageTable.getSelectedBean();
            try {
              NetcdfDataset ncd = getBufrMessageAsDataset(mb.m);
              Variable v = ncd.findVariable(BufrIosp.obsRecord);
              if ((v != null) && (v instanceof Structure)) {
                if (dataTable == null) makeDataTable();
                dataTable.setStructure((Structure) v);
                dataWindow.show();
              }
            } catch (Exception ex) {
              JOptionPane.showMessageDialog(BufrMessageViewer.this, ex.getMessage());
              ex.printStackTrace();
            }
          }
        });

    varPopup.addAction(
        "Bit Count",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            MessageBean mb = (MessageBean) messageTable.getSelectedBean();
            Message m = mb.m;

            Formatter out = new Formatter();
            try {
              infoTA2.clear();
              if (!m.dds.isCompressed()) {
                MessageUncompressedDataReader reader = new MessageUncompressedDataReader();
                reader.readData(null, m, raf, null, false, out);
              } else {
                MessageCompressedDataReader reader = new MessageCompressedDataReader();
                reader.readData(null, m, raf, null, out);
              }
              int nbitsGiven = 8 * (m.dataSection.getDataLength() - 4);
              DataDescriptor root = m.getRootDataDescriptor();
              out.format(
                  "Message nobs=%d compressed=%s vlen=%s countBits= %d givenBits=%d %n",
                  m.getNumberDatasets(),
                  m.dds.isCompressed(),
                  root.isVarLength(),
                  m.getCountedDataBits(),
                  nbitsGiven);
              out.format(" countBits= %d givenBits=%d %n", m.getCountedDataBits(), nbitsGiven);
              out.format(
                  " countBytes= %d dataSize=%d %n",
                  m.getCountedDataBytes(), m.dataSection.getDataLength());
              out.format("%n");
              infoTA2.appendLine(out.toString());

            } catch (Exception ex) {
              ByteArrayOutputStream bos = new ByteArrayOutputStream();
              ex.printStackTrace(new PrintStream(bos));
              infoTA2.appendLine(out.toString());
              infoTA2.appendLine(bos.toString());
            }

            infoTA2.gotoTop();
            infoWindow2.show();
          }
        });

    varPopup.addAction(
        "Write Message",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            MessageBean mb = (MessageBean) messageTable.getSelectedBean();
            try {
              String defloc;
              String header = mb.m.getHeader();
              if (header != null) {
                header = header.split(" ")[0];
              }
              if (header == null) {
                defloc = (raf.getLocation() == null) ? "." : raf.getLocation();
                int pos = defloc.lastIndexOf(".");
                if (pos > 0) defloc = defloc.substring(0, pos);
              } else defloc = header;

              if (fileChooser == null)
                fileChooser =
                    new FileManager(null, null, null, (PreferencesExt) prefs.node("FileManager"));

              String filename = fileChooser.chooseFilenameToSave(defloc + ".bufr");
              if (filename == null) return;

              File file = new File(filename);
              FileOutputStream fos = new FileOutputStream(file);
              WritableByteChannel wbc = fos.getChannel();
              wbc.write(ByteBuffer.wrap(mb.m.getHeader().getBytes()));

              byte[] raw = scan.getMessageBytes(mb.m);
              wbc.write(ByteBuffer.wrap(raw));
              wbc.close();
              JOptionPane.showMessageDialog(
                  BufrMessageViewer.this, filename + " successfully written");

            } catch (Exception ex) {
              JOptionPane.showMessageDialog(BufrMessageViewer.this, "ERROR: " + ex.getMessage());
              ex.printStackTrace();
            }
          }
        });

    varPopup.addAction(
        "Dump distinct DDS",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            dumpDDS();
          }
        });

    varPopup.addAction(
        "Write all distinct messages",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            writeAll();
          }
        });

    varPopup.addAction(
        "Show XML",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            MessageBean mb = (MessageBean) messageTable.getSelectedBean();
            Message m = mb.m;

            ByteArrayOutputStream out = new ByteArrayOutputStream(1000 * 100);
            try {
              infoTA.clear();

              NetcdfDataset ncd = getBufrMessageAsDataset(mb.m);
              new Bufr2Xml(m, ncd, out, true);
              infoTA.setText(out.toString());

            } catch (Exception ex) {
              ByteArrayOutputStream bos = new ByteArrayOutputStream();
              ex.printStackTrace(new PrintStream(bos));
              infoTA.appendLine(out.toString());
              infoTA.appendLine(bos.toString());
            }

            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)));

    // the info window 2
    infoTA2 = new TextHistoryPane();
    infoWindow2 =
        new IndependentWindow("Extra Information-2", BAMutil.getImage("netcdfUI"), infoTA2);
    infoWindow2.setBounds(
        (Rectangle) prefs.getBean("InfoWindowBounds2", new Rectangle(300, 300, 500, 300)));

    split2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, false, ddsTable, obsTable);
    split2.setDividerLocation(prefs.getInt("splitPos2", 800));

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

    setLayout(new BorderLayout());
    add(split, BorderLayout.CENTER);
  }
Beispiel #5
0
 // set all menu items except for "stop" to disabled
 private void enableStop() {
   setAllEnabled(false);
   debugMenu.setEnabled(true);
   stopAction.setEnabled(true);
 }
Beispiel #6
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)));
  }