// TODO 1.5: Remove in 1.5 protected void installPreviousButtonListenersFromSuper(Component c) { AbstractButton sc = (AbstractButton) super.createPreviousButton(); ActionListener[] als = sc.getActionListeners(); MouseListener[] mls = sc.getMouseListeners(); if (c instanceof AbstractButton) { ((AbstractButton) c).addActionListener(als[0]); } c.addMouseListener(mls[0]); }
/** * Utility method for initializing a Window for displaying a JXErrorPane. This is particularly * useful because the differences between JFrame and JDialog are so minor. removed. */ private void initWindow(final Window w, final JXErrorPane pane) { w.setLayout(new BorderLayout()); w.add(pane, BorderLayout.CENTER); final Action closeAction = new CloseAction(w); closeButton.addActionListener(closeAction); final ResizeWindow resizeListener = new ResizeWindow(w); // make sure this action listener is last (or, oddly, the first in the list) ActionListener[] list = detailButton.getActionListeners(); for (ActionListener a : list) { detailButton.removeActionListener(a); } detailButton.addActionListener(resizeListener); for (ActionListener a : list) { detailButton.addActionListener(a); } if (w instanceof JFrame) { final JFrame f = (JFrame) w; f.getRootPane().setDefaultButton(closeButton); f.setResizable(true); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); f.getRootPane().registerKeyboardAction(closeAction, ks, JComponent.WHEN_IN_FOCUSED_WINDOW); } else if (w instanceof JDialog) { final JDialog d = (JDialog) w; d.getRootPane().setDefaultButton(closeButton); d.setResizable(true); d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); d.getRootPane().registerKeyboardAction(closeAction, ks, JComponent.WHEN_IN_FOCUSED_WINDOW); } w.addWindowListener( new WindowAdapter() { public void windowClosed(WindowEvent e) { // remove the action listener closeButton.removeActionListener(closeAction); detailButton.removeActionListener(resizeListener); exitIfFatal(); } }); w.pack(); }
/** Removes all action listeners associated with an AbstractButton */ private void removeActionListeners(AbstractButton ab) { ActionListener[] al = ab.getActionListeners(); for (int i = 0; i < al.length; i++) { ab.removeActionListener(al[i]); } } // removeActionListeners()