Example #1
0
  public LigandSideBar(LXDocumentFrame mainFrame) {
    super();

    final StructureModel model = LigandExplorer.sgetModel();

    if (!model.hasStructures()) {
      this.setBackground(LXDocumentFrame.sidebarColor);
      this.setLayout(new BorderLayout());

      final JPanel pdbPanel = new JPanel();
      pdbPanel.setLayout(new FlowLayout());
      pdbPanel.setBackground(LXDocumentFrame.sidebarColor);

      final JLabel pdbLabel = new JLabel("PDB id");
      pdbLabel.setFont(pdbLabel.getFont().deriveFont(Font.BOLD));
      pdbLabel.setBackground(LXDocumentFrame.sidebarColor);

      mainFrame.getPdbIdList().setBackground(LXDocumentFrame.sidebarColor);

      pdbPanel.add(pdbLabel);
      pdbPanel.add(mainFrame.getPdbIdList());

      this.add(pdbPanel, BorderLayout.NORTH);

    } else {
      this.ligandList = this.getLigandList(model.getStructures().get(0));

      final Comparator<Chain> chainComparator =
          new Comparator<Chain>() {
            public int compare(Chain c1, Chain c2) {
              return c1.getAuthorChainId().compareTo(c2.getAuthorChainId());
            }
          };
      Collections.sort(ligandList, chainComparator);

      this.setLayout(null);

      final JLabel centerView = new JLabel("Choose a ligand to analyze...");
      centerView.setFont(centerView.getFont().deriveFont(Font.BOLD + Font.ITALIC));
      this.add(centerView);

      if (this.ligandList.size() > 0) {
        DefaultMutableTreeNode root = new DefaultMutableTreeNode("Ligands:");
        ligandJList = new JTree(root);
        ligandJList
            .getSelectionModel()
            .setSelectionMode(TreeSelectionModel.CONTIGUOUS_TREE_SELECTION);
        ligandJList.setCellRenderer(new LigandTreeCellRenderer());
        ligandJList.setExpandsSelectedPaths(true);
        ligandJList.setRootVisible(false);
        ligandJList.setShowsRootHandles(true);

        String chainId = "";
        DefaultMutableTreeNode chainNode = null;
        DefaultMutableTreeNode birdNode = null;
        Bird prevBird = null;

        for (Chain chain : ligandList) {
          // create new node only if chain id is different from previous chain id
          if (!chain.getAuthorChainId().equals(chainId)) {
            //		chainNode = new DefaultMutableTreeNode(chain);
            chainNode = new DefaultMutableTreeNode(chain.getAuthorChainId());
            root.add(chainNode);
            chainId = chain.getAuthorChainId();
          }
          if (chain.getClassification() == Residue.Classification.LIGAND) {
            for (Residue residue : chain.getResidues()) {
              chainNode.add(new DefaultMutableTreeNode(residue));
            }
          } else if (chain.getClassification() == Residue.Classification.BIRD) {
            Bird currBird = chain.getBird();
            if (prevBird == null && currBird != null) {
              birdNode = new DefaultMutableTreeNode(chain);
              chainNode.add(birdNode);
              prevBird = currBird;
            } else if (!prevBird.isSameInstance(currBird)) {
              birdNode = new DefaultMutableTreeNode(chain);
              chainNode.add(birdNode);
              prevBird = currBird;
            }
            for (Residue residue : chain.getResidues()) {
              birdNode.add(new DefaultMutableTreeNode(residue));
            }
          } else if (chain.hasModifiedResidues()) {
            for (Residue residue : chain.getModifiedResidues()) {
              chainNode.add(new DefaultMutableTreeNode(residue));
            }
          }
        }

        ligandJList
            .getSelectionModel()
            .addTreeSelectionListener(
                new TreeSelectionListener() {
                  public void valueChanged(TreeSelectionEvent e) {
                    applyButton.doClick();
                    Structure structure = AppBase.sgetModel().getStructures().get(0);
                    if (structure.getStructureMap().getSurfaceCount() > 0) {
                      LigandExplorer.sgetGlGeometryViewer().ligandViewWithSurface(structure);
                    } else {
                      LigandExplorer.sgetGlGeometryViewer().ligandView(structure);
                    }
                  }
                });

        ligandScroller = new JScrollPane(this.ligandJList);

        add(ligandScroller);
      } else centerView.setText("No ligands in this structure");

      final JLabel displayView = new JLabel("Choose interactions & thresholds...");
      displayView.setFont(displayView.getFont().deriveFont(Font.BOLD + Font.ITALIC));
      this.add(displayView);

      final JCheckBox hydrophilicBox = new JCheckBox(InteractionConstants.hydrogenBondType);
      final LegendPanel hydrophilicPanel =
          new LegendPanel(InteractionConstants.hydrogenBondColor, LXDocumentFrame.sidebarColor);
      final FloatLimitField philicFLF2 = new FloatLimitField("3.3");
      this.add(hydrophilicBox);
      this.add(philicFLF2);
      this.add(hydrophilicPanel);

      final JCheckBox hydrophobicBox = new JCheckBox(InteractionConstants.hydrophobicType);
      final LegendPanel hydrophobicPanel =
          new LegendPanel(InteractionConstants.hydrophobicBondColor, LXDocumentFrame.sidebarColor);
      final FloatLimitField phobicFLF2 = new FloatLimitField("3.9");
      this.add(hydrophobicBox);
      this.add(phobicFLF2);
      this.add(hydrophobicPanel);

      final JCheckBox l_h2o_pBox = new JCheckBox(InteractionConstants.waterMediatedType);
      l_h2o_pBox.setBackground(LXDocumentFrame.sidebarColor);
      final LegendPanel l_h2o_pPanel =
          new LegendPanel(InteractionConstants.waterMediatedColor, LXDocumentFrame.sidebarColor);
      l_h2o_pBox.setBackground(LXDocumentFrame.sidebarColor);
      final FloatLimitField l_h2o_pFLF2 = new FloatLimitField("3.3");
      this.add(l_h2o_pBox);
      this.add(l_h2o_pFLF2);
      this.add(l_h2o_pPanel);

      final JCheckBox otherBox = new JCheckBox(InteractionConstants.metalInteractionType);
      final LegendPanel otherPanel =
          new LegendPanel(InteractionConstants.metalInteractionColor, LXDocumentFrame.sidebarColor);
      final FloatLimitField otherFLF2 = new FloatLimitField("3.5");
      this.add(otherBox);
      this.add(otherFLF2);
      this.add(otherPanel);

      final JCheckBox neighborBox = new JCheckBox(InteractionConstants.neighborInteractionType);
      final FloatLimitField neighborFLF1 = new FloatLimitField("4.0");
      this.add(neighborBox);
      this.add(neighborFLF1);

      // new: added this separator
      final JSeparator separator = new JSeparator();
      this.add(separator);

      final JCheckBox distanceBox = new JCheckBox("Label interactions by distance");
      distanceBox.setBackground(LXDocumentFrame.sidebarColor);
      distanceBox.setSelected(true);
      this.add(distanceBox);

      //			System.out.println("Adding BindingSiteSurfacePanel");
      final JPanel surfacePanel = new BindingSiteSurfacePanel(hasMacromoleculeChain());
      surfacePanel.setBackground(LXDocumentFrame.sidebarColor);
      this.add(surfacePanel);

      // this button should eventually be removed. Its still used
      // to fire some update events
      applyButton = new JButton("Apply");
      this.add(applyButton);

      this.setLayout(
          new LayoutManager() {
            public void addLayoutComponent(String arg0, Component arg1) {}

            private Dimension layoutSize = null;

            public void layoutContainer(Container parent) {
              final int visualBuffer = 3;
              Insets parentInsets = parent.getInsets();

              if (ligandList == null || ligandList.size() == 0) {
                Dimension preferred = centerView.getPreferredSize();
                centerView.setBounds(
                    parentInsets.left + visualBuffer,
                    parentInsets.top + visualBuffer,
                    preferred.width,
                    preferred.height);
              } else {
                Dimension step1Preferred = centerView.getPreferredSize();
                Dimension step2Preferred = displayView.getPreferredSize();
                ;
                Dimension hydrophilicBoxPreferred = hydrophilicBox.getPreferredSize();
                Dimension hydrophobicBoxPreferred = hydrophobicBox.getPreferredSize();
                Dimension l_h2o_pBoxPreferred = l_h2o_pBox.getPreferredSize();
                Dimension otherBoxPreferred = otherBox.getPreferredSize();
                Dimension neighborBoxPreferred = neighborBox.getPreferredSize();
                Dimension distancePreferred = distanceBox.getPreferredSize();
                Dimension hydrophilicFLF2Preferred = philicFLF2.getPreferredSize();
                Dimension hydrophobicFLF2Preferred = phobicFLF2.getPreferredSize();
                Dimension l_h2o_pFLF2Preferred = l_h2o_pFLF2.getPreferredSize();
                Dimension otherFLF2Preferred = otherFLF2.getPreferredSize();
                Dimension neighborFLF1Preferred = neighborFLF1.getPreferredSize();
                Dimension separatorPreferred = separator.getPreferredSize();
                Dimension surfacePanelPreferred = surfacePanel.getPreferredSize();

                int parentHeight = parent.getHeight();
                int parentWidth = parent.getWidth();
                int fullWidth =
                    parentWidth - parentInsets.left - parentInsets.right - visualBuffer * 2;

                int listHeight =
                    parentHeight
                        - parentInsets.top
                        - parentInsets.bottom
                        - (step1Preferred.height
                            + step2Preferred.height
                            + hydrophilicBoxPreferred.height
                            + hydrophobicBoxPreferred.height
                            + l_h2o_pBoxPreferred.height
                            + otherBoxPreferred.height
                            + neighborBoxPreferred.height
                            + separatorPreferred.height
                            + distancePreferred.height
                            + surfacePanelPreferred.height
                            + visualBuffer * 13);

                int curY = parentInsets.top + visualBuffer;
                int curX = parentInsets.left + visualBuffer;
                int maxWidth = 0;

                centerView.setBounds(curX, curY, step1Preferred.width, step1Preferred.height);
                curY += step1Preferred.height + visualBuffer;
                maxWidth = step1Preferred.width;

                ligandScroller.setBounds(curX, curY, fullWidth, listHeight);
                curY += listHeight + visualBuffer;

                displayView.setBounds(curX, curY, step2Preferred.width, step2Preferred.height);
                curY += step2Preferred.height + visualBuffer;
                maxWidth = Math.max(maxWidth, step2Preferred.width);

                int maxCheckboxWidth = 0;
                int hydrophilicBoxStartY = curY;
                hydrophilicBox.setBounds(
                    curX, curY, hydrophilicBoxPreferred.width, hydrophilicBoxPreferred.height);
                curY += hydrophilicBoxPreferred.height + visualBuffer;
                maxWidth = Math.max(maxWidth, hydrophilicBoxPreferred.width);
                maxCheckboxWidth = Math.max(maxCheckboxWidth, hydrophilicBoxPreferred.width);

                int hydrophobicBoxStartY = curY;
                hydrophobicBox.setBounds(
                    curX, curY, hydrophobicBoxPreferred.width, hydrophobicBoxPreferred.height);
                curY += hydrophobicBoxPreferred.height + visualBuffer;
                maxWidth = Math.max(maxWidth, hydrophobicBoxPreferred.width);
                maxCheckboxWidth = Math.max(maxCheckboxWidth, hydrophobicBoxPreferred.width);

                int l_h2o_pBoxStartY = curY;
                l_h2o_pBox.setBounds(
                    curX, curY, l_h2o_pBoxPreferred.width, l_h2o_pBoxPreferred.height);
                curY += l_h2o_pBoxPreferred.height + visualBuffer;
                maxWidth = Math.max(maxWidth, l_h2o_pBoxPreferred.width);
                maxCheckboxWidth = Math.max(maxCheckboxWidth, l_h2o_pBoxPreferred.width);

                int otherBoxStartY = curY;
                otherBox.setBounds(curX, curY, otherBoxPreferred.width, otherBoxPreferred.height);
                curY += otherBoxPreferred.height + visualBuffer;
                maxWidth = Math.max(maxWidth, otherBoxPreferred.width);
                maxCheckboxWidth = Math.max(maxCheckboxWidth, otherBoxPreferred.width);

                int neighborBoxStartY = curY;
                neighborBox.setBounds(
                    curX, curY, neighborBoxPreferred.width, neighborBoxPreferred.height);
                curY += neighborBoxPreferred.height + visualBuffer;
                maxWidth = Math.max(maxWidth, neighborBoxPreferred.width);
                maxCheckboxWidth = Math.max(maxCheckboxWidth, neighborBoxPreferred.width);

                // now align the constraint boxes to a grid defined by the check boxes.
                final int legendWidth = 50;
                curX += maxCheckboxWidth + visualBuffer * 2;
                neighborFLF1.setBounds(
                    curX,
                    neighborBoxStartY,
                    neighborFLF1Preferred.width,
                    neighborFLF1Preferred.height);
                philicFLF2.setBounds(
                    curX,
                    hydrophilicBoxStartY,
                    hydrophilicFLF2Preferred.width,
                    hydrophilicFLF2Preferred.height);
                phobicFLF2.setBounds(
                    curX,
                    hydrophobicBoxStartY,
                    hydrophobicFLF2Preferred.width,
                    hydrophobicFLF2Preferred.height);
                l_h2o_pFLF2.setBounds(
                    curX,
                    l_h2o_pBoxStartY,
                    l_h2o_pFLF2Preferred.width,
                    l_h2o_pFLF2Preferred.height);
                otherFLF2.setBounds(
                    curX, otherBoxStartY, otherFLF2Preferred.width, otherFLF2Preferred.height);
                curX += philicFLF2.getWidth() + visualBuffer;
                hydrophilicPanel.setBounds(
                    curX, hydrophilicBoxStartY, legendWidth, hydrophilicFLF2Preferred.height);
                hydrophobicPanel.setBounds(
                    curX, hydrophobicBoxStartY, legendWidth, hydrophobicFLF2Preferred.height);
                l_h2o_pPanel.setBounds(
                    curX, l_h2o_pBoxStartY, legendWidth, l_h2o_pFLF2Preferred.height);
                otherPanel.setBounds(curX, otherBoxStartY, legendWidth, otherFLF2Preferred.height);
                curX = parentInsets.left + visualBuffer;

                separator.setBounds(
                    curX, curY, separatorPreferred.width, separatorPreferred.height);
                curY += separatorPreferred.height + 3 * visualBuffer;
                maxWidth = Math.max(maxWidth, separatorPreferred.width);

                distanceBox.setBounds(
                    curX, curY, distancePreferred.width, distancePreferred.height);
                curY += distancePreferred.height + visualBuffer;
                maxWidth = Math.max(maxWidth, distancePreferred.width);

                surfacePanel.setBounds(
                    curX, curY, surfacePanelPreferred.width, surfacePanelPreferred.height);
                curY += surfacePanelPreferred.height + visualBuffer;
                maxWidth = Math.max(maxWidth, surfacePanelPreferred.width);

                //							this.layoutSize.width = maxWidth + parentInsets.left + parentInsets.right +
                // visualBuffer * 2;

                // TODO check width on Mac OSX
                this.layoutSize.width =
                    maxWidth + parentInsets.left + parentInsets.right + visualBuffer * 2;
              }
            }

            public Dimension minimumLayoutSize(Container parent) {
              if (this.layoutSize == null) {
                this.layoutSize = new Dimension();
                this.layoutContainer(parent);
              }
              return this.layoutSize;
            }

            public Dimension preferredLayoutSize(Container parent) {
              if (this.layoutSize == null) {
                this.layoutSize = new Dimension();
                this.layoutContainer(parent);
              }
              return this.layoutSize;
            }

            public void removeLayoutComponent(Component comp) {}
          });

      // set colors and initial state
      this.setBackground(LXDocumentFrame.sidebarColor);
      hydrophilicBox.setBackground(LXDocumentFrame.sidebarColor);
      hydrophilicBox.setSelected(false);
      hydrophobicBox.setBackground(LXDocumentFrame.sidebarColor);
      hydrophobicBox.setSelected(false);
      otherBox.setBackground(LXDocumentFrame.sidebarColor);
      otherBox.setSelected(false);
      neighborBox.setBackground(LXDocumentFrame.sidebarColor);
      neighborBox.setSelected(false);

      // separator is not visible, why ??
      separator.setBackground(Color.BLACK);
      separator.setForeground(Color.BLACK);
      separator.setVisible(true);

      interactionListener =
          new InteractionListener(
              l_h2o_pBox,
              hydrophilicBox,
              hydrophobicBox,
              otherBox,
              neighborBox,
              distanceBox,
              l_h2o_pFLF2,
              philicFLF2,
              phobicFLF2,
              otherFLF2,
              neighborFLF1);

      applyButton.addActionListener(interactionListener);
      hydrophilicBox.addActionListener(interactionListener);
      hydrophobicBox.addActionListener(interactionListener);
      l_h2o_pBox.addActionListener(interactionListener);
      otherBox.addActionListener(interactionListener);
      neighborBox.addActionListener(interactionListener);
      distanceBox.addActionListener(interactionListener);

      // add action listener to the distance threshold text boxes
      l_h2o_pFLF2.addActionListener(interactionListener);
      philicFLF2.addActionListener(interactionListener);
      phobicFLF2.addActionListener(interactionListener);
      otherFLF2.addActionListener(interactionListener);
      neighborFLF1.addActionListener(interactionListener);
      ;
    }
  }
Example #2
0
    public void actionPerformed(final ActionEvent ae) {
      final boolean saveInteractionsFlag = LigandExplorer.saveInteractionsFlag;
      LigandExplorer.saveInteractionsFlag = false;

      final StructureModel model = LigandExplorer.sgetModel();
      //			final LXGlGeometryViewer glViewer = LigandExplorer.sgetGlGeometryViewer();

      // **J check to make sure all text fields have three
      // characters in them; if not, make the correction
      String philicText2 = philicFLF2.getText();
      switch (philicText2.length()) {
        case 0:
          philicText2 = "0.0";
          philicFLF2.setText(philicText2);
          break;
        case 1:
          philicText2 = philicText2 + ".0";
          philicFLF2.setText(philicText2);
          break;
        case 2:
          philicText2 = philicText2 + "0";
          philicFLF2.setText(philicText2);
      }

      String phobicText2 = phobicFLF2.getText();
      switch (phobicText2.length()) {
        case 0:
          phobicText2 = "0.0";
          phobicFLF2.setText(phobicText2);
          break;
        case 1:
          phobicText2 = phobicText2 + ".0";
          phobicFLF2.setText(phobicText2);
          break;
        case 2:
          phobicText2 = phobicText2 + "0";
          phobicFLF2.setText(phobicText2);
      }

      String l_h2o_pText2 = l_h2o_pflf2.getText();
      switch (l_h2o_pText2.length()) {
        case 0:
          l_h2o_pText2 = "0.0";
          l_h2o_pflf2.setText(l_h2o_pText2);
          break;
        case 1:
          l_h2o_pText2 = l_h2o_pText2 + ".0";
          l_h2o_pflf2.setText(l_h2o_pText2);
          break;
        case 2:
          l_h2o_pText2 = l_h2o_pText2 + "0";
          l_h2o_pflf2.setText(l_h2o_pText2);
      }

      String otherText2 = otherFLF2.getText();
      switch (otherText2.length()) {
        case 0:
          otherText2 = "0.0";
          otherFLF2.setText(otherText2);
          break;
        case 1:
          otherText2 = otherText2 + ".0";
          otherFLF2.setText(otherText2);
          break;
        case 2:
          otherText2 = otherText2 + "0";
          otherFLF2.setText(otherText2);
      }
      String neighborText1 = neighborFLF1.getText();
      switch (neighborText1.length()) {
        case 0:
          neighborText1 = "0.0";
          neighborFLF1.setText(neighborText1);
          break;
        case 1:
          neighborText1 = neighborText1 + ".0";
          neighborFLF1.setText(neighborText1);
          break;
        case 2:
          neighborText1 = neighborText1 + "0";
          neighborFLF1.setText(neighborText1);
      }

      if (model.hasStructures()) {
        final Structure structure = model.getStructures().get(0);

        final TreePath treeSelection[] = ligandJList.getSelectionPaths();
        if (treeSelection != null) {
          Residue residues[] = null;
          DefaultMutableTreeNode node =
              (DefaultMutableTreeNode) treeSelection[0].getLastPathComponent();
          StructureComponent nodeValue = (StructureComponent) node.getUserObject();
          if (nodeValue instanceof Chain) {
            assert (treeSelection.length == 1);
            Chain chain = (Chain) nodeValue;
            if (chain.getBird() != null) {
              residues = getBirdResidues(structure, chain);
            } else {
              residues = new Residue[chain.getResidueCount()];
              for (int ix = 0; ix < chain.getResidueCount(); ix++) {
                residues[ix] = chain.getResidue(ix);
              }
            }
          } else if (nodeValue instanceof Residue) {
            int ix = 0;
            residues = new Residue[treeSelection.length];

            for (TreePath path : treeSelection) {
              node = (DefaultMutableTreeNode) path.getLastPathComponent();
              nodeValue = (StructureComponent) node.getUserObject();
              assert (nodeValue instanceof Residue);
              residues[ix] = (Residue) nodeValue;
              ix++;
            }
          }
          if (residues != null) {
            LigandExplorer.sgetSceneController().setLigandResidues(residues);
          }
        }

        final float philicf2 = Float.parseFloat(philicText2);
        final float phobicf2 = Float.parseFloat(phobicText2);
        final float l_h2o_pf2 = Float.parseFloat(l_h2o_pText2);
        final float otherf2 = Float.parseFloat(otherText2);
        final float neighborf1 = Float.parseFloat(neighborText1);

        // Thread runner = new Thread() {
        //
        // public void run() {
        try {
          LigandExplorer.sgetSceneController()
              .processLeftPanelEvent(
                  structure,
                  l_h2o_pf2,
                  box.isSelected(),
                  hydrogenBondBox.isSelected(),
                  philicf2,
                  hydrophobicBox.isSelected(),
                  phobicf2,
                  metalInteractionBox.isSelected(),
                  otherf2,
                  distanceBox.isSelected(),
                  neighborf1,
                  neighborBox.isSelected(),
                  saveInteractionsFlag);
        } catch (final Exception e) {
          e.printStackTrace();
          Status.progress(
              100, "Error while processing your options...Please select different options");
        }
        // }
        // };
        // runner.start();

        // remove current surfaces from display list and add them again to ensure
        // transparent surfaces are drawn on top of the interactions
        LigandExplorer.sgetGlGeometryViewer().surfaceRemoved(structure);
        LigandExplorer.sgetGlGeometryViewer().surfaceAdded(structure);
      } else {
        // add a display message here, ask user to load a
        // structure, do this later
      }
    }