Exemple #1
0
 /**
  * Update the query coverage component. Call this method if the effective selected table may have
  * changed.
  */
 private void updateQueryCoverage() {
   if (coverageModel_.isSelected()) {
     Coverage coverage;
     if (tcModel_ == null) {
       coverage = null;
     } else {
       int[] rowMap = tcModel_.getViewModel().getRowMap();
       ColumnData raData = raSelector_.getColumnData();
       ColumnData decData = decSelector_.getColumnData();
       ColumnData srData = srSelector_.getColumnData();
       if (raData != null && decData != null) {
         DatasQuerySequenceFactory qsf =
             new DatasQuerySequenceFactory(raData, decData, srData, rowMap);
         try {
           StarTable table = tcModel_.getApparentStarTable();
           ConeQueryRowSequence qseq = qsf.createQuerySequence(table);
           double resDeg = 1.0;
           coverage = new ConeQueryCoverage(qseq, resDeg);
         } catch (IOException e) {
           coverage = null;
         }
       } else {
         coverage = null;
       }
     }
     queryCoverageView_.setCoverage(coverage);
     updateOverlapCoverage();
   } else {
     queryCoverageView_.setCoverage(null);
   }
 }
Exemple #2
0
  /**
   * Constructs and returns a worker thread which can perform a match as specified by the current
   * state of this component.
   *
   * @return new worker thread
   * @throws RuntimeException if the current state does not fully specify a multi query job; such
   *     exceptions will have comprehensible messages
   */
  private MatchWorker createMatchWorker() {

    /* Acquire state from this panel's GUI components. */
    String sUrl = urlField_.getText();
    if (sUrl == null || sUrl.trim().length() == 0) {
      throw new IllegalArgumentException("No " + service_.getName() + " URL given");
    }
    URL serviceUrl;
    try {
      serviceUrl = new URL(sUrl);
    } catch (MalformedURLException e) {
      throw (IllegalArgumentException)
          new IllegalArgumentException("Bad " + service_.getName() + " URL syntax: " + sUrl)
              .initCause(e);
    }
    ConeErrorPolicy erract = (ConeErrorPolicy) erractSelector_.getSelectedItem();
    TopcatModel tcModel = tcModel_;
    if (tcModel == null) {
      throw new NullPointerException("No table selected");
    }
    final StarTable inTable = tcModel.getApparentStarTable();
    int[] rowMap = tcModel.getViewModel().getRowMap();
    ColumnData raData = raSelector_.getColumnData();
    ColumnData decData = decSelector_.getColumnData();
    ColumnData srData = srSelector_.getColumnData();
    if (raData == null) {
      throw new NullPointerException("No RA column given");
    }
    if (decData == null) {
      throw new NullPointerException("No Dec column given");
    }
    Number parNum = parallelModel_.getNumber();
    int parallelism = parNum == null ? 1 : parNum.intValue();
    MulticoneMode mcMode = (MulticoneMode) modeSelector_.getSelectedItem();
    StarTableFactory tfact = ControlWindow.getInstance().getTableFactory();

    /* Assemble objects based on this information. */
    ConeSearcher searcher = service_.createSearcher(serviceUrl, tfact);
    Coverage coverage = coverageModel_.isSelected() ? service_.getCoverage(serviceUrl) : null;
    DatasQuerySequenceFactory qsf = new DatasQuerySequenceFactory(raData, decData, srData, rowMap);
    ConeMatcher matcher =
        mcMode.createConeMatcher(searcher, erract, inTable, qsf, coverage, parallelism);
    ResultHandler resultHandler =
        mcMode.createResultHandler(this, tfact.getStoragePolicy(), tcModel, inTable);

    /* Create MatchWorker encapsulating all of this. */
    MatchWorker worker = new MatchWorker(matcher, resultHandler, tcModel, inTable);

    /* Perform post-construction configuration of constituent objects
     * as required. */
    qsf.setMatchWorker(worker);
    resultHandler.setMatchWorker(worker);

    /* Return worker thread. */
    return worker;
  }
Exemple #3
0
  /**
   * Sets the input table whose rows will specify the multiple queries.
   *
   * @param tcModel input table
   */
  private void setInputTable(TopcatModel tcModel) {
    if (tcModel_ != null && tcListener_ != null) {
      tcModel_.removeTopcatListener(tcListener_);
    }
    tcModel_ = tcModel;
    if (tcModel_ != null && tcListener_ != null) {
      tcModel_.addTopcatListener(tcListener_);
    }

    /* Set the column selectors up to select from the correct table. */
    raSelector_.setTable(tcModel);
    decSelector_.setTable(tcModel);

    /* For the size selector, jump through some hoops.
     * Although its value has the same form as for the RA and Dec
     * selectors (value may be a JEL expression or column name),
     * in practice it will often be a constant expression, so
     * making sure that a default constant value is in place should
     * make it more obvious for users rather than leaving it blank.
     * Check if the existing value makes sense for the new table;
     * if it does, leave it, otherwise, set it to a sensible default. */
    if (srSelector_.getModel() == null) {
      srSelector_.setTable(tcModel);
      service_.setSizeDefault(srSelector_);
    } else {
      String txt = srSelector_.getStringValue();
      Object conv = srSelector_.getModel().getConverterModel().getSelectedItem();
      srSelector_.setTable(tcModel);
      ComboBoxModel srColModel = srSelector_.getModel().getColumnModel();
      assert srColModel instanceof ColumnDataComboBoxModel;
      if (srColModel instanceof ColumnDataComboBoxModel) {
        try {
          ((ColumnDataComboBoxModel) srColModel).stringToColumnData(txt);
          srSelector_.setStringValue(txt);
          srSelector_.getModel().getConverterModel().setSelectedItem(conv);
        } catch (CompilationException e) {
          service_.setSizeDefault(srSelector_);
        }
      }
    }
  }
Exemple #4
0
  /**
   * Constructor.
   *
   * @param service defines type of service that queries will be carried out on
   */
  public DalMultiPanel(DalMultiService service, JProgressBar progBar) {
    super(new BorderLayout());
    service_ = service;
    progBar_ = progBar;
    progBar.setStringPainted(true);
    JComponent main = Box.createVerticalBox();
    List cList = new ArrayList();
    add(main);

    /* Field for service URL. */
    urlField_ = new JTextField();
    JLabel urlLabel = new JLabel(service.getName() + " URL: ");
    Box urlLine = Box.createHorizontalBox();
    cList.add(urlField_);
    cList.add(urlLabel);
    urlLine.add(urlLabel);
    urlLine.add(urlField_);
    main.add(urlLine);
    main.add(Box.createVerticalStrut(10));

    /* Field for input table. */
    final JComboBox tableSelector = new TablesListComboBox();
    tableSelector.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent evt) {
            setInputTable((TopcatModel) tableSelector.getSelectedItem());
          }
        });
    JLabel tableLabel = new JLabel("Input Table: ");
    cList.add(tableLabel);
    cList.add(tableSelector);
    Box tableLine = Box.createHorizontalBox();
    tableLine.add(tableLabel);
    tableLine.add(new ShrinkWrapper(tableSelector));
    tableLine.add(Box.createHorizontalGlue());
    main.add(tableLine);
    main.add(Box.createVerticalStrut(5));

    /* Fields for position parameters. */
    raSelector_ = new ColumnSelector(Tables.RA_INFO, true);
    Box raLine = Box.createHorizontalBox();
    raLine.add(raSelector_);
    JLabel raSysLabel = new JLabel(" (J2000)");
    raLine.add(raSysLabel);
    raLine.add(Box.createHorizontalGlue());
    main.add(raLine);
    main.add(Box.createVerticalStrut(5));
    cList.add(raSelector_);
    cList.add(raSysLabel);
    decSelector_ = new ColumnSelector(Tables.DEC_INFO, true);
    Box decLine = Box.createHorizontalBox();
    decLine.add(decSelector_);
    JLabel decSysLabel = new JLabel(" (J2000)");
    decLine.add(decSysLabel);
    decLine.add(Box.createHorizontalGlue());
    main.add(decLine);
    main.add(Box.createVerticalStrut(5));
    cList.add(decSelector_);
    cList.add(decSysLabel);
    srSelector_ = new ColumnSelector(service.getSizeInfo(), true);
    service.setSizeDefault(srSelector_);
    Box srLine = Box.createHorizontalBox();
    srLine.add(srSelector_);
    JLabel srSysLabel = new JLabel("");
    srLine.add(srSysLabel);
    srLine.add(Box.createHorizontalGlue());
    main.add(srLine);
    cList.add(srSelector_);
    cList.add(srSysLabel);

    /* Align the positional fields. */
    alignLabels(
        new JLabel[] {
          raSelector_.getLabel(), decSelector_.getLabel(), srSelector_.getLabel(),
        });
    alignLabels(
        new JLabel[] {
          raSysLabel, decSysLabel, srSysLabel,
        });

    /* Custom service controls. */
    JComponent servicePanel = service_.getControlPanel();
    if (servicePanel != null) {
      JComponent serviceLine = Box.createHorizontalBox();
      serviceLine.add(servicePanel);
      serviceLine.add(Box.createHorizontalGlue());
      main.add(Box.createVerticalStrut(5));
      main.add(serviceLine);
      cList.add(servicePanel);
    }

    /* Multicone output mode selector. */
    main.add(Box.createVerticalStrut(10));
    modeSelector_ = new JComboBox(getMulticoneModes());
    Box modeLine = Box.createHorizontalBox();
    JLabel modeLabel = new JLabel("Output Mode: ");
    modeLine.add(modeLabel);
    modeLine.add(new ShrinkWrapper(modeSelector_));
    modeLine.add(Box.createHorizontalGlue());
    cList.add(modeLabel);
    cList.add(modeSelector_);
    main.add(modeLine);
    main.add(Box.createVerticalStrut(5));

    /* Set up coverage icons. */
    hasCoverage_ = service_.hasCoverages();
    if (hasCoverage_) {

      /* Service coverage icon. */
      serviceCoverageView_ = new CoverageView(service_.getLabel() + " service");
      serviceCoverageView_.setForeground(new Color(0x0000ff));
      serviceCoverageView_.setBackground(new Color(0xc0c0ff));
      urlField_.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              updateServiceCoverage();
            }
          });
      urlField_.addFocusListener(
          new FocusListener() {
            public void focusLost(FocusEvent evt) {
              updateServiceCoverage();
            }

            public void focusGained(FocusEvent evt) {}
          });
      urlLine.add(Box.createHorizontalStrut(5));
      urlLine.add(serviceCoverageView_);

      /* Table coverage icon. */
      queryCoverageView_ = new CoverageView("table");
      queryCoverageView_.setForeground(new Color(0xff0000));
      queryCoverageView_.setBackground(new Color(0xffc0c0));
      ActionListener tableListener =
          new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              updateQueryCoverage();
            }
          };
      tableSelector.addActionListener(tableListener);
      raSelector_.addActionListener(tableListener);
      decSelector_.addActionListener(tableListener);
      srSelector_.addActionListener(tableListener);
      tableLine.add(new ShrinkWrapper(queryCoverageView_));
      tcListener_ =
          new TopcatListener() {
            public void modelChanged(TopcatEvent evt) {
              if (evt.getCode() == TopcatEvent.CURRENT_SUBSET) {
                updateQueryCoverage();
              }
            }
          };

      /* Overlap coverage icon. */
      overlapCoverageView_ = new CoverageView("potential matches");
      overlapCoverageView_.setForeground(new Color(0xd000d0));
      overlapCoverageView_.setBackground(new Color(0xffc0ff));
      modeLine.add(new ShrinkWrapper(overlapCoverageView_));
    } else {
      tcListener_ = null;
      queryCoverageView_ = null;
      serviceCoverageView_ = null;
      overlapCoverageView_ = null;
    }

    /* Configure coverage display toggle. */
    coverageModel_ =
        new ToggleButtonModel(
            "Use Service Coverage",
            ResourceIcon.FOOTPRINT,
            "Use service coverage information (MOCs) "
                + "where available to avoid unnecessary "
                + "queries");
    coverageModel_.setSelected(hasCoverage_);
    coverageModel_.setEnabled(hasCoverage_);
    coverageModel_.addChangeListener(
        new ChangeListener() {
          private boolean wasSelected_ = coverageModel_.isSelected();

          public void stateChanged(ChangeEvent evt) {
            boolean isSelected = coverageModel_.isSelected();
            if (isSelected ^ wasSelected_) {
              updateServiceCoverage();
              updateQueryCoverage();
              updateOverlapCoverage();
              wasSelected_ = isSelected;
            }
          }
        });

    /* Service access parameters. */
    int maxpar = ParallelResultRowSequence.getMaxParallelism();
    parallelModel_ = new SpinnerNumberModel(Math.min(5, maxpar), 1, maxpar, 1);
    JLabel parallelLabel = new JLabel("Parallelism: ");
    JSpinner parallelSpinner = new JSpinner(parallelModel_);
    cList.add(parallelLabel);
    cList.add(parallelSpinner);
    erractSelector_ = new JComboBox(getConeErrorPolicies(service));
    JLabel erractLabel = new JLabel(ERRACT_LABEL + ": ");
    cList.add(erractLabel);
    cList.add(erractSelector_);
    Box accessLine = Box.createHorizontalBox();
    accessLine.add(parallelLabel);
    accessLine.add(new ShrinkWrapper(parallelSpinner));
    accessLine.add(Box.createHorizontalStrut(10));
    accessLine.add(erractLabel);
    accessLine.add(new ShrinkWrapper(erractSelector_));
    accessLine.add(Box.createHorizontalGlue());
    main.add(accessLine);

    /* Action to initiate multicone. */
    startAction_ =
        new BasicAction("Go", null, "Start multiple query running") {
          public void actionPerformed(ActionEvent evt) {
            startMatch();
          }
        };

    /* Action to interrupt processing. */
    stopAction_ =
        new BasicAction(
            "Stop", null, "Interrupt running multiple query; " + "results will be discarded") {
          public void actionPerformed(ActionEvent evt) {
            setActive(null);
          }
        };

    /* Initialise enabledness of controls etc. */
    components_ = (JComponent[]) cList.toArray(new JComponent[0]);
    updateState();
  }