public Component getTreeCellRendererComponent(
     JTree tree,
     Object value,
     boolean sel,
     boolean expanded,
     boolean leaf,
     int row,
     boolean hasFocus) {
   DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
   TreeNodeObject nodeObject = (TreeNodeObject) node.getUserObject();
   if (nodeObject.isLogger()) {
     Level level = nodeObject.getLogger().getLevel();
     if (level == null) {
       super.setClosedIcon(loggerNoLevel);
       super.setOpenIcon(loggerNoLevel);
       super.setLeafIcon(loggerNoLevel);
     } else {
       super.setClosedIcon(loggerWithLevel);
       super.setOpenIcon(loggerWithLevel);
       super.setLeafIcon(loggerWithLevel);
     }
   } else {
     super.setClosedIcon(noLoggerIcon);
     super.setOpenIcon(noLoggerIcon);
   }
   return super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
 }
  /**
   * This method initializes treeParam
   *
   * @return javax.swing.JTree
   */
  private JTree getTreeParam() {
    if (treeParam == null) {
      treeParam = new JTree();
      treeParam.setModel(getTreeModel());
      treeParam.setShowsRootHandles(true);
      treeParam.setRootVisible(true);
      treeParam.addTreeSelectionListener(
          new javax.swing.event.TreeSelectionListener() {

            public void valueChanged(javax.swing.event.TreeSelectionEvent e) {

              DefaultMutableTreeNode node =
                  (DefaultMutableTreeNode) getTreeParam().getLastSelectedPathComponent();
              if (node == null) return;
              String name = (String) node.getUserObject();
              showParamPanel(name);
            }
          });
      DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
      renderer.setLeafIcon(null);
      renderer.setOpenIcon(null);
      renderer.setClosedIcon(null);
      treeParam.setCellRenderer(renderer);

      treeParam.setRowHeight(18);
    }
    return treeParam;
  }
Esempio n. 3
0
  private void init(DefaultTreeModel model) {
    tree = getTree(model);

    DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) getTree().getCellRenderer();
    Icon openIcon = new ImageIcon("src/com/geopista/app/alfresco/ui/image/folder_open.png");
    // Icon leafIcon = new ImageIcon("src/com/geopista/app/alfresco/ui/image/folder_close.png");
    Icon closedIcon = new ImageIcon("src/com/geopista/app/alfresco/ui/image/folder_close.png");
    renderer.setOpenIcon(openIcon);
    // renderer.setLeafIcon(leafIcon);
    renderer.setLeafIcon(openIcon);
    renderer.setClosedIcon(closedIcon);

    setLayout(new BorderLayout());
    add(getTree(), BorderLayout.CENTER);
  }
Esempio n. 4
0
  public GoodsTopComponent() {

    builder = new GoodsTreeBuilder();
    groupModel = builder.buildGroupTree();
    complexModel = builder.buidComplexTree();

    initComponents();
    setName(Bundle.CTL_GoodsTopComponent());
    setToolTipText(Bundle.HINT_GoodsTopComponent());

    complexTreeTable.setTreeTableModel(complexModel);

    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
    renderer.setLeafIcon(new ImageIcon(getClass().getResource("folder_close_16.png")));
    renderer.setOpenIcon(new ImageIcon(getClass().getResource("folder_open_16.png")));
    renderer.setClosedIcon(new ImageIcon(getClass().getResource("folder_close_16.png")));
    groupTree.setCellRenderer(renderer);
  }
Esempio n. 5
0
  public TestTree() {
    super("Custom Icon Example");
    setSize(350, 450);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    // Build the hierarchy of containers & objects
    String[] schoolyard = {"School", "Playground", "Parking Lot", "Field"};
    String[] mainstreet = {"Grocery", "Shoe Shop", "Five & Dime", "Post Office"};
    String[] highway = {"Gas Station", "Convenience Store"};
    String[] housing = {"Victorian_blue", "Faux Colonial", "Victorian_white"};
    String[] housing2 = {"Mission", "Ranch", "Condo"};
    Hashtable homeHash = new Hashtable();
    homeHash.put("Residential 1", housing);
    homeHash.put("Residential 2", housing2);

    Hashtable cityHash = new Hashtable();
    cityHash.put("School grounds", schoolyard);
    cityHash.put("Downtown", mainstreet);
    cityHash.put("Highway", highway);
    cityHash.put("Housing", homeHash);

    Hashtable worldHash = new Hashtable();
    worldHash.put("My First VRML World", cityHash);

    // Build our tree out of our big hashtable
    tree1 = new JTree(worldHash);
    tree2 = new JTree(worldHash);

    DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) tree2.getCellRenderer();
    renderer.setClosedIcon(new ImageIcon("door.closed.gif"));
    renderer.setOpenIcon(new ImageIcon("door.open.gif"));
    renderer.setLeafIcon(new ImageIcon("world.gif"));

    JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, tree1, tree2);

    getContentPane().add(pane, BorderLayout.CENTER);
  }
 public boolean setIcons(DefaultTreeCellRenderer renderer) {
   renderer.setOpenIcon(DEFAULT_ICON);
   renderer.setClosedIcon(DEFAULT_ICON);
   renderer.setLeafIcon(DEFAULT_ICON);
   return true;
 }
Esempio n. 7
0
  /**
   * Helper function to display a Swing window with a tree representation of the specified list of
   * joins. See {@link #orderJoins}, which may want to call this when the analyze flag is true.
   *
   * @param js the join plan to visualize
   * @param pc the PlanCache accumulated whild building the optimal plan
   * @param stats table statistics for base tables
   * @param selectivities the selectivities of the filters over each of the tables (where tables are
   *     indentified by their alias or name if no alias is given)
   */
  private void printJoins(
      Vector<LogicalJoinNode> js,
      PlanCache pc,
      HashMap<String, TableStats> stats,
      HashMap<String, Double> selectivities) {

    JFrame f = new JFrame("Join Plan for " + p.getQuery());

    // Set the default close operation for the window,
    // or else the program won't exit when clicking close button
    f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    f.setVisible(true);

    f.setSize(300, 500);

    HashMap<String, DefaultMutableTreeNode> m = new HashMap<String, DefaultMutableTreeNode>();

    // int numTabs = 0;

    // int k;
    DefaultMutableTreeNode root = null, treetop = null;
    HashSet<LogicalJoinNode> pathSoFar = new HashSet<LogicalJoinNode>();
    boolean neither;

    System.out.println(js);
    for (LogicalJoinNode j : js) {
      pathSoFar.add(j);
      System.out.println("PATH SO FAR = " + pathSoFar);

      String table1Name = Database.getCatalog().getTableName(this.p.getTableId(j.t1Alias));
      String table2Name = Database.getCatalog().getTableName(this.p.getTableId(j.t2Alias));

      // Double c = pc.getCost(pathSoFar);
      neither = true;

      root =
          new DefaultMutableTreeNode(
              "Join "
                  + j
                  + " (Cost ="
                  + pc.getCost(pathSoFar)
                  + ", card = "
                  + pc.getCard(pathSoFar)
                  + ")");
      DefaultMutableTreeNode n = m.get(j.t1Alias);
      if (n == null) { // never seen this table before
        n =
            new DefaultMutableTreeNode(
                j.t1Alias
                    + " (Cost = "
                    + stats.get(table1Name).estimateScanCost()
                    + ", card = "
                    + stats.get(table1Name).estimateTableCardinality(selectivities.get(j.t1Alias))
                    + ")");
        root.add(n);
      } else {
        // make left child root n
        root.add(n);
        neither = false;
      }
      m.put(j.t1Alias, root);

      n = m.get(j.t2Alias);
      if (n == null) { // never seen this table before

        n =
            new DefaultMutableTreeNode(
                j.t2Alias == null
                    ? "Subplan"
                    : (j.t2Alias
                        + " (Cost = "
                        + stats.get(table2Name).estimateScanCost()
                        + ", card = "
                        + stats
                            .get(table2Name)
                            .estimateTableCardinality(selectivities.get(j.t2Alias))
                        + ")"));
        root.add(n);
      } else {
        // make right child root n
        root.add(n);
        neither = false;
      }
      m.put(j.t2Alias, root);

      // unless this table doesn't join with other tables,
      // all tables are accessed from root
      if (!neither) {
        for (String key : m.keySet()) {
          m.put(key, root);
        }
      }

      treetop = root;
    }

    JTree tree = new JTree(treetop);
    JScrollPane treeView = new JScrollPane(tree);

    tree.setShowsRootHandles(true);

    // Set the icon for leaf nodes.
    ImageIcon leafIcon = new ImageIcon("join.jpg");
    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
    renderer.setOpenIcon(leafIcon);
    renderer.setClosedIcon(leafIcon);

    tree.setCellRenderer(renderer);

    f.setSize(300, 500);

    f.add(treeView);
    for (int i = 0; i < tree.getRowCount(); i++) {
      tree.expandRow(i);
    }

    if (js.size() == 0) {
      f.add(new JLabel("No joins in plan."));
    }

    f.pack();
  }
Esempio n. 8
0
  public ActiveModel(List<Stock> stocks) {
    Dimension dim = getPreferredSize();
    dim.width = (170);
    setPreferredSize(dim);
    setMinimumSize(dim);

    setLayout(new BorderLayout());

    this.stocks = stocks;

    // TREE

    stockTree = new JTree(createTree());

    stockCellRenderer = new DefaultTreeCellRenderer();

    Border emptyBorder = BorderFactory.createEmptyBorder(5, 5, 5, 5);
    stockTree.setBorder(emptyBorder);
    stockCellRenderer.setLeafIcon(Utils.createIcon("/images/stock16.png"));
    stockCellRenderer.setOpenIcon(Utils.createIcon("/images/cubes.png"));
    stockCellRenderer.setClosedIcon(Utils.createIcon("/images/cubes.png"));

    stockTree.setCellRenderer(stockCellRenderer);

    add(new JScrollPane(stockTree), BorderLayout.CENTER);

    popup = new JPopupMenu();
    JMenuItem refreshItem = new JMenuItem("Refresh Data");
    JMenuItem settingsItem = new JMenuItem("Stock Settings");
    JMenuItem deleteItem = new JMenuItem("Delete Stock");
    popup.add(refreshItem);
    popup.addSeparator();
    popup.add(settingsItem);
    popup.add(deleteItem);

    stockTree.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            TreePath path = stockTree.getPathForLocation(e.getX(), e.getY());
            if (path == null) return;

            stockTree.setSelectionPath(path);
            ;

            if (e.getButton() == MouseEvent.BUTTON3) {
              popup.show(stockTree, e.getX(), e.getY());
            }
          }
        });

    refreshItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            DefaultMutableTreeNode node =
                (DefaultMutableTreeNode) stockTree.getLastSelectedPathComponent();
            Stock selectedStock = (Stock) node.getUserObject();
            selectedStock.downloadData();
          }
        });

    settingsItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode node =
                (DefaultMutableTreeNode) stockTree.getLastSelectedPathComponent();
            Stock selectedStock = (Stock) node.getUserObject();

            if (activeModelListener != null) {
              activeModelListener.showStockSettingsEventOccurred(selectedStock);
            }
          }
        });

    deleteItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            DefaultMutableTreeNode node =
                (DefaultMutableTreeNode) stockTree.getLastSelectedPathComponent();
            Stock selectedStock = (Stock) node.getUserObject();
            if (selectedStock != null) {
              ActiveModelEvent ev = new ActiveModelEvent(selectedStock);
              if (activeModelListener != null) {
                activeModelListener.activeModelDeleteEventOccurred(ev, selectedStock.toString());
              }
            }
          }
        });

    // BUTTON PANEL
    JPanel buttonsPanel = new JPanel();
    symbolField = new JTextField(4);
    HintTextField fieldUI = new HintTextField(" Symbol", true, new Color(126, 126, 126));
    symbolField.setUI(fieldUI);

    addbtn = new JButton("");
    delbtn = new JButton("");

    addbtn.setIcon(Utils.createIcon("/images/plus.png"));
    delbtn.setIcon(Utils.createIcon("/images/Minus16.png"));

    buttonsPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    buttonsPanel.add(symbolField);
    buttonsPanel.add(addbtn);
    buttonsPanel.add(delbtn);
    add(buttonsPanel, BorderLayout.SOUTH);

    addbtn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            addAction();
          }
        });

    symbolField.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            addAction();
          }
        });

    delbtn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode node =
                (DefaultMutableTreeNode) stockTree.getLastSelectedPathComponent();
            Stock selectedStock = (Stock) node.getUserObject();

            // CHECK IF A STOCK HAS BEEN SELECTED
            if (selectedStock != null) {
              ActiveModelEvent ev = new ActiveModelEvent(selectedStock);
              if (activeModelListener != null) {
                activeModelListener.activeModelDeleteEventOccurred(ev, selectedStock.toString());
              }
            } else {
              JOptionPane.showMessageDialog(
                  null,
                  "Please select a stock to remove",
                  "Stock not selected",
                  JOptionPane.ERROR_MESSAGE);
            }
          }
        });

    // Border
    Border innerBorder = BorderFactory.createTitledBorder("Active Models");
    Border outerBorder = BorderFactory.createEmptyBorder(5, 5, 5, 5);
    Border title = BorderFactory.createCompoundBorder(outerBorder, innerBorder);
    Border inset = BorderFactory.createEmptyBorder(2, 5, 5, 5);

    setBorder(BorderFactory.createCompoundBorder(title, inset));
  }
Esempio n. 9
0
 public boolean setIcons(DefaultTreeCellRenderer renderer) {
   renderer.setOpenIcon(FOLDER_OPEN_ICON);
   renderer.setClosedIcon(FOLDER_CLOSED_ICON);
   renderer.setLeafIcon(FOLDER_CLOSED_ICON);
   return true;
 }