/** Constructor */
 public ServiceFilterPanel(String text, Vector list) {
   empty_border = new EmptyBorder(5, 5, 0, 5);
   indent_border = new EmptyBorder(5, 25, 5, 5);
   service_box = new JCheckBox(text);
   service_box.addActionListener(this);
   service_data = new Vector();
   if (list != null) {
     service_box.setSelected(true);
     service_data = (Vector) list.clone();
   }
   service_list = new JList(service_data);
   service_list.setBorder(new EtchedBorder());
   service_list.setVisibleRowCount(5);
   service_list.addListSelectionListener(this);
   service_list.setEnabled(service_box.isSelected());
   service_scroll = new JScrollPane(service_list);
   service_scroll.setBorder(new EtchedBorder());
   remove_service_button = new JButton("Remove");
   remove_service_button.addActionListener(this);
   remove_service_button.setEnabled(false);
   remove_service_panel = new JPanel();
   remove_service_panel.setLayout(new FlowLayout());
   remove_service_panel.add(remove_service_button);
   service_area = new JPanel();
   service_area.setLayout(new BorderLayout());
   service_area.add(service_scroll, BorderLayout.CENTER);
   service_area.add(remove_service_panel, BorderLayout.EAST);
   service_area.setBorder(indent_border);
   add_service_field = new JTextField();
   add_service_field.addActionListener(this);
   add_service_field.getDocument().addDocumentListener(this);
   add_service_field.setEnabled(service_box.isSelected());
   add_service_button = new JButton("Add");
   add_service_button.addActionListener(this);
   add_service_button.setEnabled(false);
   add_service_panel = new JPanel();
   add_service_panel.setLayout(new BorderLayout());
   JPanel dummy = new JPanel();
   dummy.setBorder(empty_border);
   add_service_panel.add(dummy, BorderLayout.WEST);
   add_service_panel.add(add_service_button, BorderLayout.EAST);
   add_service_area = new JPanel();
   add_service_area.setLayout(new BorderLayout());
   add_service_area.add(add_service_field, BorderLayout.CENTER);
   add_service_area.add(add_service_panel, BorderLayout.EAST);
   add_service_area.setBorder(indent_border);
   setLayout(new BorderLayout());
   add(service_box, BorderLayout.NORTH);
   add(service_area, BorderLayout.CENTER);
   add(add_service_area, BorderLayout.SOUTH);
   setBorder(empty_border);
 }
Пример #2
0
    public DrawViewPanel() {

      setLayout(new BorderLayout());
      splitPane = new JSplitPane();
      fromList.setBorder(BorderFactory.createTitledBorder("Select FROM node to Connect"));
      toList.setBorder(BorderFactory.createTitledBorder("Select TO node to Connect"));
      fromList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
      toList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
      JPanel nodePanel = new JPanel();
      JPanel toNodePanel = new JPanel();
      JList arcList = new JList(arcListModel);

      nodePanel.setLayout(new BorderLayout());
      toNodePanel.setLayout(new BorderLayout());
      fromListScrollPane = new JScrollPane(fromList);

      nodePanel.add(fromListScrollPane, BorderLayout.CENTER);
      toNodePanel.add(new JScrollPane(toList), BorderLayout.CENTER);
      nodePanel.add(toNodePanel, BorderLayout.SOUTH);

      JPanel arcButtonPanel = new JPanel();
      arcButtonPanel.setLayout(new GridLayout(1, 2));
      JPanel northArcButtonPanel = new JPanel();
      JPanel southArcButtonPanel = new JPanel();

      northArcButtonPanel.setLayout(new BorderLayout());
      southArcButtonPanel.setLayout(new BorderLayout());

      JButton addDirArcButton = new JButton("==>>");
      addDirArcButton.setToolTipText("Add Directed Arc from left node to right node");
      addDirArcButton.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              addDirectedArc();
            }
          });
      JButton addUndirArcButton = new JButton("<==>");
      addUndirArcButton.setToolTipText("Add Undrected Arc between selected nodes");
      addUndirArcButton.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              addUndirectedArc();
            }
          });

      /** Adding Dijkstra button to the viewer* */
      JButton runDijkstraButton = new JButton("Dijkstra");
      runDijkstraButton.setToolTipText("Runs Dijsktra's algorithm on the given graph");
      runDijkstraButton.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              try {
                runDijkstra();
              } catch (NotMemberException e1) {
                JOptionPane.showMessageDialog(GraphViewer.this, e1.getMessage());
              }
            }

            private void runDijkstra() throws NotMemberException {

              graph.dijkstra(fromList.getSelectedValue(), toList.getSelectedValue(), Graph.DIRECT);
              graph.printoutShortestPath();
            }
          });

      /** Adding DijkstraReverse button to the viewer* */
      JButton runDijkstraReverseButton = new JButton("DijkstraRev");
      runDijkstraReverseButton.setToolTipText(
          "Runs Dijsktra's algorithm (in reverse order) on the given graph");
      runDijkstraReverseButton.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              try {
                runDijkstraReverse();
              } catch (NotMemberException e1) {
                JOptionPane.showMessageDialog(GraphViewer.this, e1.getMessage());
              }
            }

            private void runDijkstraReverse() throws NotMemberException {
              Node lastNode = null;
              graph.dijkstraReverse(graph.findNode("12a"));
              graph.printoutShortestPath();
            }
          });

      /** Adding BiDijkstra button to the viewer* */
      JButton runBiDijkstraButton = new JButton("BiDijkstra");
      runBiDijkstraButton.setToolTipText(
          "Runs Bidirectional Dijsktra's algorithm on the given graph");
      runBiDijkstraButton.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              try {
                runBiDijkstra();
              } catch (NotMemberException e1) {
                JOptionPane.showMessageDialog(GraphViewer.this, e1.getMessage());
              }
            }

            private void runBiDijkstra() throws NotMemberException {
              Node firstNode = null;
              Node lastNode = null;
              graph.biDijkstra(fromList.getSelectedValue(), toList.getSelectedValue());
              graph.printoutShortestPath();
            }
          });
      northArcButtonPanel.add(addDirArcButton, BorderLayout.EAST);
      southArcButtonPanel.add(addUndirArcButton, BorderLayout.WEST);
      arcButtonPanel.add(northArcButtonPanel);
      arcButtonPanel.add(southArcButtonPanel);
      toNodePanel.add(arcButtonPanel, BorderLayout.NORTH);

      splitPane.setLeftComponent(nodePanel);

      // right component
      //			rightPanel = new JPanel();

      graph.addListener(layouter);
      canvas = new Draw2DPanel(layouter, null);
      layouter.settCanvas(canvas);

      JTabbedPane tabbedPane = new JTabbedPane();
      splitPane.setRightComponent(tabbedPane);

      if (hasOption(VIEW_2D)) {
        tabbedPane.addTab("Graph2D", canvas);
      }

      if (hasOption(VIEW_WF)) {
        canvasWF = new DrawWFPanel(layouterWF3D, null);
        layouterWF3D.setCanvasWF(canvasWF);
        tabbedPane.addTab("WireFrame3D", canvasWF);
      }
      if (hasOption(VIEW_3D)) {
        canvasAnim = new AnimPanel(layouterWF3D, null, new Vector3d(10.0, 10.0, 50.0), false);
        layouterWF3D.setCanvasAnim(canvasAnim);
        tabbedPane.addTab("Graph3D", canvasAnim);
      }
      //			rightPanel.setLayout(new BorderLayout());
      arcList.setBorder(BorderFactory.createTitledBorder("Arcs in the graph"));
      //			rightPanel.add(new JScrollPane (arcList), BorderLayout.CENTER);
      JToolBar toolBar = new JToolBar();

      // toolbar buttons
      JButton openFileButton = new JButton("File");
      JButton addNodeButton = new JButton("AN");
      JButton addArcButton = new JButton("Add Arc");
      JButton deleteNodeButton = new JButton("Delete Node");
      JButton deleteArcButton = new JButton("Delete Arc");
      JButton showBordersButton = new JButton("SB");

      openFileButton.setToolTipText("Open File");

      openFileButton.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              openFile();
            }
          });

      addNodeButton.setToolTipText("Add Node");
      addNodeButton.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              addNode();
            }
          });

      deleteNodeButton.setToolTipText("Delete Node");
      deleteNodeButton.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              deleteNode();
            }
          });

      deleteArcButton.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              deleteArc();
            }
          });
      showBordersButton.setToolTipText("ShowBorders");
      showBordersButton.addActionListener(
          new ActionListener() {

            public void actionPerformed(ActionEvent e) {
              showBorders = !showBorders;
              changeBorderDisplay();
            }
          });
      toolBar.add(openFileButton);
      toolBar.add(addNodeButton);
      toolBar.add(addArcButton);
      toolBar.add(deleteNodeButton);
      toolBar.add(deleteArcButton);
      toolBar.add(showBordersButton);
      toolBar.add(runDijkstraButton);
      toolBar.add(runDijkstraReverseButton);
      toolBar.add(runBiDijkstraButton);

      add(splitPane, BorderLayout.CENTER);
      add(toolBar, BorderLayout.SOUTH);
    }