Пример #1
0
  private void buildUI() {
    treeModel = new SoapUITreeModel(workspace);

    mainTree = new NavigatorTree(treeModel);
    mainTree.setRootVisible(true);
    mainTree.setExpandsSelectedPaths(true);
    mainTree.setScrollsOnExpand(true);
    mainTree.setToggleClickCount(0);
    mainTree.addMouseListener(new TreeMouseListener());
    mainTree.addTreeSelectionListener(new InternalTreeSelectionListener());
    mainTree.setCellRenderer(new SoapUITreeNodeRenderer());
    mainTree.setBorder(null);
    mainTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    mainTree.addKeyListener(new TreeKeyListener());

    add(new JScrollPane(mainTree), BorderLayout.CENTER);
    add(buildToolbar(), BorderLayout.NORTH);
    setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
  }
  /** Populate tree */
  private void populateTree() {

    // create model
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("My Computer");
    DefaultTreeModel model = new DefaultTreeModel(rootNode, true);

    // add root drives
    File rootDrives[] = File.listRoots();
    DefaultMutableTreeNode driveNodes[] = new DefaultMutableTreeNode[rootDrives.length];
    for (int i = 0; i < rootDrives.length; ++i) {
      driveNodes[i] = new DefaultMutableTreeNode(rootDrives[i]);
      rootNode.add(driveNodes[i]);
    }

    tree.setModel(model);
    tree.setRootVisible(false);
    tree.setExpandsSelectedPaths(true);
    tree.addTreeWillExpandListener(this);
    tree.setCellRenderer(new DirTreeCellRenderer());
    tree.addTreeSelectionListener(this);
  }
Пример #3
0
  public void initializeGUI() {
    setTitle(frameTitle);
    setSize(detailsFrameXsize, detailsFrameYsize);
    setLocation(detailsFrameXlocation, detailsFrameYlocation);
    treemodel = new DefaultTreeModel(new DefaultMutableTreeNode("LSM File Information"));
    detailsTree = new JTree(treemodel);
    detailsTree.putClientProperty("JTree.lineStyle", "Angled");
    detailsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    detailsTree.setShowsRootHandles(true);
    tablemodel = new TreeTableModel();
    table = new JTable(tablemodel);
    table.setCellSelectionEnabled(true);
    JScrollPane treepane = new JScrollPane(detailsTree);
    JScrollPane detailspane = new JScrollPane(table);
    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, treepane, detailspane);
    splitPane.setBorder(null);
    splitPane.setOneTouchExpandable(true);
    splitPane.setDividerLocation(300);
    Dimension minimumSize = new Dimension(WIDTH, HEIGHT - 50);
    treepane.setMinimumSize(minimumSize);
    detailspane.setMinimumSize(minimumSize);
    exitButton = new JButton(new ImageIcon(getClass().getResource("images/exit.png")));
    exitButton.setToolTipText("Close this window");
    searchButton = new JButton(new ImageIcon(getClass().getResource("images/find.png")));
    searchButton.setToolTipText("Find tag, property or value");
    filterButton = new JToggleButton(new ImageIcon(getClass().getResource("images/filter.png")));
    filterButton.setToolTipText("Filter unused tags");
    dumpButton = new JButton(new ImageIcon(getClass().getResource("images/dump.png")));
    dumpButton.setToolTipText("Dump data to textwindow, saving to text file is possible");
    xmlButton = new JButton(new ImageIcon(getClass().getResource("images/xml.png")));
    xmlButton.setToolTipText("Dump xml data to textwindow, saving to text file is possible");

    searchTF = new JTextField("");
    detailsTreePopupMenu = new JPopupMenu();
    expandAllItem =
        new JMenuItem("Expand all", new ImageIcon(getClass().getResource("images/plus.png")));
    collapseAllItem =
        new JMenuItem("Collapse all", new ImageIcon(getClass().getResource("images/minus.png")));
    filterCBItem =
        new JCheckBoxMenuItem(
            "Filtered", new ImageIcon(getClass().getResource("images/filter.png")));
    detailsTreePopupMenu.add(expandAllItem);
    detailsTreePopupMenu.add(collapseAllItem);
    detailsTreePopupMenu.add(new JSeparator());
    detailsTreePopupMenu.add(filterCBItem);
    detailsTreePopupMenu.setOpaque(true);
    detailsTree.add(detailsTreePopupMenu);
    detailsTree.setExpandsSelectedPaths(true);
    toolBar = new JToolBar();

    toolBar.add(exitButton);
    toolBar.add(dumpButton);
    toolBar.add(xmlButton);
    toolBar.add(filterButton);
    toolBar.add(new JSeparator());
    toolBar.add(new JLabel("  Search: "));
    toolBar.add(searchTF);
    toolBar.add(searchButton);

    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(toolBar, BorderLayout.NORTH);
    getContentPane().add(splitPane, BorderLayout.CENTER);
    // filterCBItem.setSelected(true);
    // filterButton.setSelected(true);
    pack();
    centerWindow();
    setListeners();
  }
Пример #4
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);
      ;
    }
  }
  /**
   * Constructs a X509 certificate panel.
   *
   * @param certificates <tt>X509Certificate</tt> objects
   */
  public X509CertificatePanel(Certificate[] certificates) {
    setLayout(new BorderLayout(5, 5));

    // Certificate chain list
    TransparentPanel topPanel = new TransparentPanel(new BorderLayout());
    topPanel.add(
        new JLabel(
            "<html><body><b>"
                + R.getI18NString("service.gui.CERT_INFO_CHAIN")
                + "</b></body></html>"),
        BorderLayout.NORTH);

    DefaultMutableTreeNode top = new DefaultMutableTreeNode();
    DefaultMutableTreeNode previous = top;
    for (int i = certificates.length - 1; i >= 0; i--) {
      Certificate cert = certificates[i];
      DefaultMutableTreeNode next = new DefaultMutableTreeNode(cert);
      previous.add(next);
      previous = next;
    }
    JTree tree = new JTree(top);
    tree.setBorder(new BevelBorder(BevelBorder.LOWERED));
    tree.setRootVisible(false);
    tree.setExpandsSelectedPaths(true);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    tree.setCellRenderer(
        new DefaultTreeCellRenderer() {

          @Override
          public Component getTreeCellRendererComponent(
              JTree tree,
              Object value,
              boolean sel,
              boolean expanded,
              boolean leaf,
              int row,
              boolean hasFocus) {
            JLabel component =
                (JLabel)
                    super.getTreeCellRendererComponent(
                        tree, value, sel, expanded, leaf, row, hasFocus);
            if (value instanceof DefaultMutableTreeNode) {
              Object o = ((DefaultMutableTreeNode) value).getUserObject();
              if (o instanceof X509Certificate) {
                component.setText(getSimplifiedName((X509Certificate) o));
              } else {
                // We don't know how to represent this certificate type,
                // let's use the first 20 characters
                String text = o.toString();
                if (text.length() > 20) {
                  text = text.substring(0, 20);
                }
                component.setText(text);
              }
            }
            return component;
          }
        });
    tree.getSelectionModel()
        .addTreeSelectionListener(
            new TreeSelectionListener() {

              @Override
              public void valueChanged(TreeSelectionEvent e) {
                valueChangedPerformed(e);
              }
            });
    tree.setSelectionPath(
        new TreePath((((DefaultTreeModel) tree.getModel()).getPathToRoot(previous))));
    topPanel.add(tree, BorderLayout.CENTER);

    add(topPanel, BorderLayout.NORTH);

    // Certificate details pane
    Caret caret = infoTextPane.getCaret();
    if (caret instanceof DefaultCaret) {
      ((DefaultCaret) caret).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
    }

    /*
     * Make JEditorPane respect our default font because we will be using it
     * to just display text.
     */
    infoTextPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);

    infoTextPane.setOpaque(false);
    infoTextPane.setEditable(false);
    infoTextPane.setContentType("text/html");
    infoTextPane.setText(toString(certificates[0]));

    final JScrollPane certScroll = new JScrollPane(infoTextPane);
    certScroll.setPreferredSize(new Dimension(300, 500));
    add(certScroll, BorderLayout.CENTER);
  }
Пример #6
0
  public Component getNewRep(String format) {
    // sort on format type
    if (format.equals("checkbox")) {
      // this only makes sense if there are exactly two options
      ComboCheckBox b = new ComboCheckBox(_value, this);
      comboCBs.add(b);
      if (getReadOnly()) {
        b.setEnabled(false);
      }
      updateRepresentation(b);
      return b;
    } else if (format.equals("radiobuttons")) {
      ComboRadioButtons b = new ComboRadioButtons(_value, this);
      comboRBs.add(b);
      if (getReadOnly()) {
        b.setEnabled(false);
      }
      updateRepresentation(b);
      return b;
    } else if (format.equals("onradiobutton")) {
      ComboRadioButtons b = new ComboOnRadioButton(_value, this);
      comboRBs.add(b);
      if (getReadOnly()) {
        b.setEnabled(false);
      }
      updateRepresentation(b);
      return b;
    } else if (format.equals("offradiobutton")) {
      ComboRadioButtons b = new ComboOffRadioButton(_value, this);
      comboRBs.add(b);
      if (getReadOnly()) {
        b.setEnabled(false);
      }
      updateRepresentation(b);
      return b;
    } else if (format.equals("tree")) {
      DefaultTreeModel dModel = new DefaultTreeModel(treeNodes.getFirst());
      JTree dTree = new JTree(dModel);
      trees.add(dTree);
      JScrollPane dScroll = new JScrollPane(dTree);
      dTree.setRootVisible(false);
      dTree.setShowsRootHandles(true);
      dTree.setScrollsOnExpand(true);
      dTree.setExpandsSelectedPaths(true);
      dTree.getSelectionModel().setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
      // arrange for only leaf nodes can be selected
      dTree.addTreeSelectionListener(
          new TreeSelectionListener() {
            public void valueChanged(TreeSelectionEvent e) {
              TreePath[] paths = e.getPaths();
              for (int i = 0; i < paths.length; i++) {
                DefaultMutableTreeNode o = (DefaultMutableTreeNode) paths[i].getLastPathComponent();
                if (o.getChildCount() > 0) {
                  ((JTree) e.getSource()).removeSelectionPath(paths[i]);
                }
              }
              // now record selection
              if (paths.length >= 1) {
                if (paths[0].getLastPathComponent() instanceof TreeLeafNode) {
                  // update value of Variable
                  setValue(_valueArray[((TreeLeafNode) paths[0].getLastPathComponent()).index]);
                }
              }
            }
          });
      // select initial value
      TreePath path = _pathArray[_value.getSelectedIndex()];
      dTree.setSelectionPath(path);
      // ensure selection is in visible portion of JScrollPane
      dTree.scrollPathToVisible(path);

      if (getReadOnly()) {
        log.error("read only variables cannot use tree format: {}", item());
      }
      updateRepresentation(dScroll);
      return dScroll;
    } else {
      // return a new JComboBox representing the same model
      VarComboBox b = new VarComboBox(_value.getModel(), this);
      comboVars.add(b);
      if (getReadOnly()) {
        b.setEnabled(false);
      }
      updateRepresentation(b);
      return b;
    }
  }