import org.openide.util.HelpCtx; //导入方法依赖的package包/类
boolean customize(final ValidityAwarePanel customizer, Runnable updater, boolean focusToEditor) {
ValidityAwarePanel showingCustomizer = getShowingCustomizer();
if (showingCustomizer != null) {
ProfilerDialogs.displayWarning(
Bundle.ProfilingPointsManager_AnotherPpEditedMsg());
SwingUtilities.getWindowAncestor(showingCustomizer).requestFocus();
showingCustomizer.requestFocusInWindow();
} else {
CustomizerButton cb = getCustomizerButton();
customizer.addValidityListener(cb);
cb.setEnabled(customizer.areSettingsValid()); // In fact customizer should be valid but just to be sure...
JPanel customizerContainer = new JPanel(new BorderLayout());
JPanel customizerSpacer = new JPanel(new BorderLayout());
customizerSpacer.setBorder(BorderFactory.createEmptyBorder(0, 0, 20, 0));
customizerSpacer.add(customizer, BorderLayout.CENTER);
customizerContainer.add(customizerSpacer, BorderLayout.CENTER);
customizerContainer.add(new JSeparator(), BorderLayout.SOUTH);
HelpCtx helpCtx = null;
if (customizer instanceof HelpCtx.Provider) {
helpCtx = ((HelpCtx.Provider) customizer).getHelpCtx();
}
DialogDescriptor dd = new DialogDescriptor(customizerContainer, Bundle.ProfilingPointsManager_PpCustomizerCaption(), false,
new Object[] { cb, DialogDescriptor.CANCEL_OPTION },
cb, 0, helpCtx, null);
final Dialog d = DialogDisplayer.getDefault().createDialog(dd);
d.addWindowListener(new CustomizerListener(d, dd, updater));
d.setModal(true);
// give focus to the initial focus target
d.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
if (customizer.getInitialFocusTarget() != null) {
customizer.getInitialFocusTarget().requestFocusInWindow();
}
}
});
if (focusToEditor) {
Dimension dim = d.getPreferredSize();
Component masterComponent = WindowManager.getDefault().getRegistry().getActivated();
if (masterComponent != null) {
Rectangle b = masterComponent.getBounds();
Point location = new Point((b.x + (b.width / 2)) - (dim.width / 2),
(b.y + (b.height / 2)) - (dim.height / 2));
SwingUtilities.convertPointToScreen(location, masterComponent);
d.setLocation(location);
}
}
d.setVisible(true);
if (dd.getValue() == cb) {
return true;
}
}
return false;
}