Example usage for javax.swing.tree DefaultMutableTreeNode add

List of usage examples for javax.swing.tree DefaultMutableTreeNode add

Introduction

In this page you can find the example usage for javax.swing.tree DefaultMutableTreeNode add.

Prototype

public void add(MutableTreeNode newChild) 

Source Link

Document

Removes newChild from its parent and makes it a child of this node by adding it to the end of this node's child array.

Usage

From source file:course_generator.frmMain.java

/**
 * This method is called to initialize the form.
 *///from  ww  w  . ja  v a 2s.co m
private void initComponents() {
    // -- Main windows
    // ------------------------------------------------------
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    // java.util.ResourceBundle bundle =
    // java.util.ResourceBundle.getBundle("course_generator/Bundle");
    setTitle(bundle.getString("frmMain.title"));
    setIconImages(null);
    // setName("FrameMain");
    // setPreferredSize(new java.awt.Dimension(812, 800));
    addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent evt) {
            formWindowClosing(evt);
        }
    });

    // -- Layout
    // ------------------------------------------------------------
    Container paneGlobal = getContentPane();
    // paneGlobal.setLayout(new GridBagLayout());
    paneGlobal.setLayout(new BorderLayout());

    // -- Menu bar
    // ----------------------------------------------------------
    Create_MenuBarMain();

    // -- Main toolbar
    // ------------------------------------------------------
    Create_MainToolbar();
    paneGlobal.add(ToolBarMain, BorderLayout.NORTH);

    // -- Status bar
    // ------------------------------------------------------
    Create_Statusbar();
    paneGlobal.add(StatusBar, BorderLayout.SOUTH);

    // -- Main split bar (vertical)
    // -----------------------------------------
    SplitPaneMain = new javax.swing.JSplitPane();
    paneGlobal.add(SplitPaneMain, BorderLayout.CENTER);

    // -- Left side of the split bar
    // ----------------------------------------
    jPanelLeft = new javax.swing.JPanel();
    jPanelLeft.setLayout(new java.awt.BorderLayout());

    // -- Add the left panel to the main split panel
    // ------------------------
    SplitPaneMain.setLeftComponent(jPanelLeft);

    // -- Content of the tree
    javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode(
            "Course Generator");
    javax.swing.tree.DefaultMutableTreeNode treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Parcours");
    javax.swing.tree.DefaultMutableTreeNode treeNode3 = new javax.swing.tree.DefaultMutableTreeNode(
            "Utmb 2011");
    javax.swing.tree.DefaultMutableTreeNode treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Prvu");
    treeNode3.add(treeNode4);
    treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Fait");
    treeNode3.add(treeNode4);
    treeNode2.add(treeNode3);
    treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Montagnard");
    treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Prvu");
    treeNode3.add(treeNode4);
    treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Fait");
    treeNode3.add(treeNode4);
    treeNode2.add(treeNode3);
    treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("UCDHL2008");
    treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Prvu");
    treeNode3.add(treeNode4);
    treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Fait");
    treeNode3.add(treeNode4);
    treeNode2.add(treeNode3);
    treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("UCDHL2009");
    treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Prvu");
    treeNode3.add(treeNode4);
    treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Fait");
    treeNode3.add(treeNode4);
    treeNode2.add(treeNode3);
    treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("UCDHL2010");
    treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Prvu");
    treeNode3.add(treeNode4);
    treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Fait");
    treeNode3.add(treeNode4);
    treeNode2.add(treeNode3);
    treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("UCDHL2011");
    treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Prvu");
    treeNode3.add(treeNode4);
    treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Fait");
    treeNode3.add(treeNode4);
    treeNode2.add(treeNode3);
    treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("UCDHL2012");
    treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Prvu");
    treeNode3.add(treeNode4);
    treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Fait");
    treeNode3.add(treeNode4);
    treeNode2.add(treeNode3);
    treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("UCDHL2013");
    treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Prvu");
    treeNode3.add(treeNode4);
    treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Fait");
    treeNode3.add(treeNode4);
    treeNode2.add(treeNode3);
    treeNode1.add(treeNode2);
    treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Configuration");
    treeNode1.add(treeNode2);

    // -- Tree
    // --------------------------------------------------------------
    jTreeMain = new javax.swing.JTree();
    jTreeMain.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
    jTreeMain.setPreferredSize(new java.awt.Dimension(109, 25));

    // -- Add the tree to a scroll panel
    // ------------------------------------
    jScrollPaneTree = new javax.swing.JScrollPane();
    jScrollPaneTree.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    jScrollPaneTree.setViewportView(jTreeMain);

    // -- Add the scroll panel to the left panel
    // ----------------------------
    jPanelLeft.add(jScrollPaneTree, java.awt.BorderLayout.CENTER);

    // -- Right split pane
    // --------------------------------------------------
    SplitPaneMainRight = new javax.swing.JSplitPane();
    SplitPaneMainRight.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
    SplitPaneMain.setRightComponent(SplitPaneMainRight);

    // -- Tabbed panel
    // ------------------------------------------------------
    TabbedPaneMain = new javax.swing.JTabbedPane();
    // -- Create the listener
    ChangeListener changeListener = new ChangeListener() {
        public void stateChanged(ChangeEvent changeEvent) {
            JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent.getSource();
            int index = sourceTabbedPane.getSelectedIndex();
            if (index == 4) // Tab Resume
                RefreshResume();
        }
    };
    TabbedPaneMain.addChangeListener(changeListener);

    SplitPaneMainRight.setTopComponent(TabbedPaneMain);

    // -- Tab - data (grid)
    // -------------------------------------------------
    TableMain = new javax.swing.JTable();
    TableMain.setModel(ModelTableMain);
    TableMain.getTableHeader()
            .setDefaultRenderer(new MainHeaderRenderer(TableMain.getTableHeader().getDefaultRenderer()));
    TableMain.getTableHeader().setReorderingAllowed(false);

    TableMain.setDefaultRenderer(ElevationClass.class, new ElevationRenderer());
    TableMain.setDefaultRenderer(DistClass.class, new DistRenderer());
    TableMain.setDefaultRenderer(TotalClass.class, new TotalRenderer());
    TableMain.setDefaultRenderer(DiffClass.class, new DiffRenderer());
    TableMain.setDefaultRenderer(CoeffClass.class, new CoeffRenderer());
    TableMain.setDefaultRenderer(LatClass.class, new LatRenderer());
    TableMain.setDefaultRenderer(LonClass.class, new LonRenderer());
    TableMain.setDefaultRenderer(RecupClass.class, new RecupRenderer());
    TableMain.setDefaultRenderer(TimeClass.class, new TimeRenderer());
    TableMain.setDefaultRenderer(TimelimitClass.class, new TimelimitRenderer());
    TableMain.setDefaultRenderer(HourClass.class, new HourRenderer());
    TableMain.setDefaultRenderer(StationClass.class, new StationRenderer());
    TableMain.setDefaultRenderer(TagClass.class, new TagRenderer());

    TableMain.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
    TableMain.setRowHeight(20);
    TableMain.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            if (evt.getButton() == evt.BUTTON1 && evt.getClickCount() >= 2 && !evt.isConsumed()) {
                evt.consume();
                int row = TableMain.rowAtPoint(evt.getPoint());
                int col = TableMain.columnAtPoint(evt.getPoint());
                frmEditPosition frm = new frmEditPosition();
                if (frm.showDialog(Settings, Track, row, col)) {
                    Track.isModified = true;
                    RefreshTableMain();
                    RefreshProfil();
                    RefreshStatusbar(Track);
                }
            } else
                TableMainMouseClicked(evt);
        }
    });
    TableMain.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyReleased(java.awt.event.KeyEvent evt) {
            TableMainKeyReleased(evt);
        }
    });

    // -- Add the grid to a scroll panel
    // ------------------------------------
    jScrollPaneData = new javax.swing.JScrollPane();
    jScrollPaneData.setViewportView(TableMain);

    // -- Add the scroll panel to the tabbed panel
    // --------------------------
    addTab(TabbedPaneMain, jScrollPaneData, bundle.getString("frmMain.TabData.tabTitle"),
            new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/satellite16.png")));

    // -- Tab - Profil
    // ------------------------------------------------------
    jPanelProfil = new javax.swing.JPanel();
    jPanelProfil.setPreferredSize(new java.awt.Dimension(677, 150));
    jPanelProfil.setLayout(new java.awt.BorderLayout());

    // -- Profil tool bar
    // ---------------------------------------------------
    // Create_Profil_Toolbar();
    // jPanelProfil.add(ToolBarProfil, java.awt.BorderLayout.WEST);

    // -- Profil chart
    // ------------------------------------------------------
    jPanelProfilChart = new ChartPanel(chart);
    CrosshairOverlay crosshairOverlay = new CrosshairOverlay();
    xCrosshair = new Crosshair(Double.NaN, Color.DARK_GRAY, new BasicStroke(0f));
    // xCrosshair.setLabelVisible(true);
    xCrosshair.setLabelBackgroundPaint(Color.WHITE);

    yCrosshair = new Crosshair(Double.NaN, Color.DARK_GRAY, new BasicStroke(0f));
    // yCrosshair.setLabelVisible(true);
    yCrosshair.setLabelBackgroundPaint(Color.WHITE);

    crosshairOverlay.addDomainCrosshair(xCrosshair);
    crosshairOverlay.addRangeCrosshair(yCrosshair);

    jPanelProfilChart.addOverlay(crosshairOverlay);
    jPanelProfilChart.setBackground(new java.awt.Color(255, 0, 51));
    jPanelProfilChart.addChartMouseListener(new ChartMouseListener() {
        @Override
        public void chartMouseClicked(ChartMouseEvent event) {

            ChartEntity chartentity = event.getEntity();
            if (chartentity instanceof XYItemEntity) {
                XYItemEntity e = (XYItemEntity) chartentity;
                XYDataset d = e.getDataset();
                int s = e.getSeriesIndex();
                int i = e.getItem();
                double x = d.getXValue(s, i);
                double y = d.getYValue(s, i);
                xCrosshair.setValue(x);
                yCrosshair.setValue(y);
                RefreshProfilInfo(i);
                //Refresh the position on the data grid
                TableMain.setRowSelectionInterval(i, i);
                Rectangle rect = TableMain.getCellRect(i, 0, true);
                TableMain.scrollRectToVisible(rect);
                //Refresh the marker position on the map
                RefreshCurrentPosMarker(Track.data.get(i).getLatitude(), Track.data.get(i).getLongitude());
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
        }
    });

    jPanelProfil.add(jPanelProfilChart, java.awt.BorderLayout.CENTER);

    // -- Profil info bar
    // ---------------------------------------------------
    jPanelProfilInfo = new javax.swing.JPanel();
    jPanelProfilInfo.setLayout(new GridBagLayout());
    jPanelProfil.add(jPanelProfilInfo, java.awt.BorderLayout.SOUTH);

    // -- Line 0
    // -- Distance
    // ----------------------------------------------------------
    lbProfilDistance = new javax.swing.JLabel();
    lbProfilDistance.setText(" " + bundle.getString("frmMain.lbProfilDistance.text") + "=0.000km ");
    lbProfilDistance.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelProfilInfo, lbProfilDistance, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0,
            GridBagConstraints.EAST, GridBagConstraints.BOTH);

    // -- Time
    // --------------------------------------------------------------
    lbProfilTime = new javax.swing.JLabel();
    lbProfilTime.setText(" " + bundle.getString("frmMain.lbProfilTime.text") + "=00:00:00 ");
    lbProfilTime.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelProfilInfo, lbProfilTime, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.EAST,
            GridBagConstraints.BOTH);

    // -- Slope
    // -------------------------------------------------------------
    lbProfilSlope = new javax.swing.JLabel();
    lbProfilSlope.setText(" " + bundle.getString("frmMain.lbProfilSlope.text") + "=0.0% ");
    lbProfilSlope.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelProfilInfo, lbProfilSlope, 2, 0, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.EAST,
            GridBagConstraints.BOTH);

    // -- Name
    // --------------------------------------------------------------
    lbProfilName = new javax.swing.JLabel();
    lbProfilName.setText(" " + bundle.getString("frmMain.lbProfilName.text") + "= ");
    lbProfilName.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelProfilInfo, lbProfilName, 3, 0, 1, 1, 1, 0, 0, 0, 0, 0, GridBagConstraints.EAST,
            GridBagConstraints.BOTH);

    // -- Line 1
    // -- Elevation
    // ---------------------------------------------------------
    lbProfilElevation = new javax.swing.JLabel();
    lbProfilElevation.setText(" " + bundle.getString("frmMain.lbProfilElevation.text") + "=0m ");
    lbProfilElevation.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelProfilInfo, lbProfilElevation, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0,
            GridBagConstraints.EAST, GridBagConstraints.BOTH);

    // -- Hour
    // --------------------------------------------------------------
    lbProfilHour = new javax.swing.JLabel();
    lbProfilHour.setText(" " + bundle.getString("frmMain.lbProfilHour.text") + "=00:00:00 ");
    lbProfilHour.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelProfilInfo, lbProfilHour, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.EAST,
            GridBagConstraints.BOTH);

    // -- Speed
    // -------------------------------------------------------------
    lbProfilSpeed = new javax.swing.JLabel();
    lbProfilSpeed.setText(" " + bundle.getString("frmMain.lbProfilSpeed.text") + "=0.0km/h ");
    lbProfilSpeed.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelProfilInfo, lbProfilSpeed, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, GridBagConstraints.EAST,
            GridBagConstraints.BOTH);

    // -- Comment
    // -----------------------------------------------------------
    lbProfilComment = new javax.swing.JLabel();
    lbProfilComment.setText(" " + bundle.getString("frmMain.lbProfilComment.text") + "= ");
    lbProfilComment.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    Utils.addComponent(jPanelProfilInfo, lbProfilComment, 3, 1, 1, 1, 1, 0, 0, 0, 0, 0, GridBagConstraints.EAST,
            GridBagConstraints.BOTH);
    // -- Distance / Temps / Pente / Nom
    // -- Altitude / Heure / Vitesse / Commentaire

    // -- Add the panel to the tabbed panel
    // ---------------------------------
    addTab(TabbedPaneMain, jPanelProfil, bundle.getString("frmMain.TabProfil.tabTitle"),
            new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/profil.png")));

    // -- Tab - Statistic
    // ---------------------------------------------------
    jPanelStatistic = new javax.swing.JPanel();
    jPanelStatistic.setLayout(new java.awt.BorderLayout());

    // -- Statistic tool bar
    // ---------------------------------------------------
    Create_Statistic_Toolbar();
    jPanelStatistic.add(ToolBarStatistic, java.awt.BorderLayout.NORTH);

    // TODO Add the component to display the statistics

    addTab(TabbedPaneMain, jPanelStatistic, bundle.getString("frmMain.TabStatistic.tabTitle"),
            new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/stat.png")));

    // -- Tab - Analysis
    // ----------------------------------------------------
    jPanelAnalyze = new javax.swing.JPanel();

    // TODO Define this panel

    addTab(TabbedPaneMain, jPanelAnalyze, bundle.getString("frmMain.TabAnalyze.tabTitle"),
            new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/search.png")));

    // -- Tab - Resume
    // ------------------------------------------------------
    jPanelResume = new javax.swing.JPanel();
    jPanelResume.setLayout(new java.awt.BorderLayout());

    // -- Resume tool bar
    // ---------------------------------------------------
    Create_Resume_Toolbar();
    jPanelResume.add(ToolBarResume, java.awt.BorderLayout.NORTH);

    TableResume = new javax.swing.JTable();
    TableResume.setModel(ModelTableResume);
    TableResume.setRowHeight(20);
    TableResume.getTableHeader().setReorderingAllowed(false);

    TableResume.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);

    TableResume.getTableHeader()
            .setDefaultRenderer(new ResumeHeaderRenderer(TableResume.getTableHeader().getDefaultRenderer()));

    // TODO Change the Renderer name. Add Resume...
    TableResume.setDefaultRenderer(ResumeNumClass.class, new ResumeNumRenderer());
    TableResume.setDefaultRenderer(ResumeNameClass.class, new ResumeNameRenderer());
    TableResume.setDefaultRenderer(ResumeLineClass.class, new ResumeLineRenderer());
    TableResume.setDefaultRenderer(ResumeElevationClass.class, new ResumeElevationRenderer());
    TableResume.setDefaultRenderer(ResumeClimbPClass.class, new ResumeClimbPRenderer());
    TableResume.setDefaultRenderer(ResumeClimbNClass.class, new ResumeClimbNRenderer());
    TableResume.setDefaultRenderer(ResumeDistanceClass.class, new ResumeDistanceRenderer());
    TableResume.setDefaultRenderer(ResumeTimeClass.class, new ResumeTimeRenderer());
    TableResume.setDefaultRenderer(ResumeHourClass.class, new ResumeHourRenderer());
    TableResume.setDefaultRenderer(ResumedtTimeClass.class, new ResumedtTimeRenderer());
    TableResume.setDefaultRenderer(ResumeTimeLimitClass.class, new ResumeTimeLimitRenderer());
    TableResume.setDefaultRenderer(ResumeStationTimeClass.class, new ResumeStationTimeRenderer());
    TableResume.setDefaultRenderer(ResumedtDistanceClass.class, new ResumedtDistanceRenderer());
    TableResume.setDefaultRenderer(ResumedtClimbPClass.class, new ResumedtClimbPRenderer());
    TableResume.setDefaultRenderer(ResumedtClimbNClass.class, new ResumedtClimbNRenderer());
    TableResume.setDefaultRenderer(ResumeSpeedPClass.class, new ResumeSpeedPRenderer());
    TableResume.setDefaultRenderer(ResumeSpeedNClass.class, new ResumeSpeedNRenderer());
    TableResume.setDefaultRenderer(ResumeAvgSlopePClass.class, new ResumeAvgSlopePRenderer());
    TableResume.setDefaultRenderer(ResumeAvgSlopeNClass.class, new ResumeAvgSlopeNRenderer());
    TableResume.setDefaultRenderer(ResumeAvgSpeedClass.class, new ResumeAvgSpeedRenderer());
    TableResume.setDefaultRenderer(ResumeCommentClass.class, new ResumeCommentRenderer());

    // TableResume.addMouseListener(new java.awt.event.MouseAdapter() {
    // public void mouseClicked(java.awt.event.MouseEvent evt) {
    // TableMainMouseClicked(evt);
    // }
    // });
    // TableResume.addKeyListener(new java.awt.event.KeyAdapter() {
    // public void keyReleased(java.awt.event.KeyEvent evt) {
    // TableMainKeyReleased(evt);
    // }
    // });

    // -- Add the grid to a scroll panel
    // ------------------------------------
    jScrollPaneResume = new javax.swing.JScrollPane();
    jScrollPaneResume.setViewportView(TableResume);
    jPanelResume.add(jScrollPaneResume, java.awt.BorderLayout.CENTER);

    addTab(TabbedPaneMain, jPanelResume, bundle.getString("frmMain.TabResume.tabTitle"),
            new javax.swing.ImageIcon(getClass().getResource("/course_generator/images/grid.png")));

    // -- Map panel
    // ---------------------------------------------------------
    jPanelMap = new javax.swing.JPanel();
    jPanelMap.setLayout(new java.awt.BorderLayout());

    Create_Map_Toolbar();
    jPanelMap.add(jToolBarMapViewer, java.awt.BorderLayout.WEST);

    MapViewer = new org.openstreetmap.gui.jmapviewer.JMapViewer();
    MapViewer.setMapMarkerVisible(true);
    MapViewer.setScrollWrapEnabled(true);
    MapViewer.setZoomButtonStyle(org.openstreetmap.gui.jmapviewer.JMapViewer.ZOOM_BUTTON_STYLE.VERTICAL);
    MapViewer.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseClicked(java.awt.event.MouseEvent evt) {
            MapViewerMouseClicked(evt);
        }
    });
    jPanelMap.add(MapViewer, java.awt.BorderLayout.CENTER);

    jScrollPanelMap = new javax.swing.JScrollPane();
    jScrollPanelMap.setViewportView(jPanelMap);

    SplitPaneMainRight.setRightComponent(jScrollPanelMap);

    // -- Finished - Pack
    // ---------------------------------------------------
    pack();
}

From source file:edu.ucla.stat.SOCR.chart.ChartTree.java

/**
 * Creates a tree node containing bar charts based on the 
 * {@link CategoryPlot} class./*from  w w  w  .j av  a 2s.c o  m*/
 * 
 * @return The tree node.
 */
private MutableTreeNode createCategoryBarChartsNode() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("CategoryPlot");

    MutableTreeNode n1 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.BarChartDemo1", "BarChartDemo1"));
    MutableTreeNode n2 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.BarChartDemo2", "BarChartDemo2"));
    MutableTreeNode n3 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.BarChartDemo3", "BarChartDemo3"));
    MutableTreeNode n4 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.BarChartDemo4", "BarChartDemo4"));
    MutableTreeNode n5 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.BarChartDemo5", "BarChartDemo5"));
    MutableTreeNode n6 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.BarChartDemo6", "BarChartDemo6"));
    MutableTreeNode n7 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.BarChartDemo7", "BarChartDemo7"));
    MutableTreeNode n8 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.BarChartDemo8", "BarChartDemo8"));
    MutableTreeNode n9 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.BarChartDemo9", "BarChartDemo9"));
    MutableTreeNode n10 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.BarChartDemo10", "BarChartDemo10"));
    MutableTreeNode n11 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.BarChart3DDemo1", "BarChart3DDemo1"));
    MutableTreeNode n12 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.BarChart3DDemo2", "BarChart3DDemo2"));
    MutableTreeNode n13 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.BarChart3DDemo3", "BarChart3DDemo3"));
    MutableTreeNode n14 = new DefaultMutableTreeNode(new DemoDescription(
            "edu.ucla.stat.SOCR.chart.demo.IntervalBarChartDemo1", "IntervalBarChartDemo1"));
    MutableTreeNode n15 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.LayeredBarChartDemo1", "LayeredBarChartDemo1"));
    MutableTreeNode n16 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.LayeredBarChartDemo2", "LayeredBarChartDemo2"));
    MutableTreeNode n17 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.StackedBarChartDemo1", "StackedBarChartDemo1"));
    MutableTreeNode n18 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.StackedBarChartDemo2", "StackedBarChartDemo2"));
    MutableTreeNode n19 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.StackedBarChartDemo3", "StackedBarChartDemo3"));
    MutableTreeNode n20 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.StackedBarChartDemo4", "StackedBarChartDemo4"));
    MutableTreeNode n21 = new DefaultMutableTreeNode(new DemoDescription(
            "edu.ucla.stat.SOCR.chart.demo.StatisticalBarChartDemo1", "StatisticalBarChartDemo1"));
    MutableTreeNode n22 = new DefaultMutableTreeNode(new DemoDescription(
            "edu.ucla.stat.SOCR.chart.demo.StatisticalBarChartDemo2", "StatisticalBarChartDemo2"));

    MutableTreeNode n23 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.WaterfallChartDemo1", "WaterfallChartDemo1"));

    root.add(n1);
    root.add(n2);
    root.add(n3);
    root.add(n4);
    root.add(n5);
    // root.add(n6);
    root.add(n7);
    root.add(n8);
    root.add(n9);
    // root.add(n10);
    root.add(n11);
    root.add(n12);
    root.add(n13);
    // root.add(n14);
    root.add(n15);
    root.add(n16);
    root.add(n17);
    root.add(n18);
    root.add(n19);
    root.add(n20);
    root.add(n21);
    root.add(n22);
    root.add(n23);

    return root;
}

From source file:com.pironet.tda.SunJDKParser.java

/**
 * check if any dead lock information is logged in the stream
 *
 * @param threadDump which tree node to add the histogram.
 *//*from   w  ww .jav  a  2  s  .co  m*/
private int checkForDeadlocks(DefaultMutableTreeNode threadDump) throws IOException {
    boolean finished = false;
    boolean found = false;
    int deadlocks = 0;
    int lineCounter = 0;
    StringBuffer dContent = new StringBuffer();
    TreeCategory deadlockCat = new TreeCategory("Deadlocks", IconFactory.DEADLOCKS);
    DefaultMutableTreeNode catDeadlocks = new DefaultMutableTreeNode(deadlockCat);
    boolean first = true;

    while (getBis().ready() && !finished) {
        String line = getNextLine();

        if (!found && !Strings.isNullOrEmpty(line)) {
            if (line.trim().startsWith("Found one Java-level deadlock")) {
                found = true;
                dContent.append("<body bgcolor=\"ffffff\"><font size=").append(TDA.getFontSizeModifier(-1))
                        .append("><b>");
                dContent.append("Found one Java-level deadlock");
                dContent.append("</b><hr></font><pre>\n");
            } else if (lineCounter >= getMaxCheckLines()) {
                finished = true;
            } else {
                lineCounter++;
            }
        } else if (found) {
            if (line.startsWith("Found one Java-level deadlock")) {
                if (dContent.length() > 0) {
                    deadlocks++;
                    addToCategory(catDeadlocks, "Deadlock No. " + (deadlocks), null, dContent.toString(), 0,
                            false);
                }
                dContent = new StringBuffer();
                dContent.append("</pre><b><font size=").append(TDA.getFontSizeModifier(-1)).append('>');
                dContent.append("Found one Java-level deadlock");
                dContent.append("</b><hr></font><pre>\n");
                first = true;
            } else if ((line.contains("Found"))
                    && (line.endsWith("deadlocks.") || line.endsWith("deadlock."))) {
                finished = true;
            } else if (line.startsWith("=======")) {
                // ignore this line
            } else if (line.contains(" monitor 0x")) {
                dContent.append(linkifyDeadlockInfo(line));
                dContent.append('\n');
            } else if (line.contains("Java stack information for the threads listed above")) {
                dContent.append("</pre><br><font size=").append(TDA.getFontSizeModifier(-1)).append("><b>");
                dContent.append("Java stack information for the threads listed above");
                dContent.append("</b><hr></font><pre>");
                first = true;
            } else if ((line.contains("- waiting on")) || (line.contains("- waiting to"))
                    || (line.contains("- locked")) || (line.contains("- parking to wait"))) {

                dContent.append(linkifyMonitor(line));
                dContent.append('\n');

            } else if (line.trim().startsWith("\"")) {
                dContent.append("</pre>");
                if (first) {
                    first = false;
                } else {
                    dContent.append("<br>");
                }
                dContent.append("<b><font size=").append(TDA.getFontSizeModifier(-1)).append("><code>");
                dContent.append(line);
                dContent.append("</font></code></b><pre>");
            } else {
                dContent.append(line);
                dContent.append('\n');
            }
        }
    }
    if (dContent.length() > 0) {
        deadlocks++;
        addToCategory(catDeadlocks, "Deadlock No. " + (deadlocks), null, dContent.toString(), 0, false);
    }

    if (deadlocks > 0) {
        threadDump.add(catDeadlocks);
        ((ThreadDumpInfo) threadDump.getUserObject()).setDeadlocks((TreeCategory) catDeadlocks.getUserObject());
        deadlockCat.setName("Deadlocks (" + deadlocks + (deadlocks == 1 ? " deadlock)" : " deadlocks)"));
    }

    return (deadlocks);
}

From source file:org.jfree.chart.demo.SuperDemo.java

private MutableTreeNode createMiscellaneousChartsNode() {
    DefaultMutableTreeNode defaultmutabletreenode = new DefaultMutableTreeNode("Miscellaneous");
    DefaultMutableTreeNode defaultmutabletreenode1 = new DefaultMutableTreeNode(
            new DemoDescription("BubbleChartDemo1", "BubbleChartDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode2 = new DefaultMutableTreeNode(
            new DemoDescription("BubbleChartDemo2", "BubbleChartDemo2.java"));
    DefaultMutableTreeNode defaultmutabletreenode3 = new DefaultMutableTreeNode(
            new DemoDescription("CategoryLabelPositionsDemo1", "CategoryLabelPositionsDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode4 = new DefaultMutableTreeNode(
            new DemoDescription("CategoryStepChartDemo1", "CategoryStepChartDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode5 = new DefaultMutableTreeNode(
            new DemoDescription("CompassDemo1", "CompassDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode6 = new DefaultMutableTreeNode(
            new DemoDescription("CompassFormatDemo1", "CompassFormatDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode7 = new DefaultMutableTreeNode(
            new DemoDescription("CompassFormatDemo2", "CompassFormatDemo2.java"));
    DefaultMutableTreeNode defaultmutabletreenode8 = new DefaultMutableTreeNode(
            new DemoDescription("DifferenceChartDemo1", "DifferenceChartDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode9 = new DefaultMutableTreeNode(
            new DemoDescription("DifferenceChartDemo2", "DifferenceChartDemo2.java"));
    DefaultMutableTreeNode defaultmutabletreenode10 = new DefaultMutableTreeNode(
            new DemoDescription("EventFrequencyDemo1", "EventFrequencyDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode11 = new DefaultMutableTreeNode(
            new DemoDescription("GradientPaintTransformerDemo1", "GradientPaintTransformerDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode12 = new DefaultMutableTreeNode(
            new DemoDescription("GridBandDemo1", "GridBandDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode13 = new DefaultMutableTreeNode(
            new DemoDescription("HideSeriesDemo1", "HideSeriesDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode14 = new DefaultMutableTreeNode(
            new DemoDescription("HideSeriesDemo2", "HideSeriesDemo2.java"));
    DefaultMutableTreeNode defaultmutabletreenode15 = new DefaultMutableTreeNode(
            new DemoDescription("HideSeriesDemo3", "HideSeriesDemo3.java"));
    DefaultMutableTreeNode defaultmutabletreenode16 = new DefaultMutableTreeNode(
            new DemoDescription("MultipleDatasetDemo1", "MultipleDatasetDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode17 = new DefaultMutableTreeNode(
            new DemoDescription("PolarChartDemo1", "PolarChartDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode18 = new DefaultMutableTreeNode(
            new DemoDescription("SpiderWebChartDemo1", "SpiderWebChartDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode19 = new DefaultMutableTreeNode(
            new DemoDescription("SymbolAxisDemo1", "SymbolAxisDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode20 = new DefaultMutableTreeNode(
            new DemoDescription("ThermometerDemo1", "ThermometerDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode21 = new DefaultMutableTreeNode(
            new DemoDescription("ThermometerDemo2", "ThermometerDemo2.java"));
    DefaultMutableTreeNode defaultmutabletreenode22 = new DefaultMutableTreeNode(
            new DemoDescription("TranslateDemo1", "TranslateDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode23 = new DefaultMutableTreeNode(
            new DemoDescription("YIntervalChartDemo1", "YIntervalChartDemo1.java"));
    defaultmutabletreenode.add(createAnnotationsNode());
    defaultmutabletreenode.add(createCrosshairChartsNode());
    defaultmutabletreenode.add(createDynamicChartsNode());
    defaultmutabletreenode.add(createItemLabelsNode());
    defaultmutabletreenode.add(createLegendNode());
    defaultmutabletreenode.add(createMarkersNode());
    defaultmutabletreenode.add(createOrientationNode());
    defaultmutabletreenode.add(defaultmutabletreenode1);
    defaultmutabletreenode.add(defaultmutabletreenode2);
    defaultmutabletreenode.add(defaultmutabletreenode3);
    defaultmutabletreenode.add(defaultmutabletreenode4);
    defaultmutabletreenode.add(defaultmutabletreenode5);
    defaultmutabletreenode.add(defaultmutabletreenode6);
    defaultmutabletreenode.add(defaultmutabletreenode7);
    defaultmutabletreenode.add(defaultmutabletreenode8);
    defaultmutabletreenode.add(defaultmutabletreenode9);
    defaultmutabletreenode.add(defaultmutabletreenode10);
    defaultmutabletreenode.add(defaultmutabletreenode11);
    defaultmutabletreenode.add(defaultmutabletreenode12);
    defaultmutabletreenode.add(defaultmutabletreenode13);
    defaultmutabletreenode.add(defaultmutabletreenode14);
    defaultmutabletreenode.add(defaultmutabletreenode15);
    defaultmutabletreenode.add(defaultmutabletreenode16);
    defaultmutabletreenode.add(defaultmutabletreenode17);
    defaultmutabletreenode.add(defaultmutabletreenode18);
    defaultmutabletreenode.add(defaultmutabletreenode19);
    defaultmutabletreenode.add(defaultmutabletreenode20);
    defaultmutabletreenode.add(defaultmutabletreenode21);
    defaultmutabletreenode.add(defaultmutabletreenode22);
    defaultmutabletreenode.add(defaultmutabletreenode23);
    return defaultmutabletreenode;
}

From source file:Importers.ExcelImporter.java

@Override
public DefaultMutableTreeNode readFile(File file) {
    System.out.println("==ExcelImporter=readFile: " + file.getAbsolutePath());
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("vulns");
    try {//from   ww  w.j av  a 2s . com

        POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(file));
        HSSFWorkbook wb = new HSSFWorkbook(fs);
        HSSFSheet sheet = wb.getSheetAt(0);
        HSSFRow row;
        HSSFCell cell;

        int rows; // No of rows
        rows = sheet.getPhysicalNumberOfRows();

        int cols = 0; // No of columns
        int tmp = 0;

        // This trick ensures that we get the data properly even if it doesn't start from first few rows
        for (int i = 0; i < 10 || i < rows; i++) {
            row = sheet.getRow(i);
            if (row != null) {
                tmp = sheet.getRow(i).getPhysicalNumberOfCells();
                if (tmp > cols) {
                    cols = tmp;
                }
            }
        }

        for (int r = 1; r < rows; r++) {
            row = sheet.getRow(r);
            if (row != null) {

                // Create a new vuln
                Vulnerability vuln = new Vulnerability();
                vuln.setTitle("NEW");
                vuln.setIs_custom_risk(true);
                vuln.setRisk_category("None");

                for (int c = 0; c < cols; c++) {
                    cell = row.getCell(c);
                    if (cell != null) {
                        // Your code here
                        String value = cell.getStringCellValue();
                        switch (c) {
                        case 1:// title
                            vuln.setTitle(value);
                            break;
                        case 2: // Risk
                            CellStyle style = cell.getCellStyle();
                            short colorIdx = style.getFillForegroundColor();
                            HSSFPalette palette = ((HSSFWorkbook) wb).getCustomPalette();
                            HSSFColor color = palette.getColor(colorIdx);
                            String cc = color.getHexString();
                            System.out.println(cc);
                            if (cc.equalsIgnoreCase("8080:8080:0")) {
                                vuln.setRisk_category("Critical");
                            } else if (cc.equalsIgnoreCase("FFFF:0:0")) {
                                vuln.setRisk_category("High");
                            } else if (cc.equalsIgnoreCase("FFFF:6666:0")) {
                                vuln.setRisk_category("Medium");
                            } else if (cc.equalsIgnoreCase("F2F2:ECEC:0")) {
                                vuln.setRisk_category("Low");
                            } else if (cc.equalsIgnoreCase("0:0:FFFF")) {
                                vuln.setRisk_category("Info");
                            }

                            break;
                        case 3:// cvss string
                            System.out.println(value);
                            if (value.equalsIgnoreCase("No CVSS Vector")) {
                                vuln.setIs_custom_risk(true);
                            } else {
                                vuln.setIs_custom_risk(false);
                                vuln.setCvss_vector_string("CVSS2#" + value);
                            }
                            break;
                        case 4://Description
                            vuln.setDescription(value);
                            break;
                        case 5://Recommendation
                            vuln.setRecommendation(value);
                            break;
                        case 6://Affected Hosts
                            try {
                                String[] lines = value.split("\n");

                                for (String line : lines) {
                                    String[] bits = line.split(" ");
                                    Host host = new Host();
                                    host.setIp_address(bits[0]);
                                    String portprotocol = bits[2];
                                    host.setPortnumber(portprotocol.split("/")[0]);
                                    host.setProtocol(portprotocol.split("/")[1]);
                                    vuln.addAffectedHost(host);
                                }
                            } catch (Exception ex) {
                                ;
                            }
                            break;
                        }

                    }
                }
                System.out.println(vuln);

                root.add(new DefaultMutableTreeNode(vuln));
            }
        }

    } catch (Exception ex) {
        ex.printStackTrace();
    }

    return root;
}

From source file:org.jfree.chart.demo.SuperDemo.java

private MutableTreeNode createCategoryBarChartsNode() {
    DefaultMutableTreeNode defaultmutabletreenode = new DefaultMutableTreeNode("CategoryPlot");
    DefaultMutableTreeNode defaultmutabletreenode1 = new DefaultMutableTreeNode(
            new DemoDescription("BarChartDemo1", "BarChartDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode2 = new DefaultMutableTreeNode(
            new DemoDescription("BarChartDemo2", "BarChartDemo2.java"));
    DefaultMutableTreeNode defaultmutabletreenode3 = new DefaultMutableTreeNode(
            new DemoDescription("BarChartDemo3", "BarChartDemo3.java"));
    DefaultMutableTreeNode defaultmutabletreenode4 = new DefaultMutableTreeNode(
            new DemoDescription("BarChartDemo4", "BarChartDemo4.java"));
    DefaultMutableTreeNode defaultmutabletreenode5 = new DefaultMutableTreeNode(
            new DemoDescription("BarChartDemo5", "BarChartDemo5.java"));
    DefaultMutableTreeNode defaultmutabletreenode6 = new DefaultMutableTreeNode(
            new DemoDescription("BarChartDemo6", "BarChartDemo6.java"));
    DefaultMutableTreeNode defaultmutabletreenode7 = new DefaultMutableTreeNode(
            new DemoDescription("BarChartDemo7", "BarChartDemo7.java"));
    DefaultMutableTreeNode defaultmutabletreenode8 = new DefaultMutableTreeNode(
            new DemoDescription("BarChartDemo8", "BarChartDemo8.java"));
    DefaultMutableTreeNode defaultmutabletreenode9 = new DefaultMutableTreeNode(
            new DemoDescription("BarChartDemo9", "BarChartDemo9.java"));
    DefaultMutableTreeNode defaultmutabletreenode10 = new DefaultMutableTreeNode(
            new DemoDescription("BarChartDemo10", "BarChartDemo10.java"));
    DefaultMutableTreeNode defaultmutabletreenode11 = new DefaultMutableTreeNode(
            new DemoDescription("BarChart3DDemo1", "BarChart3DDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode12 = new DefaultMutableTreeNode(
            new DemoDescription("BarChart3DDemo2", "BarChart3DDemo2.java"));
    DefaultMutableTreeNode defaultmutabletreenode13 = new DefaultMutableTreeNode(
            new DemoDescription("BarChart3DDemo3", "BarChart3DDemo3.java"));
    DefaultMutableTreeNode defaultmutabletreenode14 = new DefaultMutableTreeNode(
            new DemoDescription("BarChart3DDemo4", "BarChart3DDemo4.java"));
    DefaultMutableTreeNode defaultmutabletreenode15 = new DefaultMutableTreeNode(
            new DemoDescription("CylinderChartDemo1", "CylinderChartDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode16 = new DefaultMutableTreeNode(
            new DemoDescription("CylinderChartDemo2", "CylinderChartDemo2.java"));
    DefaultMutableTreeNode defaultmutabletreenode17 = new DefaultMutableTreeNode(
            new DemoDescription("IntervalBarChartDemo1", "IntervalBarChartDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode18 = new DefaultMutableTreeNode(
            new DemoDescription("LayeredBarChartDemo1", "LayeredBarChartDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode19 = new DefaultMutableTreeNode(
            new DemoDescription("LayeredBarChartDemo2", "LayeredBarChartDemo2.java"));
    DefaultMutableTreeNode defaultmutabletreenode20 = new DefaultMutableTreeNode(
            new DemoDescription("StackedBarChartDemo1", "StackedBarChartDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode21 = new DefaultMutableTreeNode(
            new DemoDescription("StackedBarChartDemo2", "StackedBarChartDemo2.java"));
    DefaultMutableTreeNode defaultmutabletreenode22 = new DefaultMutableTreeNode(
            new DemoDescription("StackedBarChartDemo3", "StackedBarChartDemo3.java"));
    DefaultMutableTreeNode defaultmutabletreenode23 = new DefaultMutableTreeNode(
            new DemoDescription("StackedBarChartDemo4", "StackedBarChartDemo4.java"));
    DefaultMutableTreeNode defaultmutabletreenode24 = new DefaultMutableTreeNode(
            new DemoDescription("StackedBarChartDemo5", "StackedBarChartDemo5.java"));
    DefaultMutableTreeNode defaultmutabletreenode25 = new DefaultMutableTreeNode(
            new DemoDescription("StackedBarChartDemo6", "StackedBarChartDemo6.java"));
    DefaultMutableTreeNode defaultmutabletreenode26 = new DefaultMutableTreeNode(
            new DemoDescription("StackedBarChartDemo7", "StackedBarChartDemo7.java"));
    DefaultMutableTreeNode defaultmutabletreenode27 = new DefaultMutableTreeNode(
            new DemoDescription("StatisticalBarChartDemo1", "StatisticalBarChartDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode28 = new DefaultMutableTreeNode(
            new DemoDescription("SurveyResultsDemo1", "SurveyResultsDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode29 = new DefaultMutableTreeNode(
            new DemoDescription("SurveyResultsDemo2", "SurveyResultsDemo2.java"));
    DefaultMutableTreeNode defaultmutabletreenode30 = new DefaultMutableTreeNode(
            new DemoDescription("SurveyResultsDemo3", "SurveyResultsDemo3.java"));
    DefaultMutableTreeNode defaultmutabletreenode31 = new DefaultMutableTreeNode(
            new DemoDescription("WaterfallChartDemo1", "WaterfallChartDemo1.java"));
    defaultmutabletreenode.add(defaultmutabletreenode1);
    defaultmutabletreenode.add(defaultmutabletreenode2);
    defaultmutabletreenode.add(defaultmutabletreenode3);
    defaultmutabletreenode.add(defaultmutabletreenode4);
    defaultmutabletreenode.add(defaultmutabletreenode5);
    defaultmutabletreenode.add(defaultmutabletreenode6);
    defaultmutabletreenode.add(defaultmutabletreenode7);
    defaultmutabletreenode.add(defaultmutabletreenode8);
    defaultmutabletreenode.add(defaultmutabletreenode9);
    defaultmutabletreenode.add(defaultmutabletreenode10);
    defaultmutabletreenode.add(defaultmutabletreenode11);
    defaultmutabletreenode.add(defaultmutabletreenode12);
    defaultmutabletreenode.add(defaultmutabletreenode13);
    defaultmutabletreenode.add(defaultmutabletreenode14);
    defaultmutabletreenode.add(defaultmutabletreenode15);
    defaultmutabletreenode.add(defaultmutabletreenode16);
    defaultmutabletreenode.add(defaultmutabletreenode17);
    defaultmutabletreenode.add(defaultmutabletreenode18);
    defaultmutabletreenode.add(defaultmutabletreenode19);
    defaultmutabletreenode.add(defaultmutabletreenode20);
    defaultmutabletreenode.add(defaultmutabletreenode21);
    defaultmutabletreenode.add(defaultmutabletreenode22);
    defaultmutabletreenode.add(defaultmutabletreenode23);
    defaultmutabletreenode.add(defaultmutabletreenode24);
    defaultmutabletreenode.add(defaultmutabletreenode25);
    defaultmutabletreenode.add(defaultmutabletreenode26);
    defaultmutabletreenode.add(defaultmutabletreenode27);
    defaultmutabletreenode.add(defaultmutabletreenode28);
    defaultmutabletreenode.add(defaultmutabletreenode29);
    defaultmutabletreenode.add(defaultmutabletreenode30);
    defaultmutabletreenode.add(defaultmutabletreenode31);
    return defaultmutabletreenode;
}

From source file:com.monead.semantic.workbench.SemanticWorkbench.java

/**
 * Build a tree representation of the semantic model
 * /*from  w  w  w .  ja va  2s.  c o  m*/
 * TODO aggregate items from duplicate nodes
 * 
 * TODO Consider more efficient approach that scans the model once rather than
 * querying for each class, individual and property collection
 * 
 * @see #addClassesToTree(DefaultMutableTreeNode, String)
 * @see OntologyTreeCellRenderer
 * 
 * @return The message to be presented on the status line
 */
private String createTreeFromModel() {
    final String messagePrefix = "Creating the tree view";
    DefaultMutableTreeNode treeTopNode;
    DefaultMutableTreeNode classesNode;
    String message;
    int maxIndividualsPerClass;

    setStatus(messagePrefix);
    setWaitCursor(true);

    clearTree();

    try {
        maxIndividualsPerClass = Integer.parseInt(
                properties.getProperty(ConfigurationProperty.MAX_INDIVIDUALS_PER_CLASS_IN_TREE.key(), "0"));
    } catch (Throwable throwable) {
        maxIndividualsPerClass = 0;
    }

    treeTopNode = new DefaultMutableTreeNode("Model");

    // Ignore latest value since we have just released the old tree (if there
    // was one)
    MemoryWarningSystem.hasLatestAvailableTenuredGenAfterCollectionChanged(this);

    // Classes
    classesNode = new DefaultMutableTreeNode("Classes");
    treeTopNode.add(classesNode);

    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Building list of classes in the model");
    }

    try {
        addClassesToTree(classesNode, maxIndividualsPerClass, messagePrefix);

        // Select the tree view tab
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                tabbedPane.setSelectedIndex(TAB_NUMBER_TREE_VIEW);
            }
        });

        message = "Tree view of current model created";
        if (maxIndividualsPerClass > 0) {
            message += " (individuals per class limited to " + maxIndividualsPerClass + ")";
        }

        ontModelTree.setModel(new DefaultTreeModel(treeTopNode));
        isTreeInSyncWithModel = true;
        colorCodeTabs();
    } catch (IllegalStateException ise) {
        // Memory exhaustion, keep the incomplete tree
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                tabbedPane.setSelectedIndex(TAB_NUMBER_TREE_VIEW);
            }
        });
        message = "Insufficient memory for entire tree, partial tree view of current model created";
        ontModelTree.setModel(new DefaultTreeModel(treeTopNode));
        isTreeInSyncWithModel = false;
        colorCodeTabs();
        throw ise;
    } catch (RuntimeException rte) {
        if (rte.getMessage().contains("canceled by user")) {
            message = rte.getMessage();
        } else {
            throw rte;
        }
    }

    return message;
}

From source file:com.monead.semantic.workbench.SemanticWorkbench.java

/**
 * Add individuals of a class to the tree
 * //from www .  j ava  2 s. c  o m
 * @see #addStatementsToTree(OntClass, Individual, DefaultMutableTreeNode,
 *      ProgressMonitor)
 * 
 * @param ontClass
 *          The class of individuals to be added
 * @param oneClassNode
 *          The class's node in the tree
 * @param maxIndividualsPerClass
 *          The maximum number of individuals to display in each class
 * @param progress
 *          A progress monitor to display progress to the user
 */
private void addIndividualsToTree(OntClass ontClass, DefaultMutableTreeNode oneClassNode,
        int maxIndividualsPerClass, ProgressMonitor progress) {
    DefaultMutableTreeNode oneIndividualNode;
    List<Individual> individuals;
    ExtendedIterator<Individual> individualsIterator;
    int nodeCount = 0;

    // Individuals
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Get list of individuals for " + ontClass.getURI());
    }
    individualsIterator = ontModel.listIndividuals(ontClass);
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("List of individuals built for " + ontClass.getURI()
                + " Is there at least one individual? " + individualsIterator.hasNext());
    }
    individuals = new ArrayList<Individual>();

    while (individualsIterator.hasNext()) {
        individuals.add(individualsIterator.next());
        ++nodeCount;
        if (maxIndividualsPerClass > 0 && nodeCount >= maxIndividualsPerClass) {
            break;
        }
    }

    Collections.sort(individuals, new IndividualComparator());
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("List of individuals sorted for " + ontClass.getURI());
    }

    for (Individual individual : individuals) {
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Next individual: " + individual.getLocalName());
        }

        if (MemoryWarningSystem.hasLatestAvailableTenuredGenAfterCollectionChanged(this) && MemoryWarningSystem
                .getLatestAvailableTenuredGenAfterCollection() < MINIMUM_BYTES_REQUIRED_FOR_TREE_BUILD) {
            throw new IllegalStateException(
                    "Insufficient memory available to complete building the tree (individual iteration)");
        }

        if (individual.isAnon()) {
            // Show anonymous individuals based on configuration
            if (filterShowAnonymousNodes.isSelected()) {
                if (individual.getId().getLabelString() != null) {
                    oneIndividualNode = new DefaultMutableTreeNode(new WrapperInstance(
                            individual.getId().getLabelString(), "[Anonymous individual]", true));
                } else {
                    oneIndividualNode = new DefaultMutableTreeNode(new WrapperInstance(individual.toString(),
                            "[null label - anonymous individual]", true));
                }
            } else {
                LOGGER.debug("Skip anonymous individual: " + individual.getId().getLabelString());
                continue;
            }
        } else if (individual.getLocalName() != null) {
            oneIndividualNode = new DefaultMutableTreeNode(new WrapperInstance(individual.getLocalName(),
                    individual.getURI(), showFqnInTree.isSelected()));
        } else {
            oneIndividualNode = new DefaultMutableTreeNode(
                    new WrapperInstance(individual.toString(), "[null name - non anonymous]", true));
        }
        oneClassNode.add(oneIndividualNode);

        addStatementsToTree(individual, oneIndividualNode, progress);
    }

}

From source file:com.monead.semantic.workbench.SemanticWorkbench.java

/**
 * Add statements to the tree (predicates and properties)
 * //  w w  w.ja v  a 2 s .c  om
 * @param individual
 *          The individual whose statements are to be added to the tree
 * @param oneIndividualNode
 *          The individual's node in the tree
 * @param progress
 *          A progress monitor to display progress to the user
 */
private void addStatementsToTree(Individual individual, DefaultMutableTreeNode oneIndividualNode,
        ProgressMonitor progress) {
    DefaultMutableTreeNode onePropertyNode;
    List<Statement> statements;
    Property property;
    RDFNode rdfNode;
    Literal literal;
    StmtIterator stmtIterator;

    // Properties (predicates) and Objects
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Get list of statements for " + individual.getURI());
    }
    stmtIterator = individual.listProperties();
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("List of statements built for " + individual.getURI());
    }
    statements = new ArrayList<Statement>();
    while (stmtIterator.hasNext()) {
        statements.add(stmtIterator.next());
    }
    Collections.sort(statements, new StatementComparator());
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("List of statements sorted for " + individual.getURI());
    }

    for (Statement statement : statements) {
        property = statement.getPredicate();

        // Check whether predicate is to be skipped
        if (filterEnableFilters.isSelected() && predicatesToSkipInTree.get(property.getURI()) != null) {
            continue;
        }

        rdfNode = statement.getObject();

        if (MemoryWarningSystem.hasLatestAvailableTenuredGenAfterCollectionChanged(this) && MemoryWarningSystem
                .getLatestAvailableTenuredGenAfterCollection() < MINIMUM_BYTES_REQUIRED_FOR_TREE_BUILD) {
            throw new IllegalStateException(
                    "Insufficient memory available to complete building the tree (statement iteration)");
        }

        if (property.isAnon()) {
            // Show anonymous properties based on configuration
            if (filterShowAnonymousNodes.isSelected()) {
                if (rdfNode.isLiteral()) {
                    onePropertyNode = new DefaultMutableTreeNode(new WrapperDataProperty(
                            property.getId().getLabelString(), "[Anonymous data property]", true));
                } else {
                    onePropertyNode = new DefaultMutableTreeNode(new WrapperObjectProperty(
                            property.getId().getLabelString(), "[Anonymous object property]", true));
                }
            } else {
                LOGGER.debug("Skip anonymous property: " + property.getId().getLabelString());
                continue;
            }
        } else if (rdfNode.isLiteral() || !statement.getResource().isAnon()
                || filterShowAnonymousNodes.isSelected()) {
            if (rdfNode.isLiteral()) {
                onePropertyNode = new DefaultMutableTreeNode(new WrapperDataProperty(property.getLocalName(),
                        property.getURI(), showFqnInTree.isSelected()));
            } else {
                onePropertyNode = new DefaultMutableTreeNode(new WrapperObjectProperty(property.getLocalName(),
                        property.getURI(), showFqnInTree.isSelected()));
            }
        } else {
            LOGGER.debug("Skip concrete property of an anonymous individual: " + property.getURI() + ", "
                    + statement.getResource().getId().getLabelString());
            continue;

        }
        oneIndividualNode.add(onePropertyNode);

        if (rdfNode.isLiteral()) {
            literal = statement.getLiteral();
            if (setupOutputDatatypesForLiterals.isSelected()) {
                onePropertyNode.add(new DefaultMutableTreeNode(new WrapperLiteral(
                        ValueFormatter.getInstance().applyFormat(literal.getString(), literal.getDatatypeURI())
                                + " [" + literal.getDatatypeURI() + "]")));

            } else {
                onePropertyNode.add(new DefaultMutableTreeNode(new WrapperLiteral(ValueFormatter.getInstance()
                        .applyFormat(literal.getString(), literal.getDatatypeURI()))));
            }
        } else {
            if (statement.getResource().isAnon()) {
                if (filterShowAnonymousNodes.isSelected()) {
                    onePropertyNode.add(new DefaultMutableTreeNode(new WrapperInstance(
                            statement.getResource().getId().getLabelString(), "[Anonymous individual]", true)));
                } else {
                    LOGGER.debug(
                            "Skip anonymous individual: " + statement.getResource().getId().getLabelString());
                    continue;
                }
            } else {
                onePropertyNode.add(
                        new DefaultMutableTreeNode(new WrapperInstance(statement.getResource().getLocalName(),
                                statement.getResource().getURI(), showFqnInTree.isSelected())));
            }
        }
    }
}

From source file:com.monead.semantic.workbench.SemanticWorkbench.java

/**
 * Add the classes to the tree view/*  ww  w.j a v  a  2 s .c om*/
 * 
 * @see #addIndividualsToTree(OntClass, DefaultMutableTreeNode,
 *      ProgressMonitor)
 * 
 * @param classesNode
 *          The classes parent node in the tree
 * @param maxIndividualsPerClass
 *          The maximum number of individuals to display in each class
 * @param messagePrefix
 *          Prefix for display messages
 */
private void addClassesToTree(DefaultMutableTreeNode classesNode, int maxIndividualsPerClass,
        String messagePrefix) {
    ProgressMonitor progress = null;
    DefaultMutableTreeNode oneClassNode;
    List<OntClass> ontClasses;
    ExtendedIterator<OntClass> classesIterator;
    int classNumber;
    try {
        classesIterator = ontModel.listClasses();

        setStatus(messagePrefix + "... obtaining the list of classes");

        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("List of classes built");
        }
        ontClasses = new ArrayList<OntClass>();
        while (classesIterator.hasNext()) {
            ontClasses.add(classesIterator.next());
        }
        progress = new ProgressMonitor(this, "Create the model tree view", "Setting up the class list", 0,
                ontClasses.size());
        Collections.sort(ontClasses, new OntClassComparator());
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("List of classes sorted. Num classes:" + ontClasses.size());
        }

        classNumber = 0;
        for (OntClass ontClass : ontClasses) {
            setStatus(messagePrefix + " for class " + ontClass);

            if (MemoryWarningSystem.hasLatestAvailableTenuredGenAfterCollectionChanged(this)
                    && MemoryWarningSystem
                            .getLatestAvailableTenuredGenAfterCollection() < MINIMUM_BYTES_REQUIRED_FOR_TREE_BUILD) {
                throw new IllegalStateException(
                        "Insufficient memory available to complete building the tree (class iteration)");
            }

            if (progress.isCanceled()) {
                throw new RuntimeException("Tree model creation canceled by user");
            }

            progress.setNote(ontClass.toString());
            progress.setProgress(++classNumber);

            // Check whether class is to be skipped
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Check if class to be skipped: " + ontClass.getURI());
                for (String skipClass : classesToSkipInTree.keySet()) {
                    LOGGER.trace("Class to skip: " + skipClass + "  equal? "
                            + (skipClass.equals(ontClass.getURI())));
                }
            }
            if (filterEnableFilters.isSelected() && classesToSkipInTree.get(ontClass.getURI()) != null) {
                LOGGER.debug("Class to be skipped: " + ontClass.getURI());
                continue;
            }

            if (ontClass.isAnon()) {
                // Show anonymous classes based on configuration
                if (filterShowAnonymousNodes.isSelected()) {
                    oneClassNode = new DefaultMutableTreeNode(
                            new WrapperClass(ontClass.getId().getLabelString(), "[Anonymous class]", true));
                } else {
                    LOGGER.debug("Skip anonymous class: " + ontClass.getId().getLabelString());
                    continue;
                }
            } else {
                oneClassNode = new DefaultMutableTreeNode(new WrapperClass(ontClass.getLocalName(),
                        ontClass.getURI(), showFqnInTree.isSelected()));
                LOGGER.debug("Add class node: " + ontClass.getLocalName() + " (" + ontClass.getURI() + ")");
            }
            classesNode.add(oneClassNode);

            addIndividualsToTree(ontClass, oneClassNode, maxIndividualsPerClass, progress);
        }

    } finally {
        if (progress != null) {
            progress.close();
        }
    }
}