1 2 23 24 package net.fenyo.gnetwatch.data; 25 26 import net.fenyo.gnetwatch.*; 27 import net.fenyo.gnetwatch.GUI.*; 28 import net.fenyo.gnetwatch.targets.*; 29 30 import java.lang.reflect.InvocationTargetException ; 31 import java.util.*; 32 import java.util.List ; 33 import java.awt.Component ; 34 35 import javax.swing.JFrame ; 36 37 import org.apache.commons.logging.Log; 38 import org.apache.commons.logging.LogFactory; 39 import org.eclipse.swt.*; 40 import org.eclipse.swt.events.*; 41 import org.eclipse.swt.graphics.*; 42 import org.eclipse.swt.custom.*; 43 import org.eclipse.swt.widgets.*; 44 import org.eclipse.swt.browser.*; 45 46 51 52 public class NmapView extends VisualElement { 53 private static Log log = LogFactory.getLog(DataView.class); 54 55 final private Target target; 56 private CTabItem tab_item = null; 57 58 private Browser browser = null; 59 60 65 public NmapView(final GUI gui, final Target target) { 67 this.target = target; 68 setType("view"); 69 setItem("nmap signature"); 70 setParent(gui, target); 71 } 72 73 78 protected void initialize(final GUI gui) { 79 super.initialize(gui); 80 if (gui != null) setImageMultiRow(); 81 } 82 83 88 protected Browser getBrowser() { 89 return browser; 90 } 91 92 97 public Target getTarget() { 99 return target; 100 } 101 102 107 public String getTitle() { 109 return "NmapView"; 110 } 111 112 117 private String htmlFace(final String html) { 118 return getGUI().htmlFace(html); 119 } 120 121 126 protected StringBuffer getBrowserContent() { 127 final StringBuffer content = new StringBuffer (); 128 129 content.append("Nmap output:<BR/><TABLE BORDER='0' BGCOLOR='black' cellspacing='1' cellpadding='1'><TR><TD bgcolor='lightyellow'>" + 130 htmlFace("<PRE>" + ((EventNmap) getTarget().getLastEvent(EventNmap.class)).getOutput() + "</PRE>") + 131 "</TD></TR></TABLE"); 132 133 return new StringBuffer (htmlFace(content.toString())); 134 } 135 136 141 private void updateBrowserContent() { 142 browser.setText("<html><body bgcolor='#" + 143 String.format("%2x%2x%2x", 144 getGUI().getBackgroundColor().getRed(), 145 getGUI().getBackgroundColor().getGreen(), 146 getGUI().getBackgroundColor().getBlue()) + 147 "'><small>" + 148 getBrowserContent() + 149 "</small></body></html>"); 150 } 151 152 158 final public void informSelected() { 161 final CTabFolder folder = getGUI().getTabFolder(); 162 163 synchronized (folder) { 165 167 boolean tab_item_found = false; 168 for (final CTabItem tab_item : folder.getItems()) 169 if (tab_item == this.tab_item) { 170 folder.setSelection(tab_item); 171 tab_item_found = true; 172 updateBrowserContent(); 173 } 174 if (tab_item_found == false) { 175 tab_item = new CTabItem(folder, SWT.CLOSE); 177 tab_item.setText(getTitle()); 178 folder.setSelection(tab_item); 179 180 browser = new Browser(getGUI().getTabFolder(), SWT.BORDER | SWT.FILL); 182 tab_item.setControl(browser); 183 184 updateBrowserContent(); 185 } 186 187 } 188 } 189 190 195 protected void disposed() { 196 super.disposed(); 197 if (tab_item != null) tab_item.dispose(); 198 getTarget().removeEvents(EventNmap.class); 199 } 200 } 201 | Popular Tags |