1 37 38 39 40 41 42 package com.lutris.appserver.debugger.applet; 43 44 import java.util.Vector ; 45 46 47 import java.io.*; 48 import java.net.*; 49 import java.awt.*; 50 import java.awt.event.*; 51 import java.applet.AppletContext ; 52 import javax.swing.*; 53 import javax.swing.event.*; 54 import javax.swing.border.*; 55 import javax.swing.table.*; 56 import com.lutris.appserver.debugger.applet.io.*; 57 58 59 public class DebuggerApplet extends JApplet 60 implements ActionListener, ListSelectionListener, MouseListener { 61 62 63 public void init() { 64 65 System.out.println("INIT " + this); 66 67 showStatus("Starting debugger, please wait..."); 68 Globals.japplet = this; 69 setBackground(Color.lightGray); 70 Container contentPane = getContentPane(); 71 contentPane.setLayout(new BorderLayout()); 72 contentPane.add(createApplicationsPane(), BorderLayout.NORTH); 73 contentPane.add(createTransactionsPane(), BorderLayout.CENTER); 74 contentPane.add(createControlsPane(), BorderLayout.SOUTH); 75 } 76 77 public void start() { 78 super.start(); 79 System.out.println("START " + this); 80 initializeUI(); 81 } 82 83 public void stop() { 84 super.stop(); 85 System.out.println("STOP " + this); 86 Updater.killThread(); 87 } 88 89 public void destroy() { 90 super.destroy(); 91 System.out.println("DESTROY " + this); 92 } 93 94 95 private JPanel createApplicationsPane() { 96 JPanel result = new JPanel(); 97 result.setLayout(new BorderLayout()); 98 result.setBorder(new TitledBorder("Enhydra Applications")); 99 Globals.servletModel = new ServletTableModel(); 100 Globals.applicationTable = new JTable(Globals.servletModel); 101 Globals.applicationTable.addMouseListener(this); 102 Globals.applicationTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); 103 Globals.applicationTable.setShowGrid(false); 104 Globals.applicationTable.setRowSelectionAllowed(false); 105 Globals.applicationTable.setCellSelectionEnabled(false); 106 TableColumnModel tcm = Globals.applicationTable.getColumnModel(); 107 TableColumn tc = tcm.getColumn(0); 108 FontMetrics fm = Globals.applicationTable.getFontMetrics(Globals.applicationTable.getFont()); 109 int width = fm.stringWidth("Debug"); 110 Dimension d = Globals.applicationTable.getPreferredSize(); 113 JScrollPane sp = new JScrollPane(Globals.applicationTable); 115 d.height = 60; 116 sp.setPreferredSize(d); 117 sp.setBackground(Globals.applicationTable.getBackground()); 118 result.add(sp, BorderLayout.CENTER); 119 return result; 120 } 121 122 private JPanel createTransactionsPane() { 123 JPanel result = new JPanel(); 124 result.setBorder(new TitledBorder("Transactions")); 125 result.setLayout(new BorderLayout()); 126 Globals.transactionModel = new TransactionListModel(); 127 Globals.transactionList = new JList(Globals.transactionModel); 128 Globals.transactionList.addListSelectionListener(this); 129 JScrollPane sp = new JScrollPane(Globals.transactionList); 130 sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); 131 sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 132 result.add(sp, BorderLayout.CENTER); 133 return result; 134 } 135 136 137 private JPanel createControlsPane() { 138 JPanel result = new JPanel(); 139 result.setBorder(new TitledBorder("Controls")); 140 result.setLayout(new BorderLayout()); 141 Globals.serverButton = new JButton(); 142 updateButtonLabel(); 143 result.add(Globals.serverButton, BorderLayout.CENTER); 144 Globals.serverButton.addActionListener(this); 145 Globals.updateButton = new JButton("Update"); 146 result.add(Globals.updateButton, BorderLayout.WEST); 147 Globals.updateButton.addActionListener(this); 148 return result; 149 } 150 151 152 private void updateButtonLabel() { 153 if (Updater.threadRunning()) 154 Globals.serverButton.setText(Globals.activeTitle); 155 else 156 Globals.serverButton.setText(Globals.inactiveTitle); 157 } 158 159 160 private static void initializeUI() { 161 Updater.updateState(0); 162 } 163 164 166 167 public void actionPerformed(ActionEvent actionEvent) { 168 System.out.println("BUTTON HANDLER " + actionEvent); 169 Object source = actionEvent.getSource(); 170 if (source == Globals.serverButton) { 171 System.out.println(" flipping"); 172 if (Updater.threadRunning()) { 173 Updater.killThread(); 174 Globals.serverButton.setText(Globals.inactiveTitle); 175 Globals.updateButton.setEnabled(true); 176 } else { 177 Updater.startThread(); 178 Globals.serverButton.setText(Globals.activeTitle); 179 Globals.updateButton.setEnabled(false); 180 } 181 System.out.println("BUTTON HANDLER DONE"); 182 } else if (source == Globals.updateButton) { 183 Updater.updateState(0); 184 } 185 } 186 187 188 189 191 public void valueChanged(ListSelectionEvent e) { 192 if ((e.getSource() != Globals.transactionList) || 193 e.getValueIsAdjusting()) 194 return; 195 System.out.println("LIST HANDLER " + e); 196 showSelectedTransaction(); 197 System.out.println("LIST HANDLER DONE"); 198 } 199 200 private static int currentTransId = -1; 201 202 private void showSelectedTransaction() { 203 int sel = Globals.transactionList.getSelectedIndex(); 204 System.out.println("sel = " + sel); 205 if (sel < 0) 206 return; 207 try { 208 TransactionDescription t = (TransactionDescription) Globals.transactionList.getModel().getElementAt(sel); 209 if (t.id != currentTransId) { 210 URL target = new URL(getDocumentBase(), "StatusFrame.po?id=" + t.id); 211 AppletContext context = getAppletContext(); 212 context.showDocument(target, "StatusFrame"); 213 currentTransId = t.id; 214 } 215 } catch (Throwable t) { 216 System.err.println(t); 217 } 218 } 219 220 222 public void mouseClicked(MouseEvent e) { 223 if (e.getSource() != Globals.applicationTable) 224 return; 225 if (e.getClickCount() != 2) 226 return; 227 System.out.println("MOUSE HANDLER"); 228 int sel = Globals.applicationTable.getSelectedRow(); 229 if (sel >= 0) 230 Globals.servletModel.toggleRow(sel); 231 System.out.println("MOUSE HANDLER DONE"); 232 } 233 234 public void mousePressed(MouseEvent e) {} 235 public void mouseReleased(MouseEvent e) {} 236 public void mouseEntered(MouseEvent e) {} 237 public void mouseExited(MouseEvent e) {} 238 239 240 241 242 } 243 | Popular Tags |