Пример #1
0
  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 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);
  }
Пример #3
0
  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);
  }
Пример #4
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);
  }
Пример #5
0
  /**
   * 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();
  }
Пример #6
0
    NestedTable(int level) {
      this.level = level;
      myPrefs = (PreferencesExt) prefs.node("NestedTable" + level);

      table = new BeanTableSorted(VariableBean.class, myPrefs, false);

      JTable jtable = table.getJTable();
      PopupMenu csPopup = new PopupMenu(jtable, "Options");
      csPopup.addAction(
          "Show Declaration",
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              showDeclaration(table, false);
            }
          });
      csPopup.addAction(
          "Show NcML",
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              showDeclaration(table, true);
            }
          });
      csPopup.addAction(
          "NCdump Data",
          "Dump",
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              dumpData(table);
            }
          });
      if (level == 0) {
        csPopup.addAction(
            "Data Table",
            new AbstractAction() {
              public void actionPerformed(ActionEvent e) {
                dataTable(table);
              }
            });
      }

      // get selected variable, see if its a structure
      table.addListSelectionListener(
          new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
              Variable v = getCurrentVariable(table);
              if ((v != null) && (v instanceof Structure)) {
                hideNestedTable(NestedTable.this.level + 2);
                setNestedTable(NestedTable.this.level + 1, (Structure) v);

              } else {
                hideNestedTable(NestedTable.this.level + 1);
              }
              if (eventsOK) datasetTree.setSelected(v);
            }
          });

      // layout
      if (currentComponent == null) {
        currentComponent = table;
        tablePanel.add(currentComponent, BorderLayout.CENTER);
        isShowing = true;

      } else {
        split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, false, currentComponent, table);
        splitPos = myPrefs.getInt("splitPos" + level, 500);
        if (splitPos > 0) split.setDividerLocation(splitPos);

        show();
      }
    }