package com.touchgraph.wikibrowser; import java.awt.*; import java.applet.AppletContext; import java.awt.event.*; import java.io.File; import java.net.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.html.HTMLEditorKit; class TGWikiPanel extends TGWikiBrowser { AppletContext appletContext; /* This is a hack for opening selected Nodes in the browser. It should better be solved with event notification ... */ TGWikiPanel(AppletContext ac){ appletContext = ac; } protected void buildPanel() { final JScrollBar horizontalSB = hvScroll.getHorizontalSB(); final JScrollBar verticalSB = hvScroll.getVerticalSB(); final JScrollBar zoomSB = zoomScroll.getZoomSB(); setLayout(new BorderLayout()); ToolTipManager.sharedInstance().setInitialDelay(0); // the graph part JPanel scrollPanel = new JPanel(new BorderLayout()); final JToolBar topPanel = new JToolBar("TGWikibrowser controls"); maxAddCombo = new JComboBox(new String[] {"25","30","35","40","50","60","100","200"}); maxExpandCombo = new JComboBox(new String[] {"10","15","20","25","30","40","50","70","100"}); localityRadiusCombo = new JComboBox(new String[] {"0","1","2","3","4","5","6"}); maxAddCombo.setSelectedIndex(3); maxExpandCombo.setSelectedIndex(3); localityRadiusCombo.setSelectedIndex(2); maxAddCombo.setToolTipText("Don't show nodes with more E# of edges"); maxExpandCombo.setToolTipText("Don't expand nodes with more then E# of edges"); localityRadiusCombo.setToolTipText("Show nodes reachable by following Radius# edges"); showBackLinksCheckBox = new JCheckBox("BackLinks",false); showBackLinksCheckBox.setHorizontalTextPosition(SwingConstants.LEFT); //todo: dynamically replace "the selected one" with the current selections name ... showBackLinksCheckBox.setToolTipText("Show topics referring to the selected one"); ActionListener setLocaleAL = new ActionListener() { public void actionPerformed(ActionEvent e) { setLocale(tgPanel.getSelect()); } }; maxAddCombo.addActionListener(setLocaleAL); maxExpandCombo.addActionListener(setLocaleAL); localityRadiusCombo.addActionListener(setLocaleAL); showBackLinksCheckBox.addActionListener(setLocaleAL); maxAddCombo.setPreferredSize(new Dimension(50,20)); maxExpandCombo.setPreferredSize(new Dimension(50,20)); localityRadiusCombo.setPreferredSize(new Dimension(50,20)); JLabel maxAddComboLabel = new JLabel("Show E#",Label.RIGHT); maxAddComboLabel.setLabelFor(maxAddCombo); topPanel.add(maxAddComboLabel); topPanel.add(maxAddCombo); JLabel maxExpandComboLabel = new JLabel("Expand E#",Label.RIGHT); maxExpandComboLabel.setLabelFor(maxExpandCombo); topPanel.add(maxExpandComboLabel); topPanel.add(maxExpandCombo); JLabel localityRadiusComboLabel = new JLabel("Radius",Label.RIGHT); localityRadiusComboLabel.setLabelFor(localityRadiusCombo); topPanel.add(localityRadiusComboLabel); topPanel.add(localityRadiusCombo); topPanel.add(showBackLinksCheckBox); JLabel zoomSBLabel = new JLabel("Zoom",Label.RIGHT); zoomSBLabel.setLabelFor(zoomSB); topPanel.add(zoomSBLabel); topPanel.add(zoomSB); JButton stopButton; URL stopIcon = this.getClass().getResource("/images/kill.png"); if (stopIcon != null) { System.out.println("Stop icon: " + stopIcon); stopButton = new JButton(new ImageIcon(stopIcon)); } else { stopButton = new JButton("Stop!"); stopButton.setBackground(Color.decode("#D8C0C0")); } stopButton.setToolTipText("Stop graph motion, click twice to stop all motion"); stopButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tgPanel.stopMotion(); tgPanel.fastFinishAnimation(); } }); topPanel.add(stopButton); add(topPanel, BorderLayout.NORTH); scrollPanel.add(tgPanel, BorderLayout.CENTER); scrollPanel.add(verticalSB, BorderLayout.EAST); scrollPanel.add(horizontalSB,BorderLayout.SOUTH); add(scrollPanel, BorderLayout.CENTER); // statusButton.setText() is called all the time in WikiNavigateUI // this hack avoids NullPointerExceptions ... statusButton = new JButton(); wikiPopup = new JPopupMenu(); JMenuItem menuItem = new JMenuItem("Toggle Controls"); ActionListener toggleControlsAction = new ActionListener() { boolean controlsVisible = true; public void actionPerformed(ActionEvent e) { controlsVisible = !controlsVisible; horizontalSB.setVisible(controlsVisible); verticalSB.setVisible(controlsVisible); topPanel.setVisible(controlsVisible); } }; menuItem.addActionListener(toggleControlsAction); wikiPopup.add(menuItem); } /* we abuse this callback to open the selected topic in the browser */ public void setWikiTextPane(String url) { textPaneURL = url; System.out.println("Opening " + textPaneURL); if (appletContext != null) { try { appletContext.showDocument(new URL(textPaneURL), "wiki"); } catch (MalformedURLException mue) { System.err.println(mue); //mue.printStackTrace(); } } } }