示例#1
0
  /**
   * Move to the specified origin (in bins)
   *
   * @param newBinX new location X
   * @param newBinY new location Y
   */
  private void moveTo(double newBinX, double newBinY) {
    try {
      MatrixZoomData zd = getZd();

      final double wBins = (superAdapter.getHeatmapPanel().getWidth() / getScaleFactor());
      double maxX = zd.getXGridAxis().getBinCount() - wBins;

      final double hBins = (superAdapter.getHeatmapPanel().getHeight() / getScaleFactor());
      double maxY = zd.getYGridAxis().getBinCount() - hBins;

      double x = Math.max(0, Math.min(maxX, newBinX));
      double y = Math.max(0, Math.min(maxY, newBinY));

      xContext.setBinOrigin(x);
      yContext.setBinOrigin(y);

      superAdapter.repaint();
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (linkedMode) {
      broadcastLocation();
    }
  }
示例#2
0
    @Override
    public void execute(final GUI gui) {
      final boolean rt = gui.gprop.invert(GUIProp.FILTERRT);
      gui.stop();
      // refresh buttons in input bar
      gui.refreshControls();
      // refresh editor buttons
      gui.editor.refreshMark();

      final Context ctx = gui.context;
      final boolean root = ctx.root();
      final Data data = ctx.data();
      if (!rt) {
        if (!root) {
          gui.notify.context(new Nodes(0, data), true, null);
          gui.notify.mark(ctx.current(), null);
        }
      } else {
        if (root) {
          gui.notify.mark(new Nodes(data), null);
        } else {
          final Nodes mark = ctx.marked;
          ctx.marked = new Nodes(data);
          gui.notify.context(mark, true, null);
        }
      }
    }
示例#3
0
 @Override
 public void execute(final GUI gui) {
   // skip operation for root context
   final Context ctx = gui.context;
   if (ctx.root()) return;
   // jump to database root
   ctx.update();
   gui.notify.context(ctx.current(), false, null);
 }
示例#4
0
 @Override
 public void execute(final GUI gui) {
   final Context ctx = gui.context;
   Nodes marked = ctx.marked;
   if (marked.size() == 0) {
     final int pre = gui.context.focused;
     if (pre == -1) return;
     marked = new Nodes(pre, ctx.data());
   }
   gui.notify.context(marked, false, null);
 }
示例#5
0
 public void nameFocusLost(java.awt.event.FocusEvent evt) {
   ctxt.saveState = true;
   String newName = name.getText(), msg;
   while (!Library.validateFileName(newName, false)) {
     msg = "The name '" + newName + "' violates the rules for names:";
     msg += "\nIt must have 2 to 28 characters.";
     msg += "\nYou may not use BackSlash, ForwardSlash, Colon, DoubleQuote";
     msg += "\nAsterisk, QuestionMark, LeftAngleBracket, RightAngleBracket,";
     msg += "\nor the VerticalBar in a name. TRY AGAIN.";
     newName = JOptionPane.showInputDialog(msg);
   } //  end of harrass-em-until-they-give-a-good-name
   name.setText(newName);
   if (!newName.equals(ctxt.languageName)) { // Made a change
     msg = "Change this context's language name\nto" + newName + "?";
     String[] options = {newName, ctxt.languageName};
     int choice =
         JOptionPane.showOptionDialog(
             this,
             msg,
             "Confirm Changed Language Name",
             JOptionPane.YES_NO_OPTION,
             JOptionPane.QUESTION_MESSAGE,
             null,
             options,
             options[0]);
     if (choice == 0) { //  Change is confirmed
       ctxt.languageName = newName;
       msg =
           "Normally, the file name for a context is the same as the language name "
               + "\nfor that context.  Change this context's file name\n"
               + "to "
               + newName
               + "?";
       options[0] = "Change File Name";
       options[1] = "Do Not Change";
       choice =
           JOptionPane.showOptionDialog(
               this,
               msg,
               "Confirm Correct File Name",
               JOptionPane.YES_NO_OPTION,
               JOptionPane.QUESTION_MESSAGE,
               null,
               options,
               options[0]);
       if (choice == 0) {
         Library.userContextName = newName;
         if (SIL_Edit.edWin != null && ctxt == Library.contextUnderConstruction) {
           SIL_Edit.edWin.chart.changeFileName(newName);
         }
       }
     } //  end of Change-is-confirmed
   } //  end of change-was-made
 }
示例#6
0
 public Matrix getMatrix() {
   if (dataset == null) {
     // System.err.println("Dataset is null");
     return null;
   } else if (xContext == null) {
     // System.err.println("xContext is null");
     return null;
   } else if (yContext == null) {
     // System.err.println("yContext is null");
     return null;
   }
   return dataset.getMatrix(xContext.getChromosome(), yContext.getChromosome());
 }
示例#7
0
  public int[] getCurrentRegionWindowGenomicPositions() {

    // address int overflow or exceeding bound issues
    int xEndEdge =
        xContext.getGenomicPositionOrigin()
            + (int)
                ((double) getZoom().getBinSize()
                    * superAdapter.getHeatmapPanel().getWidth()
                    / getScaleFactor());
    if (xEndEdge < 0 || xEndEdge > xContext.getChromosome().getLength()) {
      xEndEdge = xContext.getChromosome().getLength();
    }

    int yEndEdge =
        yContext.getGenomicPositionOrigin()
            + (int)
                ((double) getZoom().getBinSize()
                    * superAdapter.getHeatmapPanel().getHeight()
                    / getScaleFactor());
    if (yEndEdge < 0 || yEndEdge > yContext.getChromosome().getLength()) {
      yEndEdge = yContext.getChromosome().getLength();
    }

    return new int[] {
      xContext.getGenomicPositionOrigin(), xEndEdge, yContext.getGenomicPositionOrigin(), yEndEdge
    };
  }
示例#8
0
      @Override
      public Boolean dispatch(@NotNull KeyEvent e, @NotNull Context context) {
        if (myWrapper == null || myTypeAheadDone.isProcessed()) return null;

        myEvents.addAll(context.getQueue());
        context.getQueue().clear();

        if (isToDispatchToDialogNow(e)) {
          return false;
        } else {
          myEvents.add(e);
          return true;
        }
      }
示例#9
0
  public String getDefaultLocationDescription() {

    String xChr = xContext.getChromosome().getName();
    String yChr = yContext.getChromosome().getName();

    if (!(xChr.toLowerCase().contains("chr"))) xChr = "chr" + xChr;
    if (!(yChr.toLowerCase().contains("chr"))) yChr = "chr" + yChr;

    return xChr
        + "@"
        + (long) (xContext.getBinOrigin() * currentZoom.getBinSize())
        + "_"
        + yChr
        + "@"
        + (long) (yContext.getBinOrigin() * currentZoom.getBinSize());
  }
示例#10
0
  private void setChromosomesFromBroadcast(String chrXName, String chrYName) {
    if (!chrXName.equals(xContext.getChromosome().getName())
        || !chrYName.equals(yContext.getChromosome().getName())) {
      Chromosome chrX = HiCFileTools.getChromosomeNamed(chrXName, chromosomes);
      Chromosome chrY = HiCFileTools.getChromosomeNamed(chrYName, chromosomes);

      if (chrX == null || chrY == null) {
        // log.info("Most probably origin is a different species saved location or sync/link between
        // two different species maps.");
        return;
      }

      this.xContext = new Context(chrX);
      this.yContext = new Context(chrY);
      superAdapter.setSelectedChromosomesNoRefresh(chrX, chrY);
      refreshEigenvectorTrackIfExists();
    }
  }
示例#11
0
  public void update() {
    nUpdate();

    if (!isFocused && parent != null && parent_focused.compareAndSet(true, false)) {
      setFocus(getHwnd());
    }

    if (redoMakeContextCurrent) {
      redoMakeContextCurrent = false;
      /**
       * WORKAROUND: Making the context current (redundantly) when the window is maximized helps
       * some gfx cards recover from fullscreen
       */
      try {
        Context context = ((DrawableLWJGL) Display.getDrawable()).getContext();
        if (context != null && context.isCurrent()) context.makeCurrent();
      } catch (LWJGLException e) {
        LWJGLUtil.log("Exception occurred while trying to make context current: " + e);
      }
    }
  }
示例#12
0
  public String getLocationDescription() {
    String xChr = xContext.getChromosome().getName();
    String yChr = yContext.getChromosome().getName();

    if (!(xChr.toLowerCase().contains("chr"))) xChr = "chr" + xChr;
    if (!(yChr.toLowerCase().contains("chr"))) yChr = "chr" + yChr;

    return "setlocation "
        + xChr
        + " "
        + yChr
        + " "
        + currentZoom.getUnit().toString()
        + " "
        + currentZoom.getBinSize()
        + " "
        + xContext.getBinOrigin()
        + " "
        + yContext.getBinOrigin()
        + " "
        + getScaleFactor();
  }
示例#13
0
 @Override
 public void execute(final GUI gui) {
   // skip operation for root context
   final Context ctx = gui.context;
   if (ctx.root()) return;
   // check if all nodes are document nodes
   boolean doc = true;
   final Data data = ctx.data();
   for (final int pre : ctx.current().pres) doc &= data.kind(pre) == Data.DOC;
   if (doc) {
     // if yes, jump to database root
     ctx.update();
     gui.notify.context(ctx.current(), false, null);
   } else {
     // otherwise, jump to parent nodes
     gui.execute(new Cs(".."));
   }
 }
示例#14
0
 @Override
 public void execute(final GUI gui) {
   final Context ctx = gui.context;
   final Nodes n = ctx.marked;
   ctx.copied = new Nodes(n.pres, n.data);
 }
示例#15
0
  /**
   * ************************************************************* Official Method for setting the
   * zoom and location for heatmap DO NOT IMPLEMENT A NEW FUNCTION Make the necessary
   * customizations, then call this function
   * *************************************************************
   *
   * @param newZoom
   * @param genomeX
   * @param genomeY
   * @param scaleFactor (pass -1 if scaleFactor should be calculated)
   * @return
   */
  public boolean unsafeActuallySetZoomAndLocation(
      String chrXName,
      String chrYName,
      HiCZoom newZoom,
      int genomeX,
      int genomeY,
      double scaleFactor,
      boolean resetZoom,
      ZoomCallType zoomCallType,
      boolean allowLocationBroadcast) {

    if (dataset == null) return false; // No data in view

    // Check this zoom operation is possible, if not, fail it here:
    //        if (superAdapter.testNewZoom(newZoom))
    //        {
    //            return false;
    //        }

    // String chr1OriginalName = xContext.getChromosome().getName();
    // String chr2OriginalName = yContext.getChromosome().getName();
    if (chrXName.length() > 0 && chrYName.length() > 0) {
      setChromosomesFromBroadcast(chrXName, chrYName);
      // We might end with All->All view, make sure normalization state is updates accordingly...
      superAdapter.getMainViewPanel().setNormalizationDisplayState(superAdapter.getHiC());
    }

    if (newZoom == null) {
      System.err.println("Invalid zoom " + newZoom);
    }

    Chromosome chr1 = xContext.getChromosome();
    Chromosome chr2 = yContext.getChromosome();
    final Matrix matrix = dataset.getMatrix(chr1, chr2);

    if (matrix == null) {
      superAdapter.launchGenericMessageDialog(
          "Sorry, this region is not available", "Matrix unavailable", JOptionPane.WARNING_MESSAGE);
      return false;
    }

    MatrixZoomData newZD = matrix.getZoomData(newZoom);
    if (HiCFileTools.isAllChromosome(chr1)) {
      newZD = matrix.getFirstZoomData(Unit.BP);
    }

    if (newZD == null) {
      superAdapter.launchGenericMessageDialog(
          "Sorry, this zoom is not available", "Zoom unavailable", JOptionPane.WARNING_MESSAGE);
      return false;
    }

    /* TODO Undo Zoom implementation mss2 _UZI
    if(currentZoom != null) {
        tempZoomState = new ZoomState(chr1OriginalName, chr2OriginalName, currentZoom.clone(), (int) xContext.getBinOrigin(),
                (int) yContext.getBinOrigin(), getScaleFactor(), resetZoom, ZoomCallType.GOTO);
    }
    */

    currentZoom = newZoom;
    xContext.setZoom(currentZoom);
    yContext.setZoom(currentZoom);

    if (scaleFactor > 0) {
      setScaleFactor(scaleFactor);
    } else {
      int maxBinCount =
          Math.max(newZD.getXGridAxis().getBinCount(), newZD.getYGridAxis().getBinCount());
      double defaultScaleFactor =
          Math.max(
              1.0, (double) superAdapter.getHeatmapPanel().getMinimumDimension() / maxBinCount);
      setScaleFactor(defaultScaleFactor);
    }

    int binX = newZD.getXGridAxis().getBinNumberForGenomicPosition(genomeX);
    int binY = newZD.getYGridAxis().getBinNumberForGenomicPosition(genomeY);
    switch (zoomCallType) {
      case INITIAL:
      case STANDARD:
        center(binX, binY);
        break;
      case DRAG:
        xContext.setBinOrigin(binX);
        yContext.setBinOrigin(binY);
        break;
      case DIRECT:
        xContext.setBinOrigin(genomeX);
        yContext.setBinOrigin(genomeY);
        break;
    }

    // Notify HeatmapPanel render that zoom has changed. Render should update zoom slider once with
    // previous range values

    setZoomChanged();
    if (resetZoom) {
      superAdapter.updateAndResetZoom(newZoom);
    } else {
      superAdapter.updateZoom(newZoom);
    }
    superAdapter.refresh();

    if (linkedMode && allowLocationBroadcast) {
      broadcastLocation();
    }
    /*
    TODO Undo Zoom implementation mss2 _UZI
    if(zoomCallType == ZoomCallType.INITIAL || tempZoomState == null || chrXName.equals(Globals.CHR_ALL) || chrYName.equals(Globals.CHR_ALL)
            || tempZoomState.chr1Name.equals(Globals.CHR_ALL) || tempZoomState.chr2Name.equals(Globals.CHR_ALL)){
        canRedoZoomChange = false;
        canUndoZoomChange = false;
    }
    else {
        // defauts for a normal zoom operation
        canRedoZoomChange = false;
        canUndoZoomChange = true;
        previousZoomState = tempZoomState;
    }
    */

    return true;
  }
示例#16
0
 private void flushEvents() {
   if (myWrapper.isToDispatchTypeAhead() && myContextOnFinish != null) {
     myContextOnFinish.dispatch(myEvents);
   }
 }
示例#17
0
 public Matrix getControlMatrix() {
   if (controlDataset == null || xContext == null || currentZoom == null) return null;
   return controlDataset.getMatrix(xContext.getChromosome(), yContext.getChromosome());
 }
  BallDetector(boolean _display) {

    ctx = Freenect.createContext();
    if (ctx.numDevices() > 0) {
      kinect = ctx.openDevice(0);
    } else {
      System.err.println("WARNING: No kinects detected");
      return;
    }
    display = _display;

    controlFrame = new JFrame("Controls");
    controlFrame.setLayout(new GridLayout(5, 1));
    controlFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    pg = new ParameterGUI();
    pg.addIntSlider("maxDepth", "max depth", 800, 2047, 1050);
    pg.addIntSlider("blobThresh", "blob thresh", 1, 500, 125);
    pg.addIntSlider("thresh", "thresh", 1, 100, 10);
    pg.addIntSlider("frames", "frames", 1, 1000, 1);
    pg.addListener(
        new ParameterListener() {
          public void parameterChanged(ParameterGUI _pg, String name) {
            if (name.equals("thresh")) {
              KinectDepthVideo.THRESH = _pg.gi(name);
            } else if (name.equals("frames")) {
              KinectDepthVideo.MAX_FRAMES = _pg.gi(name);
            } else if (name.equals("maxDepth")) {
              KinectDepthVideo.MAX_DEPTH = _pg.gi(name);
            }
          }
        });
    controlFrame.add(pg, 0, 0);

    startTracking = new JButton("Start Tracking Balls");
    startTracking.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            if (!tracking) {
              tracking = true;
              colorStream.pause();
              depthStream.pause();
              startTracking.setText("Stop Tracking");
            } else {
              tracking = false;
              colorStream.resume();
              depthStream.resume();
              startTracking.setText("Start Tracking Balls");
            }
          }
        });
    controlFrame.add(startTracking, 1, 0);

    resetProjectile = new JButton("Reset Projectile");
    resetProjectile.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              lcm.publish("6_RESET", "reset");
            } catch (IOException ex) {
              System.out.println("can't publish reset");
            }
          }
        });
    controlFrame.add(resetProjectile, 2, 0);
    resetDepth = new JButton("Reset Depth Avgs");
    resetDepth.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            DepthClearer ic = new DepthClearer(pg);
            ic.start();
          }
        });
    controlFrame.add(resetDepth, 3, 0);
    JPanel scoreButtons = new JPanel(new GridLayout(1, 3));
    JButton addHuman = new JButton("human++");
    addHuman.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              lcm.publish("6_SCORE_HUMAN", "bish");
            } catch (IOException ex) {
              System.out.println("can't publish score");
            }
          }
        });
    JButton addRobot = new JButton("robot++");
    addRobot.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              lcm.publish("6_SCORE_ROBOT", "bish");
            } catch (IOException ex) {
              System.out.println("can't publish score");
            }
          }
        });
    JButton resetScores = new JButton("reset scores");
    resetScores.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              lcm.publish("6_SCORE_RESET", "bish");
            } catch (IOException ex) {
              System.out.println("can't publish score");
            }
          }
        });
    scoreButtons.add(addHuman, 0, 0);
    scoreButtons.add(addRobot, 0, 1);
    scoreButtons.add(resetScores, 0, 2);
    controlFrame.add(scoreButtons, 4, 0);
    controlFrame.setSize(800, 600);
    controlFrame.setVisible(true);

    colorFrame = new JFrame("color feed");
    colorMonitor = new Object();
    colorStream = new KinectRGBVideo(kinect, colorMonitor, display);
    colorFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    colorFrame.addWindowListener(new RGBClose());
    colorFrame.setSize(KinectVideo.WIDTH, KinectVideo.HEIGHT);
    colorFrame.setContentPane(colorStream);
    colorFrame.setVisible(true);

    depthFrame = new JFrame("depth feed");
    depthMonitor = new Object();
    depthStream = new KinectDepthVideo(kinect, depthMonitor, display);
    depthFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    depthFrame.setSize(KinectVideo.WIDTH, KinectVideo.HEIGHT);
    depthFrame.setContentPane(depthStream);
    depthFrame.setVisible(true);

    rgbImg = new BufferedImage(640, 480, BufferedImage.TYPE_INT_ARGB);
    depthImg = new BufferedImage(640, 480, BufferedImage.TYPE_INT_ARGB);

    validImageValue = new boolean[KinectVideo.WIDTH * KinectVideo.HEIGHT];
    try {
      lcm = new LCM("udpm://239.255.76.67:7667?ttl=1");
    } catch (IOException e) {
      lcm = LCM.getSingleton();
    }
    BALL = new Statistics();

    finder = new BallTracker(KinectVideo.WIDTH, KinectVideo.HEIGHT, false);

    if (display) {
      depthImg = depthStream.getFrame();
      rgbImg = colorStream.getFrame();
    }
    // get robot position from click
    depthStream.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            Point botPix = e.getPoint();
            botStart = depthStream.getWorldCoords(botPix);
            botStart.z += 0.08;
            System.out.println("botStart: " + botStart.toString());
            depthStream.showSubtraction();
            depthStream.botLoc = botPix;
          }
        });
    DepthClearer ic = new DepthClearer(pg);
    ic.start();
  }
示例#19
0
 private void doneButtonActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_doneButtonActionPerformed
   Context currCtxt = Context.current;
   if (accepted) {
     try {
       String sourceContextName = propDef.ktd.domTh.languageName;
       Context sourceCtxt = Library.findOrCreateContext(sourceContextName);
       if (propDef.ktd.domTh.addressTerms) {
         sourceCtxt.updateDomTheoryAdr(); // loads it on sourceCtxt
       } else {
         sourceCtxt.updateDomTheoryRef();
       }
       KinTermDef newDef = new KinTermDef(propDef.kinTerm);
       newDef.comments = FamilyPanel.convertBannedCharacters(notesText.getText());
       newDef.definitions = propDef.ktd.definitions;
       newDef.expandClauses(sourceCtxt);
       makePCStrings(newDef, propDef.eqc.sigString);
       updateCBPtrs(newDef);
       newDef.makeSigStrings();
       dt.addTerm(newDef);
       Context.AcceptedDefPtr ptr;
       ptr = new Context.AcceptedDefPtr(propDef.kinTerm, UDate.today(), "false", newDef.comments);
       ptr.postToHistory(learningHistory);
       // Move all dyads for this kinTerm to "Defined" category.
       TreeMap<String, ArrayList<Object>> dyads;
       dyads = (TreeMap<String, ArrayList<Object>>) dt.dyadsUndefined.remove(newDef.kinTerm);
       dt.dyadsDefined.put(newDef.kinTerm, dyads);
       SIL_Edit.edWin.chart.dirty = true;
       //  Set up auto-def for this KTD
       TreeMap<String, ArrayList<Context.CB_Ptr>>
           autoDef = // autoDef: kinType => AList of Context.CB_Ptrs
           (dt.addressTerms ? currCtxt.autoDefAdr : currCtxt.autoDefRef);
       for (Object o : newDef.expandedDefs) {
         ClauseBody cb = (ClauseBody) o;
         String kinType = cb.pcString;
         if (autoDef.get(kinType) == null) {
           autoDef.put(kinType, new ArrayList<Context.CB_Ptr>());
         }
         ArrayList<Context.CB_Ptr> defList = autoDef.get(kinType);
         defList.add(new Context.CB_Ptr(newDef.kinTerm, cb.seqNmbr));
       }
       //                Context.current = currCtxt;  // It was reset by updates to SourceCtxt
       String msg =
           "Would you like to apply this new definition to all\n"
               + "Ego/Alter pairs that it fits?";
       int decision =
           JOptionPane.showConfirmDialog(
               this, msg, "Apply Definition?", JOptionPane.YES_NO_OPTION);
       if (decision == JOptionPane.YES_OPTION) {
         SIL_Edit.edWin.applyDef(newDef, dt);
       }
       //  Mark this suggestion as processed and update menu
       papa.markProcessed(suggNmbr);
       papa.reset();
     } catch (Exception exc) {
       String msg = "While fleshing out a KTD for " + propDef.kinTerm;
       msg += "\nhit internal error: " + exc;
       MainPane.displayError(msg, "Internal Error", JOptionPane.ERROR_MESSAGE);
     }
   } else if (rejected) {
     Context.RejectedPropDefPtr reject =
         new Context.RejectedPropDefPtr(
             propDef.kinTerm,
             UDate.today(),
             "false",
             FamilyPanel.convertBannedCharacters(notesText.getText()),
             propDef.eqc.sigString,
             propDef.eqc.prototype.languageName,
             propDef.eqc.prototype.kinTerm);
     reject.postToHistory(learningHistory);
     papa.markProcessed(suggNmbr);
     papa.reset();
   }
   reset();
 } // GEN-LAST:event_doneButtonActionPerformed
示例#20
0
 public boolean isWholeGenome() {
   return xContext != null && HiCFileTools.isAllChromosome(xContext.getChromosome());
 }
示例#21
0
 public void folderFocusLost(java.awt.event.FocusEvent evt) {
   ctxt.saveState = true;
   ctxt.editDirectory = folder.getText();
 }
示例#22
0
 /**
  * Move by the specified delta (in bins)
  *
  * @param dxBins -- delta x in bins
  * @param dyBins -- delta y in bins
  */
 public void moveBy(double dxBins, double dyBins) {
   final double newX = xContext.getBinOrigin() + dxBins;
   final double newY = yContext.getBinOrigin() + dyBins;
   moveTo(newX, newY);
 }
示例#23
0
  public ContextEditor(Context cntxt) {
    super("Edit User Context: " + localFileName(cntxt));
    ctxt = cntxt;
    windowNum = ctxt.languageName + " Context Editor";
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    listener = new CEListener(this);

    JPanel nameBox = new JPanel();
    nameBox.setLayout(new BoxLayout(nameBox, BoxLayout.LINE_AXIS));
    name = new JTextField(ctxt.languageName, 28);
    name.setMaximumSize(new Dimension(225, 22));
    name.addFocusListener(
        new java.awt.event.FocusAdapter() {

          public void focusLost(java.awt.event.FocusEvent evt) {
            nameFocusLost(evt);
          }
        });

    JLabel nameLabel = new JLabel("Language Name: ");
    nameBox.add(nameLabel);
    nameBox.add(name);

    JPanel folderBox = new JPanel();
    folderBox.setLayout(new BoxLayout(folderBox, BoxLayout.LINE_AXIS));
    folder = new JTextField(ctxt.editDirectory);
    folder.setMaximumSize(new Dimension(225, 22));
    //        folder.addActionListener(listener);
    //        folder.setActionCommand("folder edit");
    folder.addFocusListener(
        new java.awt.event.FocusAdapter() {

          public void focusLost(java.awt.event.FocusEvent evt) {
            folderFocusLost(evt);
          }
        });

    JLabel folderLabel = new JLabel("SILK file folder: ");
    folderBox.add(folderLabel);
    folderBox.add(folder);

    JPanel nameFolderBox = new JPanel();
    nameFolderBox.setLayout(new BoxLayout(nameFolderBox, BoxLayout.PAGE_AXIS));
    nameBox.setAlignmentX(0.5f);
    nameFolderBox.add(nameBox);
    nameFolderBox.add(Box.createRigidArea(new Dimension(0, 4)));
    nameFolderBox.add(folderBox);
    nameFolderBox.setAlignmentX(0.5f);

    buildPopulationBox();

    JPanel btnBoxUDPs = new JPanel(), subBoxUDP = new JPanel();
    btnBoxUDPs.setLayout(new BoxLayout(btnBoxUDPs, BoxLayout.PAGE_AXIS));
    subBoxUDP.setLayout(new BoxLayout(subBoxUDP, BoxLayout.LINE_AXIS));
    int numUDPs = 0;
    if (ctxt.userDefinedProperties != null) {
      numUDPs = ctxt.userDefinedProperties.size();
    }
    String plur = "ies";
    if (numUDPs == 1) {
      plur = "y";
    }
    JLabel udpLabel = new JLabel("Has " + numUDPs + " User-Defined Propert" + plur);
    subBoxUDP.add(udpLabel);
    JButton addUDP = new JButton("Add UDP");
    addUDP.setActionCommand("add UDP");
    addUDP.addActionListener(listener);
    subBoxUDP.add(addUDP);
    btnBoxUDPs.add(subBoxUDP);
    if (numUDPs > 0) {
      Dimension sizer = new Dimension(250, 50);
      String[] udpMenu = genUDPMenu();
      UDPick = new JComboBox(udpMenu);
      UDPick.addActionListener(listener);
      UDPick.setActionCommand("view/edit UDP");
      UDPick.setMinimumSize(sizer);
      UDPick.setMaximumSize(sizer);
      UDPick.setBorder(
          BorderFactory.createTitledBorder(
              BorderFactory.createLineBorder(Color.blue), "View/Edit UDPs"));
      btnBoxUDPs.add(UDPick);
    } //  end of if-any-UDPs-exist

    JPanel domThs = new JPanel();
    domThs.setLayout(new BoxLayout(domThs, BoxLayout.PAGE_AXIS));
    domThs.setBorder(
        BorderFactory.createTitledBorder(
            BorderFactory.createLineBorder(Color.blue), "Kinship System Domain Theories"));
    domThs.setAlignmentX(0.5f);
    JPanel dtRefBtnBox = new JPanel();
    dtRefBtnBox.setLayout(new BoxLayout(dtRefBtnBox, BoxLayout.LINE_AXIS));
    dtRefBtnBox.setAlignmentX(0.0f);
    JLabel dtRefLabel = new JLabel("Terms of Reference ");
    dtRefBtnBox.add(dtRefLabel);
    if (ctxt.domTheoryRefExists()) {
      JButton dtRefEdit = new JButton("Edit Theory");
      dtRefEdit.setActionCommand("edit dtRef");
      dtRefEdit.addActionListener(listener);
      dtRefBtnBox.add(dtRefEdit);
      //            JButton dtRefDelete = new JButton("Delete Theory");
      //            dtRefDelete.setActionCommand("dtRef delete");
      //            dtRefDelete.addActionListener(listener);
      //            dtRefBtnBox.add(dtRefDelete);
    } //  end of if-dt-exists
    else { //  if does not exist
      JLabel dtRefNone = new JLabel("< None >");
      dtRefBtnBox.add(dtRefNone);
      //            JButton dtRefAdd = new JButton("Add Theory");
      //            dtRefAdd.setActionCommand("dtRef add");
      //            dtRefAdd.addActionListener(listener);
      //            dtRefBtnBox.add(dtRefAdd);
    } //  end of does-not-exist
    domThs.add(dtRefBtnBox);

    JPanel dtAddrBtnBox = new JPanel();
    dtAddrBtnBox.setLayout(new BoxLayout(dtAddrBtnBox, BoxLayout.LINE_AXIS));
    dtAddrBtnBox.setAlignmentX(0.0f);
    JLabel dtAddrLabel = new JLabel("Terms of Address ");
    dtAddrBtnBox.add(dtAddrLabel);
    if (ctxt.domTheoryAdrExists()) {
      JButton dtAddrEdit = new JButton("Edit Theory");
      dtAddrEdit.setActionCommand("edit dtAddr");
      dtAddrEdit.addActionListener(listener);
      dtAddrBtnBox.add(dtAddrEdit);
      //            JButton dtAddrViewList = new JButton("Delete Theory");
      //            dtAddrViewList.setActionCommand("dtAddr delete");
      //            dtAddrViewList.addActionListener(listener);
      //            dtAddrBtnBox.add(dtAddrViewList);
    } //  end of if-dt-exists
    else { //  if does not exist
      JLabel dtAddrNone = new JLabel("< None >");
      dtAddrBtnBox.add(dtAddrNone);
      //            JButton dtAddrAdd = new JButton("Add Theory");
      //            dtAddrAdd.setActionCommand("dtAddr add");
      //            dtAddrAdd.addActionListener(listener);
      //            dtAddrBtnBox.add(dtAddrAdd);
    } //  end of does-not-exist
    domThs.add(dtAddrBtnBox);
    // End of the left hand portion
    // Right hand portion follows. it is narrower.

    JPanel polyBox = new JPanel();
    polyBox.setLayout(new BoxLayout(polyBox, BoxLayout.PAGE_AXIS));
    polyBox.setAlignmentX(0.5f);
    JLabel polyLabelA = new JLabel("Polygamy");
    JLabel polyLabelB = new JLabel("Permitted?");
    JRadioButton yesPoly = new JRadioButton("Yes");
    yesPoly.setActionCommand("polygamy yes");
    yesPoly.addActionListener(listener);
    JRadioButton noPoly = new JRadioButton("No");
    noPoly.setActionCommand("polygamy no");
    noPoly.addActionListener(listener);
    if (cntxt.polygamyPermit) {
      yesPoly.setSelected(true);
    } else {
      noPoly.setSelected(true);
    }
    ButtonGroup polyBtns = new ButtonGroup();
    polyBtns.add(yesPoly);
    polyBtns.add(noPoly);
    polyBox.add(polyLabelA);
    polyBox.add(polyLabelB);
    polyBox.add(yesPoly);
    polyBox.add(noPoly);

    JPanel matrixBox = new JPanel();
    matrixBox.setLayout(new BoxLayout(matrixBox, BoxLayout.PAGE_AXIS));
    matrixBox.setAlignmentX(0.5f);
    JLabel matrixLabelA = new JLabel("Kin Term Matrix");
    JLabel matrixLabelC = new JLabel(ctxt.indSerNumGen + " rows");
    JLabel matrixLabelD = new JLabel(ctxt.ktm.numberOfKinTerms() + " terms");
    matrixLabelA.setAlignmentX(0.5f);
    matrixLabelC.setAlignmentX(0.5f);
    matrixLabelD.setAlignmentX(0.5f);
    JButton matrixEditBtn = new JButton("Edit Matrix");
    matrixEditBtn.setEnabled(false);
    matrixEditBtn.setActionCommand("edit matrix");
    matrixEditBtn.addActionListener(listener);
    matrixEditBtn.setAlignmentX(0.5f);
    matrixBox.add(matrixLabelA);
    matrixBox.add(matrixLabelC);
    matrixBox.add(matrixLabelD);
    matrixBox.add(matrixEditBtn);

    JPanel distinctBox = new JPanel();
    distinctBox.setLayout(new BoxLayout(distinctBox, BoxLayout.PAGE_AXIS));
    distinctBox.setAlignmentX(0.5f);
    JLabel distinctLabelA = new JLabel("Distinct Terms");
    JLabel distinctLabelB = new JLabel("of Address");
    distinctLabelA.setAlignmentX(0.5f);
    distinctLabelB.setAlignmentX(0.5f);
    JRadioButton yesDistinct = new JRadioButton("Yes");
    yesDistinct.setActionCommand("distinct yes");
    yesDistinct.addActionListener(listener);
    JRadioButton noDistinct = new JRadioButton("No");
    noDistinct.setActionCommand("distinct no");
    noDistinct.addActionListener(listener);
    yesDistinct.setAlignmentX(0.5f);
    noDistinct.setAlignmentX(0.5f);
    if (ctxt.distinctAdrTerms) {
      yesDistinct.setSelected(true);
    } else {
      noDistinct.setSelected(true);
    }
    ButtonGroup distinctBtns = new ButtonGroup();
    distinctBtns.add(yesDistinct);
    distinctBtns.add(noDistinct);
    distinctBox.add(distinctLabelA);
    distinctBox.add(distinctLabelB);
    distinctBox.add(yesDistinct);
    distinctBox.add(noDistinct);

    /*
     * NOTE: It should be possible to put all these elements directly into
     * the ContentPane. But that doesn't work; the layout is truly ugly and
     * stuff gets stacked on top of other stuff. What works is to put
     * everything into a JPanel with BoxLayout. Then put the JPanel into
     * ContentPane.
     */
    JPanel leftCol = new JPanel();
    leftCol.setLayout(new BoxLayout(leftCol, BoxLayout.PAGE_AXIS));
    leftCol.add(nameFolderBox);
    leftCol.add(Box.createRigidArea(new Dimension(0, 4)));
    leftCol.add(populationBox);
    leftCol.add(Box.createRigidArea(new Dimension(0, 8)));
    leftCol.add(btnBoxUDPs);
    leftCol.add(Box.createRigidArea(new Dimension(0, 8)));
    leftCol.add(domThs);
    leftCol.add(new JLabel(" "));

    JPanel rightCol = new JPanel();
    rightCol.setLayout(new BoxLayout(rightCol, BoxLayout.PAGE_AXIS));
    rightCol.setBorder(
        BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.blue), "Options"));
    rightCol.add(Box.createRigidArea(new Dimension(0, 20)));
    rightCol.add(polyBox);
    rightCol.add(Box.createRigidArea(new Dimension(0, 20)));
    rightCol.add(matrixBox);
    int high = (numUDPs > 0 ? 120 : 20);
    rightCol.add(Box.createRigidArea(new Dimension(0, high)));
    rightCol.add(distinctBox);

    JPanel commentBox = new JPanel();
    commentBox.setLayout(new BoxLayout(commentBox, BoxLayout.PAGE_AXIS));
    commentBox.setBorder(
        BorderFactory.createTitledBorder(
            BorderFactory.createLineBorder(Color.blue), "Notes on this culture:"));
    JScrollPane commentsPane = new JScrollPane();
    comments = new JTextArea();
    comments.setColumns(20);
    comments.setEditable(true);
    comments.setRows(3);
    comments.setText(PersonPanel.restoreLineBreaks(ctxt.comments));
    comments.getDocument().addDocumentListener(new CommentListener());
    commentsPane.setViewportView(comments);
    commentBox.add(commentsPane);

    JPanel guts = new JPanel(); // Holds the guts of this window
    guts.setLayout(new BoxLayout(guts, BoxLayout.LINE_AXIS));
    guts.add(leftCol);
    guts.add(Box.createRigidArea(new Dimension(10, 4)));
    guts.add(rightCol);

    JPanel wholeThing = new JPanel();
    wholeThing.setLayout(new BoxLayout(wholeThing, BoxLayout.PAGE_AXIS));
    wholeThing.add(Box.createRigidArea(new Dimension(0, 4)));
    wholeThing.add(guts);
    wholeThing.add(Box.createRigidArea(new Dimension(0, 8)));
    wholeThing.add(commentBox);
    wholeThing.add(Box.createRigidArea(new Dimension(0, 4)));

    getContentPane().add(wholeThing);

    addInternalFrameListener(this);
    setSize(600, 620);
    setVisible(true);
  } //  end of ContextEditor constructor