/**
   * <code>init</code> - wait for instance to become displayable, determine appropriate font
   * metrics, and render the JGo timeline, and slot widgets
   *
   * <p>These functions are not done in the constructor to avoid: "Cannot measure text until a
   * JGoView exists and is part of a visible window". called by componentShown method on the JFrame
   * JGoView.setVisible( true) must be completed -- use runInit in constructor
   */
  public final void init() {
    handleEvent(ViewListener.EVT_INIT_BEGUN_DRAWING);
    // wait for TimelineView instance to become displayable
    while (!this.isDisplayable()) {
      try {
        Thread.currentThread().sleep(50);
      } catch (InterruptedException excp) {
      }
      // System.err.println( "timelineView displayable " + this.isDisplayable());
    }
    this.computeFontMetrics(this);

    QueryHeaderView headerJGoView = new QueryHeaderView(query);
    headerJGoView.validate();
    headerJGoView.setVisible(true);

    FixedHeightPanel variableHeaderPanel = new FixedHeightPanel(headerJGoView, this);
    variableHeaderPanel.setLayout(new BoxLayout(variableHeaderPanel, BoxLayout.Y_AXIS));
    variableHeaderPanel.add(headerJGoView, BorderLayout.NORTH);
    add(variableHeaderPanel, BorderLayout.NORTH);

    String[] columnNames = {
      ViewConstants.DB_TRANSACTION_STEP_NUM_HEADER,
      ViewConstants.QUERY_VARIABLE_KEY_HEADER,
      ViewConstants.QUERY_VARIABLE_TYPE_HEADER,
      ViewConstants.DB_TRANSACTION_PARENT_HEADER,
      // empty last column to allow user adjusting of column widths
      ""
    };
    PwPartialPlan partialPlan = null;
    try {
      partialPlan = planSequence.getPartialPlan(stepNumber);
    } catch (ResourceNotFoundException rnfExcep) {
      int index = rnfExcep.getMessage().indexOf(":");
      JOptionPane.showMessageDialog(
          PlanWorks.getPlanWorks(),
          rnfExcep.getMessage().substring(index + 1),
          "Resource Not Found Exception",
          JOptionPane.ERROR_MESSAGE);
      System.err.println(rnfExcep);
      rnfExcep.printStackTrace();
    }
    Object[][] data = new Object[variableList.size()][columnNames.length];
    for (int row = 0, nRows = variableList.size(); row < nRows; row++) {
      PwVariableQuery variable = (PwVariableQuery) variableList.get(row);
      data[row][0] = variable.getStepNumber().toString();
      data[row][1] = variable.getId().toString();
      data[row][2] = variable.getType();
      data[row][3] = partialPlan.getVariableParentName(variable.getParentId());
    }
    objectKeyColumnIndx = 1;
    stepNumberColumnIndx = 0;
    TableSorter sorter = new TableSorter(new DBTransactionTableModel(columnNames, data));
    variableTable = new DBTransactionTable(sorter, stepNumberColumnIndx, this);
    sorter.setTableHeader(variableTable.getTableHeader());
    contentScrollPane = new JScrollPane(variableTable);
    add(contentScrollPane, BorderLayout.SOUTH);

    this.setVisible(true);

    int maxViewWidth = (int) headerJGoView.getDocumentSize().getWidth();
    int maxViewHeight =
        (int)
            (headerJGoView.getDocumentSize().getHeight()
                +
                // contentJGoView.getDocumentSize().getHeight());
                // keep contentJGoView small
                (ViewConstants.INTERNAL_FRAME_X_DELTA));
    viewFrame.setSize(
        maxViewWidth + ViewConstants.MDI_FRAME_DECORATION_WIDTH,
        maxViewHeight + ViewConstants.MDI_FRAME_DECORATION_HEIGHT);
    int maxQueryFrameY =
        (int)
            (sequenceQueryWindow.getSequenceQueryFrame().getLocation().getY()
                + sequenceQueryWindow.getSequenceQueryFrame().getSize().getHeight());
    int delta =
        Math.min(
            ViewConstants.INTERNAL_FRAME_X_DELTA_DIV_4
                * sequenceQueryWindow.getQueryResultFrameCnt(),
            (int)
                (PlanWorks.getPlanWorks().getSize().getHeight()
                    - maxQueryFrameY
                    - (ViewConstants.MDI_FRAME_DECORATION_HEIGHT * 2)));
    viewFrame.setLocation(ViewConstants.INTERNAL_FRAME_X_DELTA + delta, maxQueryFrameY + delta);
    // prevent right edge from going outside the MDI frame
    expandViewFrame(
        viewFrame,
        Math.max(
            (int) headerJGoView.getDocumentSize().getWidth(),
            variableTable.getColumnModel().getTotalColumnWidth()),
        (int)
            (headerJGoView.getDocumentSize().getHeight()
                + variableTable.getRowCount() * variableTable.getRowHeight()));

    long stopTimeMSecs = System.currentTimeMillis();
    System.err.println(
        "   ... '"
            + this.getName()
            + "'elapsed time: "
            + (stopTimeMSecs - startTimeMSecs)
            + " msecs.");
    handleEvent(ViewListener.EVT_INIT_ENDED_DRAWING);
  } // end init