List of usage examples for javax.swing.tree DefaultMutableTreeNode DefaultMutableTreeNode
public DefaultMutableTreeNode(Object userObject)
From source file:EditorPaneExample13.java
public EditorPaneExample13() { super("JEditorPane Example 13"); pane = new JEditorPane(); pane.setEditable(false); // Read-only getContentPane().add(new JScrollPane(pane), "Center"); // Build the panel of controls JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = 1;/*from w w w. j av a2s . c o m*/ c.gridheight = 1; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.NONE; c.weightx = 0.0; c.weighty = 0.0; JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT); panel.add(urlLabel, c); JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT); c.gridy = 1; panel.add(loadingLabel, c); JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT); c.gridy = 2; panel.add(typeLabel, c); c.gridy = 3; panel.add(new JLabel(LOAD_TIME), c); c.gridy = 4; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; onlineLoad = new JCheckBox("Online Load"); panel.add(onlineLoad, c); onlineLoad.setSelected(true); onlineLoad.setForeground(typeLabel.getForeground()); c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.HORIZONTAL; urlCombo = new JComboBox(); panel.add(urlCombo, c); urlCombo.setEditable(true); loadingState = new JLabel(spaces, JLabel.LEFT); loadingState.setForeground(Color.black); c.gridy = 1; panel.add(loadingState, c); loadedType = new JLabel(spaces, JLabel.LEFT); loadedType.setForeground(Color.black); c.gridy = 2; panel.add(loadedType, c); timeLabel = new JLabel(""); c.gridy = 3; panel.add(timeLabel, c); getContentPane().add(panel, "South"); // Load a new default style sheet InputStream is = EditorPaneExample13.class.getResourceAsStream("changedDefault.css"); if (is != null) { try { StyleSheet ss = loadStyleSheet(is); editorKit.setStyleSheet(ss); } catch (IOException e) { System.out.println("Failed to load new default style sheet"); } } // Allocate the empty tree model DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode("Empty"); emptyModel = new DefaultTreeModel(emptyRootNode); // Create and place the heading tree tree = new JTree(emptyModel); tree.setPreferredSize(new Dimension(200, 200)); getContentPane().add(new JScrollPane(tree), "East"); // Change page based on combo selection urlCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (populatingCombo == true) { return; } Object selection = urlCombo.getSelectedItem(); loadNewPage(selection); } }); // Listen for page load to complete pane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("page")) { loadComplete(); displayLoadTime(); populateCombo(findLinks(pane.getDocument(), null)); TreeNode node = buildHeadingTree(pane.getDocument()); tree.setModel(new DefaultTreeModel(node)); enableInput(); loadingPage = false; } } }); // Listener for tree selection tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent evt) { TreePath path = evt.getNewLeadSelectionPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object userObject = node.getUserObject(); if (userObject instanceof Heading) { Heading heading = (Heading) userObject; try { Rectangle textRect = pane.modelToView(heading.getOffset()); textRect.y += 3 * textRect.height; pane.scrollRectToVisible(textRect); } catch (BadLocationException e) { } } } } }); // Listener for hypertext events pane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent evt) { // Ignore hyperlink events if the frame is busy if (loadingPage == true) { return; } if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { JEditorPane sp = (JEditorPane) evt.getSource(); if (evt instanceof HTMLFrameHyperlinkEvent) { HTMLDocument doc = (HTMLDocument) sp.getDocument(); doc.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) evt); } else { loadNewPage(evt.getURL()); } } else if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) { pane.setCursor(handCursor); } else if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) { pane.setCursor(defaultCursor); } } }); }
From source file:edu.ucla.stat.SOCR.chart.ChartTree.java
/** * Creates a tree node containing sample bar charts. * /*from www .j ava 2 s.co m*/ * @return The tree node. */ private MutableTreeNode createBarChartsNode() { DefaultMutableTreeNode root = new DefaultMutableTreeNode("Bar Charts"); root.add(createCategoryBarChartsNode()); root.add(createXYBarChartsNode()); return root; }
From source file:edu.harvard.i2b2.query.QueryConceptTreePanel.java
public DefaultMutableTreeNode addNode(QueryConceptTreeNodeData node) { DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(node); QueryConceptTreeNodeData tmpData = new QueryConceptTreeNodeData(); tmpData.name("working ......"); tmpData.tooltip("A tmp node"); tmpData.visualAttribute("LAO"); DefaultMutableTreeNode tmpNode = new DefaultMutableTreeNode(tmpData); treeModel.insertNodeInto(childNode, top, top.getChildCount()); treeModel.insertNodeInto(tmpNode, childNode, childNode.getChildCount()); //Make sure the user can see the lovely new node. jTree1.scrollPathToVisible(new TreePath(childNode.getPath())); return childNode; }
From source file:org.dcm4chee.dashboard.ui.filesystem.FileSystemPanel.java
@Override public void onBeforeRender() { super.onBeforeRender(); try {//from w w w.j av a2s . c o m DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(new FileSystemModel()); for (String groupname : DashboardDelegator .getInstance( (((BaseWicketApplication) getApplication()).getInitParameter("DashboardServiceName"))) .listAllFileSystemGroups()) { FileSystemModel group = new FileSystemModel(); int index = groupname.indexOf("group="); if (index < 0) continue; group.setDirectoryPath(groupname.substring(index + 6)); group.setDescription(groupname + ",AET=" + DashboardDelegator.getInstance( (((BaseWicketApplication) getApplication()).getInitParameter("DashboardServiceName"))) .getDefaultRetrieveAETitle(groupname)); group.setGroup(true); DefaultMutableTreeNode groupNode; rootNode.add(groupNode = new DefaultMutableTreeNode(group)); File[] fileSystems = null; try { fileSystems = DashboardDelegator.getInstance( (((BaseWicketApplication) getApplication()).getInitParameter("DashboardServiceName"))) .listFileSystemsOfGroup(groupname); } catch (MBeanException mbe) { } if (!((fileSystems == null) || (fileSystems.length == 0))) { long minBytesFree = DashboardDelegator.getInstance( (((BaseWicketApplication) getApplication()).getInitParameter("DashboardServiceName"))) .getMinimumFreeDiskSpaceOfGroup(groupname); for (File file : fileSystems) { FileSystemModel fsm = new FileSystemModel(); fsm.setDirectoryPath(file.getName()); fsm.setDescription( file.getName().startsWith("tar:") ? file.getName() : file.getAbsolutePath()); fsm.setOverallDiskSpace(file.getTotalSpace() / FileSystemModel.MEGA); fsm.setUsedDiskSpace( Math.max((file.getTotalSpace() - file.getUsableSpace()) / FileSystemModel.MEGA, 0)); fsm.setFreeDiskSpace(Math.max(file.getUsableSpace() / FileSystemModel.MEGA, 0)); fsm.setMinimumFreeDiskSpace( fsm.getOverallDiskSpaceLong() == 0 ? 0 : minBytesFree / FileSystemModel.MEGA); fsm.setUsableDiskSpace( Math.max((file.getUsableSpace() - minBytesFree) / FileSystemModel.MEGA, 0)); fsm.setRemainingTime(Math.max((file.getUsableSpace() - minBytesFree) / DashboardDelegator .getInstance((((BaseWicketApplication) getApplication()) .getInitParameter("DashboardServiceName"))) .getExpectedDataVolumePerDay(groupname), 0)); group.setOverallDiskSpace(group.getOverallDiskSpaceLong() + fsm.getOverallDiskSpaceLong()); group.setUsedDiskSpace(group.getUsedDiskSpaceLong() + fsm.getUsedDiskSpaceLong()); group.setFreeDiskSpace(group.getFreeDiskSpaceLong() + fsm.getFreeDiskSpaceLong()); group.setMinimumFreeDiskSpace( group.getMinimumFreeDiskSpaceLong() + fsm.getMinimumFreeDiskSpaceLong()); group.setUsableDiskSpace(group.getUsableDiskSpaceLong() + fsm.getUsableDiskSpaceLong()); group.setRemainingTime(group.getRemainingTime() + fsm.getRemainingTime()); groupNode.add(new DefaultMutableTreeNode(fsm)); } } } String[] otherFileSystems = DashboardDelegator .getInstance( (((BaseWicketApplication) getApplication()).getInitParameter("DashboardServiceName"))) .listOtherFileSystems(); if (otherFileSystems != null && otherFileSystems.length > 0) { FileSystemModel group = new FileSystemModel(); group.setDirectoryPath( new ResourceModel("dashboard.filesystem.group.other").wrapOnAssignment(this).getObject()); group.setGroup(true); group.setRemainingTime(-1); DefaultMutableTreeNode groupNode; rootNode.add(groupNode = new DefaultMutableTreeNode(group)); for (String otherFileSystem : otherFileSystems) { File file = new File(otherFileSystem); FileSystemModel fsm = new FileSystemModel(); fsm.setDirectoryPath(file.getAbsolutePath()); fsm.setDescription(file.getName().startsWith("tar:") ? file.getName() : file.getAbsolutePath()); fsm.setOverallDiskSpace(file.getTotalSpace() / FileSystemModel.MEGA); fsm.setUsedDiskSpace( Math.max((file.getTotalSpace() - file.getUsableSpace()) / FileSystemModel.MEGA, 0)); fsm.setFreeDiskSpace(Math.max(file.getUsableSpace() / FileSystemModel.MEGA, 0)); fsm.setMinimumFreeDiskSpace(fsm.getOverallDiskSpaceLong() / FileSystemModel.MEGA); fsm.setUsableDiskSpace(Math.max(file.getUsableSpace() / FileSystemModel.MEGA, 0)); fsm.setRemainingTime(-1); group.setOverallDiskSpace(group.getOverallDiskSpaceLong() + fsm.getOverallDiskSpaceLong()); group.setUsedDiskSpace(group.getUsedDiskSpaceLong() + fsm.getUsedDiskSpaceLong()); group.setFreeDiskSpace(group.getFreeDiskSpaceLong() + fsm.getFreeDiskSpaceLong()); group.setMinimumFreeDiskSpace( group.getMinimumFreeDiskSpaceLong() + fsm.getMinimumFreeDiskSpaceLong()); group.setUsableDiskSpace(group.getUsableDiskSpaceLong() + fsm.getUsableDiskSpaceLong()); group.setVisible(false); groupNode.add(new DefaultMutableTreeNode(fsm)); } } FileSystemTreeTable fileSystemTreeTable = new FileSystemTreeTable("filesystem-tree-table", new DefaultTreeModel(rootNode), new IColumn[] { new PropertyTreeColumn(new ColumnLocation(Alignment.LEFT, 25, Unit.PERCENT), new ResourceModel("dashboard.filesystem.table.column.name") .wrapOnAssignment(this).getObject(), "userObject.directoryPath"), new ImageRenderableColumn(new ColumnLocation(Alignment.MIDDLE, 30, Unit.PROPORTIONAL), new ResourceModel("dashboard.filesystem.table.column.image") .wrapOnAssignment(this).getObject(), "userObject.directoryPath"), new PropertyRenderableColumn(new ColumnLocation(Alignment.RIGHT, 7, Unit.PERCENT), new ResourceModel("dashboard.filesystem.table.column.overall") .wrapOnAssignment(this).getObject(), "userObject.overallDiskSpaceString"), new PropertyRenderableColumn(new ColumnLocation(Alignment.RIGHT, 7, Unit.PERCENT), new ResourceModel("dashboard.filesystem.table.column.used") .wrapOnAssignment(this).getObject(), "userObject.usedDiskSpaceString"), new PropertyRenderableColumn(new ColumnLocation(Alignment.RIGHT, 7, Unit.PERCENT), new ResourceModel("dashboard.filesystem.table.column.free") .wrapOnAssignment(this).getObject(), "userObject.freeDiskSpaceString"), new PropertyRenderableColumn(new ColumnLocation(Alignment.RIGHT, 7, Unit.PERCENT), new ResourceModel("dashboard.filesystem.table.column.minimumfree") .wrapOnAssignment(this).getObject(), "userObject.minimumFreeDiskSpaceString"), new PropertyRenderableColumn(new ColumnLocation(Alignment.RIGHT, 7, Unit.PERCENT), new ResourceModel("dashboard.filesystem.table.column.usable") .wrapOnAssignment(this).getObject(), "userObject.usableDiskSpaceString"), new PropertyRenderableColumn(new ColumnLocation(Alignment.RIGHT, 10, Unit.PERCENT), new ResourceModel("dashboard.filesystem.table.column.remainingtime") .wrapOnAssignment(this).getObject(), "userObject.remainingTimeString") }); fileSystemTreeTable.getTreeState().setAllowSelectMultiple(true); fileSystemTreeTable.getTreeState().collapseAll(); fileSystemTreeTable.setRootLess(true); addOrReplace(fileSystemTreeTable); } catch (Exception e) { log.error(this.getClass().toString() + ": " + "onBeforeRender: " + e.getMessage()); log.debug("Exception: ", e); throw new WicketRuntimeException(e.getLocalizedMessage(), e); } }
From source file:com.pironet.tda.SunJDKParser.java
/** * parse the next thread dump from the stream passed with the constructor. * * @return null if no more thread dumps were found. *///from w w w . j av a 2 s.com public MutableTreeNode parseNext() { if (nextDump != null) { MutableTreeNode tmpDump = nextDump; nextDump = null; return (tmpDump); } boolean retry = false; String line = null; do { try { Map<String, String> threads = new HashMap<>(); ThreadDumpInfo overallTDI = new ThreadDumpInfo("Dump No. " + counter++, 0); if (withCurrentTimeStamp) { overallTDI.setStartTime((new Date(System.currentTimeMillis())).toString()); } DefaultMutableTreeNode threadDump = new DefaultMutableTreeNode(overallTDI); DefaultMutableTreeNode catThreads = new DefaultMutableTreeNode( new TableCategory("Threads", IconFactory.THREADS)); threadDump.add(catThreads); DefaultMutableTreeNode catWaiting = new DefaultMutableTreeNode( new TableCategory("Threads waiting for Monitors", IconFactory.THREADS_WAITING)); DefaultMutableTreeNode catSleeping = new DefaultMutableTreeNode( new TableCategory("Threads sleeping on Monitors", IconFactory.THREADS_SLEEPING)); DefaultMutableTreeNode catLocking = new DefaultMutableTreeNode( new TableCategory("Threads locking Monitors", IconFactory.THREADS_LOCKING)); // create category for monitors with disabled filtering. // NOTE: These strings are "magic" in that the methods // TDA#displayCategory and TreeCategory#getCatComponent both // checks these literal strings and the behavior differs. DefaultMutableTreeNode catMonitors = new DefaultMutableTreeNode( new TreeCategory("Monitors", IconFactory.MONITORS, false)); DefaultMutableTreeNode catMonitorsLocks = new DefaultMutableTreeNode( new TreeCategory("Monitors without locking thread", IconFactory.MONITORS_NO_LOCKS, false)); DefaultMutableTreeNode catBlockingMonitors = new DefaultMutableTreeNode( new TreeCategory("Threads blocked by Monitors", IconFactory.THREADS_LOCKING, false)); String title = null; String dumpKey = null; StringBuffer content = null; boolean inLocking = false; boolean inSleeping = false; boolean inWaiting = false; int threadCount = 0; int waiting = 0; int locking = 0; int sleeping = 0; boolean locked = true; boolean finished = false; final MonitorMap mmap = new MonitorMap(); final Stack<String> monitorStack = new Stack<>(); long startTime = 0; int singleLineCounter = 0; boolean concurrentSyncsFlag = false; Matcher matched = getDm().getLastMatch(); while (getBis().ready() && !finished) { line = getNextLine(); lineCounter++; singleLineCounter++; if (locked) { if (line.contains("Full thread dump")) { locked = false; if (!withCurrentTimeStamp) { overallTDI.setLogLine(lineCounter); if (startTime != 0) { startTime = 0; } else if (matched != null && matched.matches()) { String parsedStartTime = matched.group(1); if (!getDm().isDefaultMatches() && isMillisTimeStamp()) { try { // the factor is a hack for a bug in oc4j timestamp printing (pattern timeStamp=2342342340) if (parsedStartTime.length() < 13) { startTime = Long.parseLong(parsedStartTime) * (long) Math.pow(10, 13 - parsedStartTime.length()); } else { startTime = Long.parseLong(parsedStartTime); } } catch (NumberFormatException nfe) { startTime = 0; } if (startTime > 0) { overallTDI.setStartTime((new Date(startTime)).toString()); } } else { overallTDI.setStartTime(parsedStartTime); } matched = null; getDm().resetLastMatch(); } } dumpKey = overallTDI.getName(); } else if (!getDm().isPatternError() && (getDm().getRegexPattern() != null)) { Matcher m = getDm().checkForDateMatch(line); if (m != null) { matched = m; } } } else { if (line.startsWith("\"")) { // We are starting a group of lines for a different thread // First, flush state for the previous thread (if any) concurrentSyncsFlag = false; String stringContent = content != null ? content.toString() : null; if (title != null) { threads.put(title, content.toString()); content.append("</pre></pre>"); addToCategory(catThreads, title, null, stringContent, singleLineCounter, true); threadCount++; } if (inWaiting) { addToCategory(catWaiting, title, null, stringContent, singleLineCounter, true); inWaiting = false; waiting++; } if (inSleeping) { addToCategory(catSleeping, title, null, stringContent, singleLineCounter, true); inSleeping = false; sleeping++; } if (inLocking) { addToCategory(catLocking, title, null, stringContent, singleLineCounter, true); inLocking = false; locking++; } singleLineCounter = 0; while (!monitorStack.empty()) { mmap.parseAndAddThread(monitorStack.pop(), title, content.toString()); } // Second, initialize state for this new thread title = line; content = new StringBuffer("<body bgcolor=\"ffffff\"><pre><font size=" + TDA.getFontSizeModifier(-1) + '>'); content.append(line); content.append('\n'); } else if (line.contains("at ")) { content.append(line); content.append('\n'); } else if (line.contains("java.lang.Thread.State")) { content.append(line); content.append('\n'); if (title.indexOf("t@") > 0) { // in this case the title line is missing state informations String state = line.substring(line.indexOf(':') + 1).trim(); if (state.indexOf(' ') > 0) { title += " state=" + state.substring(0, state.indexOf(' ')); } else { title += " state=" + state; } } } else if (line.contains("Locked ownable synchronizers:")) { concurrentSyncsFlag = true; content.append(line); content.append('\n'); } else if (line.contains("- waiting on")) { content.append(linkifyMonitor(line)); monitorStack.push(line); inSleeping = true; content.append('\n'); } else if (line.contains("- parking to wait")) { content.append(linkifyMonitor(line)); monitorStack.push(line); inSleeping = true; content.append('\n'); } else if (line.contains("- waiting to")) { content.append(linkifyMonitor(line)); monitorStack.push(line); inWaiting = true; content.append('\n'); } else if (line.contains("- locked")) { content.append(linkifyMonitor(line)); inLocking = true; monitorStack.push(line); content.append('\n'); } else if (line.contains("- ")) { if (concurrentSyncsFlag) { content.append(linkifyMonitor(line)); monitorStack.push(line); } else { content.append(line); } content.append('\n'); } // last thread reached? if ((line.contains("\"Suspend Checker Thread\"")) || (line.contains("\"VM Periodic Task Thread\"")) || (line.contains("<EndOfDump>"))) { finished = true; getBis().mark(getMarkSize()); if ((checkForDeadlocks(threadDump)) == 0) { // no deadlocks found, set back original position. getBis().reset(); } if (!checkThreadDumpStatData(overallTDI)) { // no statistical data found, set back original position. getBis().reset(); } getBis().mark(getMarkSize()); if (!(foundClassHistograms = checkForClassHistogram(threadDump))) { getBis().reset(); } } } } // last thread String stringContent = content != null ? content.toString() : null; if (title != null) { threads.put(title, content.toString()); content.append("</pre></pre>"); addToCategory(catThreads, title, null, stringContent, singleLineCounter, true); threadCount++; } if (inWaiting) { addToCategory(catWaiting, title, null, stringContent, singleLineCounter, true); waiting++; } if (inSleeping) { addToCategory(catSleeping, title, null, stringContent, singleLineCounter, true); sleeping++; } if (inLocking) { addToCategory(catLocking, title, null, stringContent, singleLineCounter, true); locking++; } while (!monitorStack.empty()) { mmap.parseAndAddThread(monitorStack.pop(), title, content.toString()); } int monitorCount = mmap.size(); int monitorsWithoutLocksCount = 0; int contendedMonitors = 0; int blockedThreads = 0; // dump monitors if (mmap.size() > 0) { int[] result = dumpMonitors(catMonitors, catMonitorsLocks, mmap); monitorsWithoutLocksCount = result[0]; overallTDI.setOverallThreadsWaitingWithoutLocksCount(result[1]); result = dumpBlockingMonitors(catBlockingMonitors, mmap); contendedMonitors = result[0]; blockedThreads = result[1]; } // display nodes with stuff to display if (waiting > 0) { overallTDI.setWaitingThreads((Category) catWaiting.getUserObject()); threadDump.add(catWaiting); } if (sleeping > 0) { overallTDI.setSleepingThreads((Category) catSleeping.getUserObject()); threadDump.add(catSleeping); } if (locking > 0) { overallTDI.setLockingThreads((Category) catLocking.getUserObject()); threadDump.add(catLocking); } if (monitorCount > 0) { overallTDI.setMonitors((Category) catMonitors.getUserObject()); threadDump.add(catMonitors); } if (contendedMonitors > 0) { overallTDI.setBlockingMonitors((Category) catBlockingMonitors.getUserObject()); threadDump.add(catBlockingMonitors); } if (monitorsWithoutLocksCount > 0) { overallTDI.setMonitorsWithoutLocks((Category) catMonitorsLocks.getUserObject()); threadDump.add(catMonitorsLocks); } overallTDI.setThreads((Category) catThreads.getUserObject()); ((Category) catThreads.getUserObject()) .setName(catThreads.getUserObject() + " (" + threadCount + " Threads overall)"); ((Category) catWaiting.getUserObject()) .setName(catWaiting.getUserObject() + " (" + waiting + " Threads waiting)"); ((Category) catSleeping.getUserObject()) .setName(catSleeping.getUserObject() + " (" + sleeping + " Threads sleeping)"); ((Category) catLocking.getUserObject()) .setName(catLocking.getUserObject() + " (" + locking + " Threads locking)"); ((Category) catMonitors.getUserObject()) .setName(catMonitors.getUserObject() + " (" + monitorCount + " Monitors)"); ((Category) catBlockingMonitors.getUserObject()).setName(catBlockingMonitors.getUserObject() + " (" + blockedThreads + " Threads blocked by " + contendedMonitors + " Monitors)"); ((Category) catMonitorsLocks.getUserObject()).setName( catMonitorsLocks.getUserObject() + " (" + monitorsWithoutLocksCount + " Monitors)"); // add thread dump to passed dump store. if ((threadCount > 0) && (dumpKey != null)) { threadStore.put(dumpKey.trim(), threads); } // check custom categories addCustomCategories(threadDump); return (threadCount > 0 ? threadDump : null); } catch (StringIndexOutOfBoundsException e) { e.printStackTrace(); JOptionPane.showMessageDialog(null, "Error during parsing of a found thread dump, skipping to next one!\n" + "Check for possible broken dumps, sometimes, stream flushing mixes the logged data.\n" + "Error Message is \"" + e.getLocalizedMessage() + "\". \n" + (line != null ? "Last line read was \"" + line + "\". \n" : ""), "Error during Parsing Thread Dump", JOptionPane.ERROR_MESSAGE); retry = true; } catch (IOException e) { e.printStackTrace(); } } while (retry); return (null); }
From source file:gr.aueb.mipmapgui.controller.datasource.operators.GenerateInstanceTree.java
@Override public void visitAttributeNode(AttributeNode node) { //web - check before change //DefaultMutableTreeNode treeNode = new DefaultMutableTreeNode(new TreeNodeAdapter(node, dataSource.getType())); DefaultMutableTreeNode treeNode = new DefaultMutableTreeNode(node); currentTreeNode.add(treeNode);/*from ww w . jav a 2s .c o m*/ //return; }
From source file:EditorPaneExample19.java
public EditorPaneExample19() { super("JEditorPane Example 19"); pane = new JEditorPane(); pane.setEditable(true); // Editable getContentPane().add(new JScrollPane(pane), "Center"); // Add a menu bar menuBar = new JMenuBar(); setJMenuBar(menuBar);/*from w w w.j a v a 2 s . c o m*/ // Populate it createMenuBar(); // Build the panel of controls JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = 1; c.gridheight = 1; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.NONE; c.weightx = 0.0; c.weighty = 0.0; JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT); panel.add(urlLabel, c); JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT); c.gridy = 1; panel.add(loadingLabel, c); JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT); c.gridy = 2; panel.add(typeLabel, c); c.gridy = 3; panel.add(new JLabel(LOAD_TIME), c); c.gridy = 4; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; onlineLoad = new JCheckBox("Online Load"); panel.add(onlineLoad, c); onlineLoad.setSelected(true); onlineLoad.setForeground(typeLabel.getForeground()); c.gridy = 5; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; editableBox = new JCheckBox("Editable JEditorPane"); panel.add(editableBox, c); editableBox.setSelected(true); editableBox.setForeground(typeLabel.getForeground()); c.gridy = 6; c.weightx = 0.0; JButton saveButton = new JButton("Save"); panel.add(saveButton, c); saveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { EditorKit kit = pane.getEditorKit(); try { if (kit instanceof RTFEditorKit) { kit.write(System.out, pane.getDocument(), 0, pane.getDocument().getLength()); System.out.flush(); } else { if (writer == null) { writer = new OutputStreamWriter(System.out); pane.write(writer); writer.flush(); } kit.write(writer, pane.getDocument(), 0, pane.getDocument().getLength()); writer.flush(); } } catch (Exception e) { System.out.println("Write failed"); } } }); c.gridx = 1; c.gridy = 0; c.weightx = 1.0; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.HORIZONTAL; urlCombo = new JComboBox(); panel.add(urlCombo, c); urlCombo.setEditable(true); loadingState = new JLabel(spaces, JLabel.LEFT); loadingState.setForeground(Color.black); c.gridy = 1; panel.add(loadingState, c); loadedType = new JLabel(spaces, JLabel.LEFT); loadedType.setForeground(Color.black); c.gridy = 2; panel.add(loadedType, c); timeLabel = new JLabel(""); c.gridy = 3; panel.add(timeLabel, c); getContentPane().add(panel, "South"); // Register a custom EditorKit for HTML ClassLoader loader = getClass().getClassLoader(); if (loader != null) { // Java 2 JEditorPane.registerEditorKitForContentType("text/html", "AdvancedSwing.Chapter4.EnhancedHTMLEditorKit", loader); } else { // JDK 1.1 JEditorPane.registerEditorKitForContentType("text/html", "AdvancedSwing.Chapter4.EnhancedHTMLEditorKit"); } // Allocate the empty tree model DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode("Empty"); emptyModel = new DefaultTreeModel(emptyRootNode); // Create and place the heading tree tree = new JTree(emptyModel); tree.setPreferredSize(new Dimension(200, 200)); getContentPane().add(new JScrollPane(tree), "East"); // Change page based on combo selection urlCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (populatingCombo == true) { return; } Object selection = urlCombo.getSelectedItem(); loadNewPage(selection); } }); // Change editability based on the checkbox editableBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { pane.setEditable(editableBox.isSelected()); pane.revalidate(); pane.repaint(); } }); // Listen for page load to complete pane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("page")) { loadComplete(); displayLoadTime(); populateCombo(findLinks(pane.getDocument(), null)); TreeNode node = buildHeadingTree(pane.getDocument()); tree.setModel(new DefaultTreeModel(node)); createMenuBar(); enableMenuBar(true); getRootPane().revalidate(); enableInput(); loadingPage = false; } } }); // Listener for tree selection tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent evt) { TreePath path = evt.getNewLeadSelectionPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object userObject = node.getUserObject(); if (userObject instanceof Heading) { Heading heading = (Heading) userObject; try { Rectangle textRect = pane.modelToView(heading.getOffset()); textRect.y += 3 * textRect.height; pane.scrollRectToVisible(textRect); } catch (BadLocationException e) { } } } } }); // Listener for hypertext events pane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent evt) { // Ignore hyperlink events if the frame is busy if (loadingPage == true) { return; } if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { JEditorPane sp = (JEditorPane) evt.getSource(); if (evt instanceof HTMLFrameHyperlinkEvent) { HTMLDocument doc = (HTMLDocument) sp.getDocument(); doc.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) evt); } else { loadNewPage(evt.getURL()); } } else if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) { pane.setCursor(handCursor); } else if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) { pane.setCursor(defaultCursor); } } }); }
From source file:BasicDnD.java
public BasicDnD() { super(new BorderLayout()); JPanel leftPanel = createVerticalBoxPanel(); JPanel rightPanel = createVerticalBoxPanel(); //Create a table model. DefaultTableModel tm = new DefaultTableModel(); tm.addColumn("Column 0"); tm.addColumn("Column 1"); tm.addColumn("Column 2"); tm.addColumn("Column 3"); tm.addRow(new String[] { "Table 00", "Table 01", "Table 02", "Table 03" }); tm.addRow(new String[] { "Table 10", "Table 11", "Table 12", "Table 13" }); tm.addRow(new String[] { "Table 20", "Table 21", "Table 22", "Table 23" }); tm.addRow(new String[] { "Table 30", "Table 31", "Table 32", "Table 33" }); //LEFT COLUMN //Use the table model to create a table. table = new JTable(tm); leftPanel.add(createPanelForComponent(table, "JTable")); //Create a color chooser. colorChooser = new JColorChooser(); leftPanel.add(createPanelForComponent(colorChooser, "JColorChooser")); //RIGHT COLUMN //Create a textfield. textField = new JTextField(30); textField.setText("Favorite foods:\nPizza, Moussaka, Pot roast"); rightPanel.add(createPanelForComponent(textField, "JTextField")); //Create a scrolled text area. textArea = new JTextArea(5, 30); textArea.setText("Favorite shows:\nBuffy, Alias, Angel"); JScrollPane scrollPane = new JScrollPane(textArea); rightPanel.add(createPanelForComponent(scrollPane, "JTextArea")); //Create a list model and a list. DefaultListModel listModel = new DefaultListModel(); listModel.addElement("Martha Washington"); listModel.addElement("Abigail Adams"); listModel.addElement("Martha Randolph"); listModel.addElement("Dolley Madison"); listModel.addElement("Elizabeth Monroe"); listModel.addElement("Louisa Adams"); listModel.addElement("Emily Donelson"); list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); JScrollPane listView = new JScrollPane(list); listView.setPreferredSize(new Dimension(300, 100)); rightPanel.add(createPanelForComponent(listView, "JList")); //Create a tree. DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Mia Familia"); DefaultMutableTreeNode sharon = new DefaultMutableTreeNode("Sharon"); rootNode.add(sharon);// w ww. ja va2 s . co m DefaultMutableTreeNode maya = new DefaultMutableTreeNode("Maya"); sharon.add(maya); DefaultMutableTreeNode anya = new DefaultMutableTreeNode("Anya"); sharon.add(anya); sharon.add(new DefaultMutableTreeNode("Bongo")); maya.add(new DefaultMutableTreeNode("Muffin")); anya.add(new DefaultMutableTreeNode("Winky")); DefaultTreeModel model = new DefaultTreeModel(rootNode); tree = new JTree(model); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); JScrollPane treeView = new JScrollPane(tree); treeView.setPreferredSize(new Dimension(300, 100)); rightPanel.add(createPanelForComponent(treeView, "JTree")); //Create the toggle button. toggleDnD = new JCheckBox("Turn on Drag and Drop"); toggleDnD.setActionCommand("toggleDnD"); toggleDnD.addActionListener(this); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel); splitPane.setOneTouchExpandable(true); add(splitPane, BorderLayout.CENTER); add(toggleDnD, BorderLayout.PAGE_END); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); }
From source file:EditorPaneExample17.java
public EditorPaneExample17() { super("JEditorPane Example 17"); pane = new JEditorPane(); pane.setEditable(true); // Editable getContentPane().add(new JScrollPane(pane), "Center"); // Build the panel of controls JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = 1;/*from www.j a va 2 s .c o m*/ c.gridheight = 1; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.NONE; c.weightx = 0.0; c.weighty = 0.0; JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT); panel.add(urlLabel, c); JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT); c.gridy = 1; panel.add(loadingLabel, c); JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT); c.gridy = 2; panel.add(typeLabel, c); c.gridy = 3; panel.add(new JLabel(LOAD_TIME), c); c.gridy = 4; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; onlineLoad = new JCheckBox("Online Load"); panel.add(onlineLoad, c); onlineLoad.setSelected(true); onlineLoad.setForeground(typeLabel.getForeground()); c.gridy = 5; c.gridwidth = 2; c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; editableBox = new JCheckBox("Editable JEditorPane"); panel.add(editableBox, c); editableBox.setSelected(true); editableBox.setForeground(typeLabel.getForeground()); c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.HORIZONTAL; urlCombo = new JComboBox(); panel.add(urlCombo, c); urlCombo.setEditable(true); loadingState = new JLabel(spaces, JLabel.LEFT); loadingState.setForeground(Color.black); c.gridy = 1; panel.add(loadingState, c); loadedType = new JLabel(spaces, JLabel.LEFT); loadedType.setForeground(Color.black); c.gridy = 2; panel.add(loadedType, c); timeLabel = new JLabel(""); c.gridy = 3; panel.add(timeLabel, c); getContentPane().add(panel, "South"); // Register a custom EditorKit for HTML ClassLoader loader = getClass().getClassLoader(); if (loader != null) { // Java 2 JEditorPane.registerEditorKitForContentType("text/html", "AdvancedSwing.Chapter4.HiddenViewHTMLEditorKit", loader); } else { // JDK 1.1 JEditorPane.registerEditorKitForContentType("text/html", "AdvancedSwing.Chapter4.HiddenViewHTMLEditorKit"); } // Allocate the empty tree model DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode("Empty"); emptyModel = new DefaultTreeModel(emptyRootNode); // Create and place the heading tree tree = new JTree(emptyModel); tree.setPreferredSize(new Dimension(200, 200)); getContentPane().add(new JScrollPane(tree), "East"); // Change page based on combo selection urlCombo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (populatingCombo == true) { return; } Object selection = urlCombo.getSelectedItem(); loadNewPage(selection); } }); // Change editability based on the checkbox editableBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { pane.setEditable(editableBox.isSelected()); pane.revalidate(); pane.repaint(); } }); // Listen for page load to complete pane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("page")) { loadComplete(); displayLoadTime(); populateCombo(findLinks(pane.getDocument(), null)); TreeNode node = buildHeadingTree(pane.getDocument()); tree.setModel(new DefaultTreeModel(node)); enableInput(); loadingPage = false; } } }); // Listener for tree selection tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent evt) { TreePath path = evt.getNewLeadSelectionPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); Object userObject = node.getUserObject(); if (userObject instanceof Heading) { Heading heading = (Heading) userObject; try { Rectangle textRect = pane.modelToView(heading.getOffset()); textRect.y += 3 * textRect.height; pane.scrollRectToVisible(textRect); } catch (BadLocationException e) { } } } } }); // Listener for hypertext events pane.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent evt) { // Ignore hyperlink events if the frame is busy if (loadingPage == true) { return; } if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { JEditorPane sp = (JEditorPane) evt.getSource(); if (evt instanceof HTMLFrameHyperlinkEvent) { HTMLDocument doc = (HTMLDocument) sp.getDocument(); doc.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) evt); } else { loadNewPage(evt.getURL()); } } else if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) { pane.setCursor(handCursor); } else if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) { pane.setCursor(defaultCursor); } } }); }
From source file:be.ugent.maf.cellmissy.gui.controller.TracksWriterController.java
/** * Initialise the data tree (JTree).//from ww w . ja va2 s.c o m */ private void initDataTree() { DefaultMutableTreeNode root = new DefaultMutableTreeNode("cellmissy"); JTree dataTree = tracksWriterDialog.getDataTree(); MapDataTreeModel mapDataTreeModel = new MapDataTreeModel(root, projectMap); dataTree.setModel(mapDataTreeModel); dataTree.setEditable(true); }