public void loadInputMap(InputMap im, String indent) { KeyStroke[] k = im.allKeys(); if (k == null) { results.append(indent + "No InputMap defined\n"); } else { results.append(indent + "\nInputMap (" + k.length + " local keys)\n"); } if (k != null) { for (int i = 0; i < k.length; i++) { results.append(indent + " Key: " + k[i] + ", binding: " + im.get(k[i]) + "\n"); } } }
public void loadActionMap(ActionMap am, String indent) { Object[] k = am.allKeys(); if (k == null) { results.append(indent + "No ActionMap defined\n"); } else { results.append(indent + "\nActionMap (" + k.length + " local keys)\n"); } if (k != null) { for (int i = 0; i < k.length; i++) { results.append(indent + " Action: " + k[i] + "\n"); } } }
public void loadBindingMap(InputMap im, ActionMap am) { results.append("Bound Actions\n"); String unboundActions = ""; String unboundInputKeys = ""; Hashtable mi = buildReverseMap(im); Object[] k = am.allKeys(); if (k != null) { for (int i = 0; i < k.length; i++) { if (mi.containsKey(k[i])) { results.append(" " + getActionName(k[i])); results.append(";" + mi.get(k[i]) + "\n"); } else { unboundActions += (" " + getActionName(k[i]) + "\n"); } } results.append("\nUnbound Actions\n\n"); results.append(unboundActions); } results.append("\nUnbound InputMap Entries\n"); k = im.allKeys(); if (k != null) { for (int i = 0; i < k.length; i++) { KeyStroke key = (KeyStroke) k[i]; Object actionKey = im.get(key); if (am.get(actionKey) == null) { results.append(" " + im.get((KeyStroke) k[i]) + ": " + k[i] + "\n"); } } } }
public void actionPerformed(ActionEvent ae) { String cname = nameF.getText().trim(); int state = conditions[stateC.getSelectedIndex()]; try { if (isSpecialCase(cname)) { handleSpecialCase(cname, state); } else { JComponent comp = (JComponent) Class.forName(cname).newInstance(); ComponentUI cui = UIManager.getUI(comp); cui.installUI(comp); results.setText("Map entries for " + cname + ":\n\n"); if (inputB.isSelected()) { loadInputMap(comp.getInputMap(state), ""); results.append("\n"); } if (actionB.isSelected()) { loadActionMap(comp.getActionMap(), ""); results.append("\n"); } if (bindingB.isSelected()) { loadBindingMap(comp, state); } } } catch (ClassCastException cce) { results.setText(cname + " is not a subclass of JComponent."); } catch (ClassNotFoundException cnfe) { results.setText(cname + " was not found."); } catch (InstantiationException ie) { results.setText(cname + " could not be instantiated."); } catch (Exception e) { results.setText("Exception found:\n" + e); e.printStackTrace(); } }
private void handleSpecialCase(String cname, int condition) { Component comp = null; JComponent mapComp = null; try { if (cname.equals("javax.swing.JApplet") || cname.equals("javax.swing.JDialog") || cname.equals("javax.swing.JFrame") || cname.equals("javax.swing.JWindow")) { comp = (Component) Class.forName(cname).newInstance(); mapComp = (JComponent) ((JApplet) comp).getLayeredPane(); results.setText("Map entries for " + cname + " (delegated to JRootPane):\n\n"); } else if (cname.equals("javax.swing.JInternalFrame")) { JDesktopPane jdp = new JDesktopPane(); JInternalFrame jif = new JInternalFrame("Demo"); jif.setVisible(true); jdp.add(jif); mapComp = jif; } if (inputB.isSelected()) { loadInputMap(mapComp.getInputMap(condition), ""); results.append("\n"); } if (actionB.isSelected()) { loadActionMap(mapComp.getActionMap(), ""); results.append("\n"); } if (bindingB.isSelected()) { loadBindingMap(mapComp, condition); } } catch (ClassCastException cce) { results.setText(cname + " is not a subclass of JComponent."); } catch (ClassNotFoundException cnfe) { results.setText(cname + " was not found."); } catch (InstantiationException ie) { results.setText(cname + " could not be instantiated."); } catch (Exception e) { results.setText("Exception found:\n" + e); e.printStackTrace(); } }