下面列出了java.awt.Dialog#getSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Just show the dialog but do not do anything about it.
*/
private boolean displayAlert(String projectDisplayName) {
String title = NbBundle.getMessage(UnboundTargetAlert.class, "UTA_TITLE", label, projectDisplayName);
final DialogDescriptor d = new DialogDescriptor(this, title);
d.setOptionType(NotifyDescriptor.OK_CANCEL_OPTION);
d.setMessageType(NotifyDescriptor.ERROR_MESSAGE);
d.setValid(false);
selectCombo.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
d.setValid(((String) selectCombo.getSelectedItem()).trim().length() > 0);
}
});
Dialog dlg = DialogDisplayer.getDefault().createDialog(d);
selectCombo.requestFocusInWindow();
// XXX combo box gets cut off at the bottom unless you do something - why??
Dimension sz = dlg.getSize();
dlg.setSize(sz.width, sz.height + 30);
dlg.setVisible(true);
return d.getValue() == NotifyDescriptor.OK_OPTION;
}
/**
* Positions the specified dialog at a position relative to its parent.
*
* @param dialog the dialog to be positioned.
* @param horizontalPercent the relative location.
* @param verticalPercent the relative location.
*/
public static void positionDialogRelativeToParent(final Dialog dialog,
final double horizontalPercent,
final double verticalPercent) {
final Container parent = dialog.getParent();
if (parent == null)
{
centerFrameOnScreen(dialog);
return;
}
final Dimension d = dialog.getSize();
final Dimension p = parent.getSize();
final int baseX = parent.getX();
final int baseY = parent.getY();
final int x = baseX + (int) (horizontalPercent * p.width);
final int y = baseY + (int) (verticalPercent * p.height);
// make sure the dialog fits completely on the screen...
final Rectangle s = parent.getGraphicsConfiguration().getBounds();
final Rectangle r = new Rectangle(x, y, d.width, d.height);
dialog.setBounds(r.intersection(s));
}
/**
* Positions the specified dialog at a position relative to its parent.
*
* @param dialog the dialog to be positioned.
* @param horizontalPercent the relative location.
* @param verticalPercent the relative location.
*/
public static void positionDialogRelativeToParent(Dialog dialog,
double horizontalPercent,
double verticalPercent) {
Dimension d = dialog.getSize();
Container parent = dialog.getParent();
Dimension p = parent.getSize();
int baseX = parent.getX() - d.width;
int baseY = parent.getY() - d.height;
int w = d.width + p.width;
int h = d.height + p.height;
int x = baseX + (int) (horizontalPercent * w);
int y = baseY + (int) (verticalPercent * h);
// make sure the dialog fits completely on the screen...
Rectangle s = getMaximumWindowBounds();
x = Math.min(x, (s.width - d.width));
x = Math.max(x, 0);
y = Math.min(y, (s.height - d.height));
y = Math.max(y, 0);
dialog.setBounds(x + s.x, y + s.y, d.width, d.height);
}
/**
* Positions the specified dialog at a position relative to its parent.
*
* @param dialog the dialog to be positioned.
* @param horizontalPercent the relative location.
* @param verticalPercent the relative location.
*/
public static void positionDialogRelativeToParent(Dialog dialog,
double horizontalPercent,
double verticalPercent) {
Dimension d = dialog.getSize();
Container parent = dialog.getParent();
Dimension p = parent.getSize();
int baseX = parent.getX() - d.width;
int baseY = parent.getY() - d.height;
int w = d.width + p.width;
int h = d.height + p.height;
int x = baseX + (int) (horizontalPercent * w);
int y = baseY + (int) (verticalPercent * h);
// make sure the dialog fits completely on the screen...
Rectangle s = getMaximumWindowBounds();
x = Math.min(x, (s.width - d.width));
x = Math.max(x, 0);
y = Math.min(y, (s.height - d.height));
y = Math.max(y, 0);
dialog.setBounds(x + s.x, y + s.y, d.width, d.height);
}
/**
* Positions the specified dialog at a position relative to its parent.
*
* @param dialog
* the dialog to be positioned.
* @param horizontalPercent
* the relative location.
* @param verticalPercent
* the relative location.
*/
public static void positionDialogRelativeToParent( final Dialog dialog, final double horizontalPercent,
final double verticalPercent ) {
final Container parent = dialog.getParent();
if ( parent == null || ( parent.isVisible() == false ) ) {
positionFrameOnScreen( dialog, horizontalPercent, verticalPercent );
return;
}
final Dimension d = dialog.getSize();
final Dimension p = parent.getSize();
final int baseX = parent.getX();
final int baseY = parent.getY();
final int parentPointX = baseX + (int) ( horizontalPercent * p.width );
final int parentPointY = baseY + (int) ( verticalPercent * p.height );
final int dialogPointX = Math.max( 0, parentPointX - (int) ( horizontalPercent * d.width ) );
final int dialogPointY = Math.max( 0, parentPointY - (int) ( verticalPercent * d.height ) );
// make sure the dialog fits completely on the screen...
final Rectangle s = parent.getGraphicsConfiguration().getBounds();
final Rectangle r = new Rectangle( dialogPointX, dialogPointY, d.width, d.height );
final Rectangle intersectedDialogBounds = r.intersection( s );
if ( intersectedDialogBounds.width < d.width ) {
r.x = s.width - d.width;
r.width = d.width;
}
if ( intersectedDialogBounds.height < d.height ) {
r.y = s.height - d.height;
r.height = d.height;
}
final Rectangle finalIntersection = r.intersection( s );
dialog.setBounds( finalIntersection );
}
private void formattersAddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_formattersAddButtonActionPerformed
VariablesFormatter f = new VariablesFormatter("");
final VariableFormatterEditPanel fPanel = new VariableFormatterEditPanel();
fPanel.load(f);
fPanel.setFormatterNames(getFormatterNames());
final Dialog[] dlgPtr = new Dialog[] { null };
DialogDescriptor formatterEditDescriptor = new DialogDescriptor(
fPanel,
NbBundle.getMessage(CategoryPanelFormatters.class, "TTL_AddFormatter"),
true,
NotifyDescriptor.OK_CANCEL_OPTION, NotifyDescriptor.OK_OPTION,
new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == NotifyDescriptor.OK_OPTION) {
boolean valid = fPanel.checkValidInput();
if (valid) {
dlgPtr[0].setVisible(false);
}
} else {
dlgPtr[0].setVisible(false);
}
}
});
formatterEditDescriptor.setClosingOptions(new Object[] {});
NotificationLineSupport notificationSupport = formatterEditDescriptor.createNotificationLineSupport();
fPanel.setValidityObjects(formatterEditDescriptor, notificationSupport, false);
//formatterEditDescriptor.setValid(false);
Dialog dlg = DialogDisplayer.getDefault().createDialog(formatterEditDescriptor);
Properties p = Properties.getDefault().getProperties("debugger.options.JPDA"); // NOI18N
int w = p.getInt("VariableFormatters_AddEdit_WIDTH", -1); // NOI18N
int h = p.getInt("VariableFormatters_AddEdit_HEIGHT", -1); // NOI18N
if (w > 0 && h > 0) {
dlg.setSize(new Dimension(w, h));
}
dlgPtr[0] = dlg;
dlg.setVisible(true);
Dimension dim = dlg.getSize();
p.setInt("VariableFormatters_AddEdit_WIDTH", dim.width); // NOI18N
p.setInt("VariableFormatters_AddEdit_HEIGHT", dim.height); // NOI18N
if (NotifyDescriptor.OK_OPTION.equals(formatterEditDescriptor.getValue())) {
fPanel.store(f);
((DefaultListModel) formattersList.getModel()).addElement(f);
formattersList.setSelectedValue(f, true);
}
/*
NotifyDescriptor.InputLine nd = new NotifyDescriptor.InputLine(
NbBundle.getMessage(CategoryPanelFormatters.class, "CategoryPanelFormatters.addDLG.nameLabel"),
NbBundle.getMessage(CategoryPanelFormatters.class, "CategoryPanelFormatters.addDLG.title"));
DialogDisplayer.getDefault().notify(nd);
VariablesFormatter f = new VariablesFormatter(nd.getInputText());
((DefaultListModel) formattersList.getModel()).addElement(f);
formattersList.setSelectedValue(f, true);
//JCheckBox cb = new JCheckBox(nd.getInputText());
//cb.setSelected(true);
//filterClassesList.add(cb);
//filterClassesList.repaint();
*/
}
private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editButtonActionPerformed
int index = formattersList.getSelectedIndex();
if (index < 0) return ;
DefaultListModel model = (DefaultListModel) formattersList.getModel();
VariablesFormatter f = (VariablesFormatter) model.getElementAt(index);
VariableFormatterEditPanel fPanel = new VariableFormatterEditPanel();
fPanel.load(f);
Set<String> formatterNames = getFormatterNames();
formatterNames.remove(f.getName());
fPanel.setFormatterNames(formatterNames);
DialogDescriptor formatterEditDescriptor = new DialogDescriptor(
fPanel,
NbBundle.getMessage(CategoryPanelFormatters.class, "TTL_EditFormatter"),
true,
NotifyDescriptor.OK_CANCEL_OPTION, NotifyDescriptor.OK_OPTION,
null);
NotificationLineSupport notificationSupport = formatterEditDescriptor.createNotificationLineSupport();
fPanel.setValidityObjects(formatterEditDescriptor, notificationSupport, true);
//formatterEditDescriptor.setValid(false);
Dialog dlg = DialogDisplayer.getDefault().createDialog(formatterEditDescriptor);
Properties p = Properties.getDefault().getProperties("debugger.options.JPDA"); // NOI18N
int w = p.getInt("VariableFormatters_AddEdit_WIDTH", -1); // NOI18N
int h = p.getInt("VariableFormatters_AddEdit_HEIGHT", -1); // NOI18N
if (w > 0 && h > 0) {
dlg.setSize(new Dimension(w, h));
}
dlg.setVisible(true);
Dimension dim = dlg.getSize();
p.setInt("VariableFormatters_AddEdit_WIDTH", dim.width); // NOI18N
p.setInt("VariableFormatters_AddEdit_HEIGHT", dim.height); // NOI18N
if (NotifyDescriptor.OK_OPTION.equals(formatterEditDescriptor.getValue())) {
fPanel.store(f);
checkBoxComponents.put(f, new JCheckBox(f.getName(), f.isEnabled()));
((DefaultListModel) formattersList.getModel()).setElementAt(f, index);
//formattersList.repaint();
formattersList.setSelectedValue(f, true);
loadSelectedFormatter(f);
}
}