/**
     * Updates the shared value instance if updateValue is true. Always forces the redraw of
     * everything.
     */
    protected void doValueUpdate(FilterBypass fb) throws BadLocationException {
      Document doc = fb.getDocument();
      String text = doc.getText(0, doc.getLength());
      if (text.isEmpty()) {
        text = "0";
      }

      if (updateValue == true) {
        try {
          Double value = new Double(text);
          double newValue = multiplier.getValueToBeSet(value.doubleValue());
          cValue.setValue(newValue);
        } catch (NumberFormatException e) {
          // do nothing, since we allow '-'
        }
      }
      topContainer.forceRedraw();
    }
  /**
   * The consturctor Constructor instantiates all the panels, convertible value instance, and the
   * frame. And adds the panels to the frame. And sets a proper size for the frame.
   */
  public HappyHackingConverter() {
    CFrame frame = new CFrame();
    frame.setBackground(white);

    ConvertibleValue temperatures = new ConvertibleValue();
    ConvertibleValue distances = new ConvertibleValue();
    ConvertibleValue weights = new ConvertibleValue();

    GridBagLayout leftSideLayout = new GridBagLayout();
    JPanel leftSide = new JPanel(leftSideLayout);
    leftSide.setBackground(white);

    GridBagLayout rightSideLayout = new GridBagLayout();
    JPanel rightSide = new JPanel(rightSideLayout);
    rightSide.setBackground(white);

    GridBagConstraints metricTemperatureConstraints = new GridBagConstraints();
    metricTemperatureConstraints.gridx = 0;
    metricTemperatureConstraints.gridy = 0;
    metricTemperatureConstraints.weighty = 0.1;
    metricTemperatureConstraints.weightx = 1;
    metricTemperatureConstraints.fill = GridBagConstraints.BOTH;
    metricTemperatureConstraints.anchor = GridBagConstraints.FIRST_LINE_START;
    JPanel metricTemperaturePanel =
        new TemperaturePanel(frame, temperatures, TemperatureScales.CENTIGRADE);
    leftSideLayout.setConstraints(metricTemperaturePanel, metricTemperatureConstraints);
    leftSide.add(metricTemperaturePanel);

    GridBagConstraints metricDistancesPanelConstraints = new GridBagConstraints();
    metricDistancesPanelConstraints.gridx = 0;
    metricDistancesPanelConstraints.gridy = 1;
    metricDistancesPanelConstraints.weighty = 0.3;
    metricDistancesPanelConstraints.weightx = 1;
    metricDistancesPanelConstraints.fill = GridBagConstraints.BOTH;
    metricDistancesPanelConstraints.anchor = GridBagConstraints.FIRST_LINE_START;
    JPanel metricDistancesPanel = new MetricDistancesPanel(frame, distances);
    leftSideLayout.setConstraints(metricDistancesPanel, metricDistancesPanelConstraints);
    leftSide.add(metricDistancesPanel);

    GridBagConstraints fahrenheitConstraints = new GridBagConstraints();
    fahrenheitConstraints.gridx = 0;
    fahrenheitConstraints.gridy = 0;
    fahrenheitConstraints.weighty = 0.1;
    fahrenheitConstraints.weightx = 1;
    fahrenheitConstraints.fill = GridBagConstraints.BOTH;
    fahrenheitConstraints.anchor = GridBagConstraints.FIRST_LINE_START;
    JPanel fahrenheitTemperaturePanel =
        new TemperaturePanel(frame, temperatures, TemperatureScales.FAHRENHEIT);
    rightSideLayout.setConstraints(fahrenheitTemperaturePanel, fahrenheitConstraints);
    rightSide.add(fahrenheitTemperaturePanel);

    GridBagConstraints imperialDistancesPanelConstraints = new GridBagConstraints();
    imperialDistancesPanelConstraints.gridx = 0;
    imperialDistancesPanelConstraints.gridy = 1;
    imperialDistancesPanelConstraints.weighty = 0.3;
    imperialDistancesPanelConstraints.weightx = 1;
    imperialDistancesPanelConstraints.fill = GridBagConstraints.BOTH;
    imperialDistancesPanelConstraints.anchor = GridBagConstraints.FIRST_LINE_START;
    JPanel imperialDistancesPanel = new ImperialDistancesPanel(frame, distances);
    rightSideLayout.setConstraints(imperialDistancesPanel, imperialDistancesPanelConstraints);
    rightSide.add(imperialDistancesPanel);

    GridBagConstraints metricWeightsConstraints = new GridBagConstraints();
    metricWeightsConstraints.gridx = 0;
    metricWeightsConstraints.gridy = 2;
    metricWeightsConstraints.weighty = 0.6;
    metricWeightsConstraints.weightx = 1;
    metricWeightsConstraints.fill = GridBagConstraints.BOTH;
    metricWeightsConstraints.anchor = GridBagConstraints.FIRST_LINE_START;
    MetricWeightsPanel metricWeightsPanel = new MetricWeightsPanel(frame, weights);
    leftSideLayout.setConstraints(metricWeightsPanel, metricWeightsConstraints);
    leftSide.add(metricWeightsPanel);

    GridBagConstraints imperialWeightsConstraints = new GridBagConstraints();
    imperialWeightsConstraints.gridx = 0;
    imperialWeightsConstraints.gridy = 2;
    imperialWeightsConstraints.weighty = 0.6;
    imperialWeightsConstraints.weightx = 1;
    imperialWeightsConstraints.fill = GridBagConstraints.BOTH;
    imperialWeightsConstraints.anchor = GridBagConstraints.FIRST_LINE_START;
    ImperialWeightsPanel imperialWeightsPanel = new ImperialWeightsPanel(frame, weights);
    rightSideLayout.setConstraints(imperialWeightsPanel, imperialWeightsConstraints);
    rightSide.add(imperialWeightsPanel);

    CSplit split = new CSplit(JSplitPane.HORIZONTAL_SPLIT, true, leftSide, rightSide);
    Container contentPane = frame.getContentPane();
    contentPane.add(split);
    frame.validate();
    frame.pack();
    frame.setSize(600, 997);
    split.setResizeWeight(0.5);
    split.setDividerLocation(0.5);
  } // end of HappyHackingConverter constructor