下面列出了java.awt.Dialog#setSize ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
static float getScaleFactor() {
final Dialog dialog = new Dialog((Window) null);
dialog.setSize(100, 100);
dialog.setModal(true);
final float[] scaleFactors = new float[1];
Panel panel = new Panel() {
@Override
public void paint(Graphics g) {
float scaleFactor = 1;
if (g instanceof SunGraphics2D) {
scaleFactor = ((SunGraphics2D) g).surfaceData.getDefaultScale();
}
scaleFactors[0] = scaleFactor;
dialog.setVisible(false);
}
};
dialog.add(panel);
dialog.setVisible(true);
dialog.dispose();
return scaleFactors[0];
}
private static void showModalDialog(Frame targetFrame) {
Dialog dialog = new Dialog(targetFrame, true);
dialog.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
passed = true;
dialog.dispose();
}
});
dialog.setSize(400, 300);
dialog.setTitle("Modal Dialog!");
clickOnModalDialog(dialog);
dialog.setVisible(true);
}
private static void testScale(double scaleX, double scaleY) {
Dialog dialog = new Dialog((Frame) null, true) {
@Override
public void paint(Graphics g) {
super.paint(g);
AffineTransform tx = ((Graphics2D) g).getTransform();
dispose();
if (scaleX != tx.getScaleX() || scaleY != tx.getScaleY()) {
throw new RuntimeException(String.format("Wrong scale:"
+ "[%f, %f] instead of [%f, %f].",
tx.getScaleX(), tx.getScaleY(), scaleX, scaleY));
}
}
};
dialog.setSize(200, 300);
dialog.setVisible(true);
}
private static void testScale(double scaleX, double scaleY) {
Dialog dialog = new Dialog((Frame) null, true) {
@Override
public void paint(Graphics g) {
super.paint(g);
AffineTransform tx = ((Graphics2D) g).getTransform();
dispose();
if (scaleX != tx.getScaleX() || scaleY != tx.getScaleY()) {
throw new RuntimeException(String.format("Wrong scale:"
+ "[%f, %f] instead of [%f, %f].",
tx.getScaleX(), tx.getScaleY(), scaleX, scaleY));
}
}
};
dialog.setSize(200, 300);
dialog.setVisible(true);
}
@Override
public void run() {
Dialog dialog = new Dialog(frame);
dialog.setSize(300, 100);
dialog.setVisible(true);
try {
sleep(delay);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
dialog.setVisible(false);
dialog.dispose();
synchronized (frame) {
frame.notify();
}
}
private static void showModalDialog(Frame targetFrame) {
Dialog dialog = new Dialog(targetFrame, true);
dialog.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
passed = true;
dialog.dispose();
}
});
dialog.setSize(400, 300);
dialog.setTitle("Modal Dialog!");
clickOnModalDialog(dialog);
dialog.setVisible(true);
}
public static void main(String[] args) {
final Frame frame = new Frame("Test");
frame.setSize(400, 400);
frame.setBackground(FRAME_COLOR);
frame.setVisible(true);
final Dialog modalDialog = new Dialog(null, true);
modalDialog.setTitle("Modal Dialog");
modalDialog.setSize(400, 200);
modalDialog.setBackground(DIALOG_COLOR);
modalDialog.setModal(true);
new Thread(new Runnable() {
@Override
public void run() {
runTest(modalDialog, frame);
}
}).start();
modalDialog.setVisible(true);
}
static float getScaleFactor() {
final Dialog dialog = new Dialog((Window) null);
dialog.setSize(100, 100);
dialog.setModal(true);
final float[] scaleFactors = new float[1];
Panel panel = new Panel() {
@Override
public void paint(Graphics g) {
float scaleFactor = 1;
if (g instanceof SunGraphics2D) {
scaleFactor = ((SunGraphics2D) g).surfaceData.getDefaultScale();
}
scaleFactors[0] = scaleFactor;
dialog.setVisible(false);
}
};
dialog.add(panel);
dialog.setVisible(true);
dialog.dispose();
return scaleFactors[0];
}
private static void showModalDialog(Frame targetFrame) {
Dialog dialog = new Dialog(targetFrame, true);
dialog.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
passed = true;
dialog.dispose();
}
});
dialog.setSize(400, 300);
dialog.setTitle("Modal Dialog!");
clickOnModalDialog(dialog);
dialog.setVisible(true);
}
@Override
public void run() {
Dialog dialog = new Dialog(frame);
dialog.setSize(300, 100);
dialog.setVisible(true);
try {
sleep(delay);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
dialog.setVisible(false);
dialog.dispose();
synchronized (frame) {
frame.notify();
}
}
private static void showModalDialog(Frame targetFrame) {
Dialog dialog = new Dialog(targetFrame, true);
dialog.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
passed = true;
dialog.dispose();
}
});
dialog.setSize(400, 300);
dialog.setTitle("Modal Dialog!");
clickOnModalDialog(dialog);
dialog.setVisible(true);
}
static float getScaleFactor() {
final Dialog dialog = new Dialog((Window) null);
dialog.setSize(100, 100);
dialog.setModal(true);
final float[] scaleFactors = new float[1];
Panel panel = new Panel() {
@Override
public void paint(Graphics g) {
float scaleFactor = 1;
if (g instanceof SunGraphics2D) {
scaleFactor = ((SunGraphics2D) g).surfaceData.getDefaultScale();
}
scaleFactors[0] = scaleFactor;
dialog.setVisible(false);
}
};
dialog.add(panel);
dialog.setVisible(true);
dialog.dispose();
return scaleFactors[0];
}
private static void showModalDialog(Frame targetFrame) {
Dialog dialog = new Dialog(targetFrame, true);
dialog.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
passed = true;
dialog.dispose();
}
});
dialog.setSize(400, 300);
dialog.setTitle("Modal Dialog!");
clickOnModalDialog(dialog);
dialog.setVisible(true);
}
public static void main(String[] args) {
final Frame frame = new Frame("Test");
frame.setSize(400, 400);
frame.setBackground(FRAME_COLOR);
frame.setVisible(true);
final Dialog modalDialog = new Dialog(null, true);
modalDialog.setTitle("Modal Dialog");
modalDialog.setSize(400, 200);
modalDialog.setBackground(DIALOG_COLOR);
modalDialog.setModal(true);
new Thread(new Runnable() {
@Override
public void run() {
runTest(modalDialog, frame);
}
}).start();
modalDialog.setVisible(true);
}
static float getScaleFactor() {
final Dialog dialog = new Dialog((Window) null);
dialog.setSize(100, 100);
dialog.setModal(true);
final float[] scaleFactors = new float[1];
Panel panel = new Panel() {
@Override
public void paint(Graphics g) {
float scaleFactor = 1;
if (g instanceof SunGraphics2D) {
scaleFactor = getScreenScaleFactor();
}
scaleFactors[0] = scaleFactor;
dialog.setVisible(false);
}
};
dialog.add(panel);
dialog.setVisible(true);
dialog.dispose();
return scaleFactors[0];
}
protected void ifNecessaryShowNoWebFolderDialog() {
if (isShowNoWebFolderDialog()) {
final NotWebFolder panel = new NotWebFolder(NO_WEB_FOLDER_WARNING);
DialogDescriptor descriptor = new DialogDescriptor(panel, NO_WEB_FOLDER_TITLE, true, NotifyDescriptor.PLAIN_MESSAGE, NotifyDescriptor.YES_OPTION, null);
JButton okButton = new JButton(
NbBundle.getMessage(PageFlowController.class, "MSG_OkButtonText")); //NOI18N
descriptor.setOptions(new Object[]{okButton});
descriptor.setMessageType(NotifyDescriptor.PLAIN_MESSAGE);
descriptor.setClosingOptions(new Object[]{okButton});
descriptor.setOptionsAlign(DialogDescriptor.BOTTOM_ALIGN);
final Dialog d = DialogDisplayer.getDefault().createDialog(descriptor);
d.setSize(400, 200);
d.setVisible(true);
setShowNoWebFolderDialog(panel.getShowDialog());
}
}
private static void testScaleFactor(final GraphicsConfiguration gc) {
final Dialog dialog = new Dialog((Frame) null, "Test", true, gc);
try {
dialog.setSize(100, 100);
Panel panel = new Panel() {
@Override
public void paint(Graphics g) {
if (g instanceof Graphics2D) {
AffineTransform gcTx = gc.getDefaultTransform();
AffineTransform gTx
= ((Graphics2D) g).getTransform();
passed = gcTx.getScaleX() == gTx.getScaleX()
&& gcTx.getScaleY() == gTx.getScaleY();
} else {
passed = true;
}
dialog.setVisible(false);
}
};
dialog.add(panel);
dialog.setVisible(true);
if (!passed) {
throw new RuntimeException("Transform is not scaled!");
}
} finally {
dialog.dispose();
}
}
private static void testScaleFactor(final GraphicsConfiguration gc) {
final Dialog dialog = new Dialog((Frame) null, "Test", true, gc);
try {
dialog.setSize(100, 100);
Panel panel = new Panel() {
@Override
public void paint(Graphics g) {
if (g instanceof Graphics2D) {
AffineTransform gcTx = gc.getDefaultTransform();
AffineTransform gTx
= ((Graphics2D) g).getTransform();
passed = gcTx.getScaleX() == gTx.getScaleX()
&& gcTx.getScaleY() == gTx.getScaleY();
} else {
passed = true;
}
dialog.setVisible(false);
}
};
dialog.add(panel);
dialog.setVisible(true);
if (!passed) {
throw new RuntimeException("Transform is not scaled!");
}
} finally {
dialog.dispose();
}
}
public void testChildPropertiesWithDialogAsParent() {
parentDialog = new Dialog((Dialog) null, "parent Dialog");
parentDialog.setSize(WIDTH, HEIGHT);
parentDialog.setLocation(100, 100);
parentDialog.setBackground(Color.RED);
parentLabel = new Label("ParentForegroundAndFont");
parentFont = new Font("Courier New", Font.ITALIC, 15);
parentDialog.setForeground(Color.BLUE);
parentDialog.setFont(parentFont);
parentDialog.add(parentLabel);
parentDialog.setVisible(true);
dialogChild = new Dialog(parentDialog, "Dialog's child");
dialogChild.setSize(WIDTH, HEIGHT);
dialogChild.setLocation(WIDTH + 200, 100);
childLabel = new Label("ChildForegroundAndFont");
dialogChild.add(childLabel);
dialogChild.setVisible(true);
if (parentDialog.getBackground() == dialogChild.getBackground()) {
dispose();
throw new RuntimeException("Child Dialog Should NOT Inherit "
+ "Parent Dialog's Background Color");
}
if (parentDialog.getForeground() == dialogChild.getForeground()) {
dispose();
throw new RuntimeException("Child Dialog Should NOT Inherit "
+ "Parent Dialog's Foreground Color");
}
if (parentDialog.getFont() == dialogChild.getFont()) {
dispose();
throw new RuntimeException("Child Dialog Should NOT Inherit "
+ "Parent Dialog's Font Style/Color");
}
}
/** Requests access for address addr. If necessary asks the user. Returns true it the access
* has been granted. */
boolean allowAccess(InetAddress addr, String requestPath) {
if (accessAllowedNow(addr, requestPath))
return true;
Thread askThread = null;
synchronized (whoAsking) {
// one more test in the synchronized block
if (accessAllowedNow(addr, requestPath))
return true;
askThread = (Thread)whoAsking.get(addr);
if (askThread == null) {
askThread = Thread.currentThread();
whoAsking.put(addr, askThread);
}
}
// now ask the user
synchronized (HttpServerSettings.class) {
if (askThread != Thread.currentThread()) {
return accessAllowedNow(addr, requestPath);
}
try {
if (!isShowGrantAccessDialog ())
return false;
String msg = NbBundle.getMessage (HttpServerSettings.class, "MSG_AddAddress", addr.getHostAddress ());
final GrantAccessPanel panel = new GrantAccessPanel (msg);
DialogDescriptor descriptor = new DialogDescriptor (
panel,
NbBundle.getMessage (HttpServerSettings.class, "CTL_GrantAccessTitle"),
true,
NotifyDescriptor.YES_NO_OPTION,
NotifyDescriptor.NO_OPTION,
null
);
descriptor.setMessageType (NotifyDescriptor.QUESTION_MESSAGE);
// descriptor.setOptionsAlign (DialogDescriptor.BOTTOM_ALIGN);
final Dialog d = DialogDisplayer.getDefault ().createDialog (descriptor);
d.setSize (580, 180);
d.setVisible(true);
setShowGrantAccessDialog (panel.getShowDialog ());
if (NotifyDescriptor.YES_OPTION.equals(descriptor.getValue ())) {
appendAddressToGranted(addr.getHostAddress());
return true;
}
else
return false;
}
finally {
whoAsking.remove(addr);
}
} // end synchronized
}