📄 swinggui.java
字号:
} VariableModel(Dim debugger, Object scope) { this.debugger = debugger; this.root = new VariableNode(scope, "this"); } // // The TreeModel interface // public Object getRoot() { if (debugger == null) { return ""; } return root; } public int getChildCount(Object nodeObj) { if (debugger == null) { return 0; } VariableNode node = (VariableNode)nodeObj; return children(node).length; } public Object getChild(Object nodeObj, int i) { if (debugger == null) { return null; } VariableNode node = (VariableNode)nodeObj; return children(node)[i]; } public boolean isLeaf(Object nodeObj) { if (debugger == null) { return true; } VariableNode node = (VariableNode)nodeObj; return children(node).length == 0; } public int getIndexOfChild(Object parentObj, Object childObj) { if (debugger == null) { return -1; } VariableNode parent = (VariableNode)parentObj; VariableNode child = (VariableNode)childObj; VariableNode[] children = children(parent); for (int i = 0; i != children.length; ++i) { if (children[i] == child) { return i; } } return -1; } public boolean isCellEditable(Object node, int column) { return column == 0; } public void setValueAt(Object value, Object node, int column) { } public void addTreeModelListener(TreeModelListener l) { } public void removeTreeModelListener(TreeModelListener l) { } public void valueForPathChanged(TreePath path, Object newValue) { } // // The TreeTableNode interface. // public int getColumnCount() { return cNames.length; } public String getColumnName(int column) { return cNames[column]; } public Class getColumnClass(int column) { return cTypes[column]; } public Object getValueAt(Object nodeObj, int column) { if (debugger == null) { return null; } VariableNode node = (VariableNode)nodeObj; switch (column) { case 0: // Name return node.toString(); case 1: // Value String result; try { result = debugger.objectToString(getValue(node)); } catch (RuntimeException exc) { result = exc.getMessage(); } StringBuffer buf = new StringBuffer(); int len = result.length(); for (int i = 0; i < len; i++) { char ch = result.charAt(i); if (Character.isISOControl(ch)) { ch = ' '; } buf.append(ch); } return buf.toString(); } return null; } private VariableNode[] children(VariableNode node) { if (node.children != null) { return node.children; } VariableNode[] children; Object value = getValue(node); Object[] ids = debugger.getObjectIds(value); if (ids.length == 0) { children = CHILDLESS; } else { java.util.Arrays.sort(ids, new java.util.Comparator() { public int compare(Object l, Object r) { if (l instanceof String) { if (r instanceof Integer) { return -1; } return ((String)l).compareToIgnoreCase((String)r); } else { if (r instanceof String) { return 1; } int lint = ((Integer)l).intValue(); int rint = ((Integer)r).intValue(); return lint - rint; } } }); children = new VariableNode[ids.length]; for (int i = 0; i != ids.length; ++i) { children[i] = new VariableNode(value, ids[i]); } } node.children = children; return children; } Object getValue(VariableNode node) { try { return debugger.getObjectProperty(node.object, node.id); } catch (Exception exc) { return "undefined"; } }}class MyTreeTable extends JTreeTable{ static final long serialVersionUID = 3457265548184453049L; public MyTreeTable(VariableModel model) { super(model); } public JTree resetTree(TreeTableModel treeTableModel) { tree = new TreeTableCellRenderer(treeTableModel); // Install a tableModel representing the visible rows in the tree. super.setModel(new TreeTableModelAdapter(treeTableModel, tree)); // Force the JTable and JTree to share their row selection models. ListToTreeSelectionModelWrapper selectionWrapper = new ListToTreeSelectionModelWrapper(); tree.setSelectionModel(selectionWrapper); setSelectionModel(selectionWrapper.getListSelectionModel()); // Make the tree and table row heights the same. if (tree.getRowHeight() < 1) { // Metal looks better like this. setRowHeight(18); } // Install the tree editor renderer and editor. setDefaultRenderer(TreeTableModel.class, tree); setDefaultEditor(TreeTableModel.class, new TreeTableCellEditor()); setShowGrid(true); setIntercellSpacing(new Dimension(1,1)); tree.setRootVisible(false); tree.setShowsRootHandles(true); DefaultTreeCellRenderer r = (DefaultTreeCellRenderer)tree.getCellRenderer(); r.setOpenIcon(null); r.setClosedIcon(null); r.setLeafIcon(null); return tree; } public boolean isCellEditable(EventObject e) { if (e instanceof MouseEvent) { MouseEvent me = (MouseEvent)e; // If the modifiers are not 0 (or the left mouse button), // tree may try and toggle the selection, and table // will then try and toggle, resulting in the // selection remaining the same. To avoid this, we // only dispatch when the modifiers are 0 (or the left mouse // button). if (me.getModifiers() == 0 || ((me.getModifiers() & (InputEvent.BUTTON1_MASK|1024)) != 0 && (me.getModifiers() & (InputEvent.SHIFT_MASK | InputEvent.CTRL_MASK | InputEvent.ALT_MASK | InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK | 64 | //SHIFT_DOWN_MASK 128 | //CTRL_DOWN_MASK 512 | // ALT_DOWN_MASK 2048 | //BUTTON2_DOWN_MASK 4096 //BUTTON3_DOWN_MASK )) == 0)) { int row = rowAtPoint(me.getPoint()); for (int counter = getColumnCount() - 1; counter >= 0; counter--) { if (TreeTableModel.class == getColumnClass(counter)) { MouseEvent newME = new MouseEvent (MyTreeTable.this.tree, me.getID(), me.getWhen(), me.getModifiers(), me.getX() - getCellRect(row, counter, true).x, me.getY(), me.getClickCount(), me.isPopupTrigger()); MyTreeTable.this.tree.dispatchEvent(newME); break; } } } if (me.getClickCount() >= 3) { return true; } return false; } if (e == null) { return true; } return false; }};class ContextWindow extends JPanel implements ActionListener{ static final long serialVersionUID = 2306040975490228051L; SwingGui debugGui; JComboBox context; Vector toolTips; JTabbedPane tabs; JTabbedPane tabs2; MyTreeTable thisTable; MyTreeTable localsTable; MyTableModel tableModel; Evaluator evaluator; EvalTextArea cmdLine; JSplitPane split; boolean enabled; ContextWindow(final SwingGui debugGui) { super(); this.debugGui = debugGui; enabled = false; JPanel left = new JPanel(); JToolBar t1 = new JToolBar(); t1.setName("Variables"); t1.setLayout(new GridLayout()); t1.add(left); JPanel p1 = new JPanel(); p1.setLayout(new GridLayout()); JPanel p2 = new JPanel(); p2.setLayout(new GridLayout()); p1.add(t1); JLabel label = new JLabel("Context:"); context = new JComboBox(); context.setLightWeightPopupEnabled(false); toolTips = new java.util.Vector(); label.setBorder(context.getBorder()); context.addActionListener(this); context.setActionCommand("ContextSwitch"); GridBagLayout layout = new GridBagLayout(); left.setLayout(layout); GridBagConstraints lc = new GridBagConstraints(); lc.insets.left = 5; lc.anchor = GridBagConstraints.WEST; lc.ipadx = 5; layout.setConstraints(label, lc); left.add(label); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.WEST; layout.setConstraints(context, c); left.add(context); tabs = new JTabbedPane(SwingConstants.BOTTOM); tabs.setPreferredSize(new Dimension(500,300)); thisTable = new MyTreeTable(new VariableModel()); JScrollPane jsp = new JScrollPane(thisTable); jsp.getViewport().setViewSize(new Dimension(5,2)); tabs.add("this", jsp); localsTable = new MyTreeTable(new VariableModel()); localsTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); localsTable.setPreferredSize(null); jsp = new JScrollPane(localsTable); tabs.add("Locals", jsp); c.weightx = c.weighty = 1; c.gridheight = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.WEST; layout.setConstraints(tabs, c); left.add(tabs); evaluator = new Evaluator(debugGui); cmdLine = new EvalTextArea(debugGui); //cmdLine.requestFocus(); tableModel = evaluator.tableModel; jsp = new JScrollPane(evaluator); JToolBar t2 = new JToolBar(); t2.setName("Evaluate"); tabs2 = new JTabbedPane(SwingConstants.BOTTOM); tabs2.add("Watch", jsp); tabs2.add("Evaluate", new JScrollPane(cmdLine)); tabs2.setPreferredSize(new Dimension(500,300)); t2.setLayout(new GridLayout()); t2.add(tabs2); p2.add(t2); evaluator.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, p1, p2); split.setOneTouchExpandable(true); SwingGui.setResizeWeight(split, 0.5); setLayout(new BorderLayout()); add(split, BorderLayout.CENTER); final JToolBar finalT1 = t1; final JToolBar finalT2 = t2; final JPanel finalP1 = p1; final JPanel finalP2 = p2; final JSplitPane finalSplit = split; final JPanel finalThis = this; ComponentListener clistener = new ComponentListener() { boolean t1Docked = true; boolean t2Docked = true; void check(Component comp) { Component thisParent = finalThis.getParent(); if (thisParent == null) { return; } Component parent = finalT1.getParent(); boolean leftDocked = true; boolean rightDocked = true; boolean adjustVerticalSplit = false; if (parent != null) { if (parent != finalP1) { while (!(parent instanceof JFrame)) { parent = parent.getParent(); } JFrame frame = (JFrame)parent; debugGui.addTopLevel("Variables", frame); // We need the following hacks because: // - We want an undocked toolbar to be // resizable. // - We are using JToolbar as a container of a // JComboBox. Without this JComboBox's popup // can get left floating when the toolbar is // re-docked. // // We make the frame resizable and then // remove JToolbar's window listener // and insert one of our own that first ensures // the JComboBox's popup window is closed // and then calls JToolbar's window listener. if (!frame.isResizable()) { frame.setResizable(true); frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); final EventListener[] l = frame.getListeners(WindowListener.class); frame.removeWindowListener((WindowListener)l[0]); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -