Пример #1
0
 /**
  * Decoder identify has not matched specific types, but did find manufacturer match
  *
  * @param pMfg Manufacturer name. This is passed to save time, as it has already been determined
  *     once.
  * @param pMfgID Manufacturer ID number (CV8)
  * @param pModelID Model ID number (CV7)
  */
 void updateForDecoderMfgID(String pMfg, int pMfgID, int pModelID) {
   String msg =
       "Found mfg " + pMfgID + " (" + pMfg + ") version " + pModelID + "; no such decoder defined";
   log.warn(msg);
   _statusLabel.setText(msg);
   // try to select all decoders from that MFG
   JComboBox<String> temp =
       DecoderIndexFile.instance()
           .matchingComboBox(null, null, Integer.toString(pMfgID), null, null, null);
   if (log.isDebugEnabled()) {
     log.debug("mfg-only selectDecoder found " + temp.getItemCount() + " matches");
   }
   // install all those in the JComboBox in place of the longer, original list
   if (temp.getItemCount() > 0) {
     decoderBox.setModel(temp.getModel());
     decoderBox.insertItemAt("<from locomotive settings>", 0);
     decoderBox.setSelectedIndex(1);
   } else {
     // if there are none from this mfg, go back to showing everything
     temp = DecoderIndexFile.instance().matchingComboBox(null, null, null, null, null, null);
     decoderBox.setModel(temp.getModel());
     decoderBox.insertItemAt("<from locomotive settings>", 0);
     decoderBox.setSelectedIndex(1);
   }
 }
Пример #2
0
  /**
   * Create the panel used to select the decoder
   *
   * @return a JPanel for handling the decoder-selection GUI
   */
  protected JPanel layoutDecoderSelection() {
    JPanel pane1a = new JPanel();
    pane1a.setLayout(new BoxLayout(pane1a, BoxLayout.X_AXIS));
    pane1a.add(new JLabel("Decoder installed: "));
    decoderBox = DecoderIndexFile.instance().matchingComboBox(null, null, null, null, null, null);
    decoderBox.insertItemAt("<from locomotive settings>", 0);
    decoderBox.setSelectedIndex(0);
    decoderBox.addActionListener(
        new ActionListener() {

          public void actionPerformed(java.awt.event.ActionEvent e) {
            if (decoderBox.getSelectedIndex() != 0) {
              // reset and disable loco selection
              locoBox.setSelectedIndex(0);
              go2.setEnabled(true);
              go2.setRequestFocusEnabled(true);
              go2.requestFocus();
              go2.setToolTipText(Bundle.getMessage("CLICK TO OPEN THE PROGRAMMER"));
            } else {
              go2.setEnabled(false);
              go2.setToolTipText(Bundle.getMessage("SELECT A LOCOMOTIVE OR DECODER TO ENABLE"));
            }
          }
        });
    pane1a.add(decoderBox);
    iddecoder = addDecoderIdentButton();
    if (iddecoder != null) {
      pane1a.add(iddecoder);
    }
    pane1a.setAlignmentX(JLabel.RIGHT_ALIGNMENT);
    return pane1a;
  }
Пример #3
0
 /** Decoder identify did not match anything, warn and show all */
 void updateForDecoderNotID(int pMfgID, int pModelID) {
   log.warn("Found mfg " + pMfgID + " version " + pModelID + "; no such manufacterer defined");
   JComboBox<String> temp =
       DecoderIndexFile.instance().matchingComboBox(null, null, null, null, null, null);
   decoderBox.setModel(temp.getModel());
   decoderBox.insertItemAt("<from locomotive settings>", 0);
   decoderBox.setSelectedIndex(1);
 }
Пример #4
0
  /** Start with a decoder selected, so we're going to create a new RosterEntry. */
  protected void openNewLoco() {
    // find the decoderFile object
    DecoderFile decoderFile = DecoderIndexFile.instance().fileFromTitle(selectedDecoderType());
    if (log.isDebugEnabled()) {
      log.debug("decoder file: " + decoderFile.getFilename());
    }

    // create a dummy RosterEntry with the decoder info
    RosterEntry re = new RosterEntry();
    re.setDecoderFamily(decoderFile.getFamily());
    re.setDecoderModel(decoderFile.getModel());
    re.setId(Bundle.getMessage("LabelNewDecoder"));
    // note that we're leaving the filename null
    // add the new roster entry to the in-memory roster
    Roster.getDefault().addEntry(re);

    startProgrammer(decoderFile, re, (String) programmerBox.getSelectedItem());
  }
Пример #5
0
 /** Decoder identify has matched one or more specific types */
 void updateForDecoderTypeID(List<DecoderFile> pList) {
   decoderBox.setModel(DecoderIndexFile.jComboBoxModelFromList(pList));
   decoderBox.insertItemAt("<from locomotive settings>", 0);
   decoderBox.setSelectedIndex(1);
 }
Пример #6
0
  /**
   * Identify decoder complete, act on it by setting the GUI This will fire "GUI changed" events
   * which will reset the locomotive GUI.
   *
   * @param mfgID the decoder's manufacturer ID value from CV8
   * @param modelID the decoder's model ID value from CV7
   * @param productID the decoder's product ID
   */
  protected void selectDecoder(int mfgID, int modelID, int productID) {
    // raise the button again
    iddecoder.setSelected(false);
    List<DecoderFile> temp = null;

    // if productID present, try with that
    if (productID != -1) {
      String sz_productID = Integer.toString(productID);
      temp =
          DecoderIndexFile.instance()
              .matchingDecoderList(
                  null,
                  null,
                  Integer.toString(mfgID),
                  Integer.toString(modelID),
                  sz_productID,
                  null);
      if (temp.isEmpty()) {
        log.debug("selectDecoder found no items with product ID " + productID);
        temp = null;
      } else {
        log.debug("selectDecoder found " + temp.size() + " matches with productID " + productID);
      }
    }

    // try without product ID if needed
    if (temp == null) { // i.e. if no match previously
      temp =
          DecoderIndexFile.instance()
              .matchingDecoderList(
                  null, null, Integer.toString(mfgID), Integer.toString(modelID), null, null);
      if (log.isDebugEnabled()) {
        log.debug("selectDecoder without productID found " + temp.size() + " matches");
      }
    }

    // remove unwanted matches
    int tempOriginalSize = temp.size(); // save size of unfiltered list
    String theFamily = "";
    String theModel = "";
    String lastWasFamily = "";

    ListIterator<DecoderFile> it = temp.listIterator();
    while (it.hasNext()) {
      log.debug("Match List size is currently {}, scanning for unwanted entries", temp.size());
      DecoderFile t = it.next();
      theFamily = t.getFamily();
      theModel = t.getModel();
      if (t.getFamily().equals(theModel)) {
        log.debug("Match List index={} is family entry '{}'", it.previousIndex(), theFamily);
        lastWasFamily = theFamily;
      } else if (lastWasFamily.equals(theFamily)) {
        log.debug(
            "Match List index={} is first model '{}' in family '{}'",
            it.previousIndex(),
            theModel,
            theFamily);
        log.debug("Removing family entry '{}'", theFamily);
        t = it.previous();
        t = it.previous();
        it.remove();
        lastWasFamily = "";
      } else if ((t.getModelElement().getAttribute("show") != null)
          && (t.getModelElement().getAttribute("show").getValue().equals("no"))) {
        log.debug(
            "Match List index={} is legacy model '{}' in family '{}'",
            it.previousIndex(),
            theModel,
            theFamily);
        log.debug("Removing legacy model '{}'", theModel);
        t = it.previous();
        it.remove();
        lastWasFamily = "";
      } else {
        log.debug(
            "Match List index={} is model '{}' in family '{}'",
            it.previousIndex(),
            theModel,
            theFamily);
        lastWasFamily = "";
      }
    }

    log.debug("Final Match List size is {}", temp.size());

    // If we had match(es) previously but have lost them in filtering
    // pretend we have no product ID so we get a coarse match
    if (tempOriginalSize > 0 && temp.isEmpty()) {
      log.debug(
          "Filtering removed all matches so reverting to coarse match with mfgID='{}' & modelID='{}'",
          Integer.toString(mfgID),
          Integer.toString(modelID));
      temp =
          DecoderIndexFile.instance()
              .matchingDecoderList(
                  null, null, Integer.toString(mfgID), Integer.toString(modelID), null, null);
      log.debug("selectDecoder without productID found {} matches", temp.size());
    }

    // install all those in the JComboBox in place of the longer, original list
    if (temp.size() > 0) {
      updateForDecoderTypeID(temp);
    } else {
      String mfg = DecoderIndexFile.instance().mfgNameFromId(Integer.toString(mfgID));
      if (mfg == null) {
        updateForDecoderNotID(mfgID, modelID);
      } else {
        updateForDecoderMfgID(mfg, mfgID, modelID);
      }
    }
  }