下面列出了javax.swing.JDialog#setModal ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public CopyMongoCollectionService(
String sourceDatabase, String sourceNamespace, String sourceCollection,
String targetDatabase, String targetNamespace, String targetCollection) {
this.sourceDatabase = sourceDatabase;
this.sourceNamespace = sourceNamespace;
this.sourceCollection = sourceCollection;
this.targetDatabase = targetDatabase;
this.targetNamespace = targetNamespace;
this.targetCollection = targetCollection;
panel = new JXPanel();
panel.setLayout(new MigLayout("wrap 1"));
panel.add(label, "growx, wrap 20");
panel.add(progressBar, "grow, push");
dialog = new JDialog();
dialog.add(panel);
dialog.setSize(300, 120);
Point p = WindowUtils.getPointForCentering(dialog);
dialog.setLocation(p);
dialog.setModal(true);
dialog.setResizable(false);
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
}
public static void showLoadingWindow()
{
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
}
JOptionPane pane = new JOptionPane("Загрузка. Пожалуйста, подождите...", JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new Object[]{}, null);
LOADING_PANE = new JDialog();
LOADING_PANE.setModal(false);
LOADING_PANE.setContentPane(pane);
LOADING_PANE.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
LOADING_PANE.setLocation(100, 200);
LOADING_PANE.pack();
LOADING_PANE.setVisible(true);
}
public static JDialog createJDialog(MTGUIComponent c, boolean resizable,boolean modal)
{
JDialog j = new JDialog();
j.getContentPane().setLayout(new BorderLayout());
j.getContentPane().add(c, BorderLayout.CENTER);
j.setTitle(c.getTitle());
j.setLocationRelativeTo(null);
if(c.getIcon()!=null)
j.setIconImage(c.getIcon().getImage());
j.pack();
j.setModal(modal);
j.setResizable(resizable);
j.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
c.onDestroy();
}
});
return j;
}
@Override
public GDXProgressDialog build() {
optionPane = new JOptionPane(message, JOptionPane.INFORMATION_MESSAGE, JOptionPane.DEFAULT_OPTION, null,
new Object[] {}, null);
dialog = new JDialog();
dialog.setTitle((String) title);
dialog.setModal(true);
dialog.setContentPane(optionPane);
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
dialog.pack();
return this;
}
public RedisCleanService(Jedis jedis) {
this.treeTableModel = treeTableModel;
this.jedis = jedis;
panel = new JXPanel();
panel.setLayout(new MigLayout("wrap 1"));
panel.add(label, "growx, wrap 20");
panel.add(progressBar, "grow, push");
dialog = new JDialog();
dialog.add(panel);
dialog.setSize(300, 120);
Point p = WindowUtils.getPointForCentering(dialog);
dialog.setLocation(p);
dialog.setModal(true);
dialog.setResizable(false);
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
}
private void imageBorderWizardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_imageBorderWizardActionPerformed
deriveBorder.setSelected(false);
ImageBorderWizardTabbedPane iw = new ImageBorderWizardTabbedPane(resources, themeName);
String name = (String)componentName.getSelectedItem();
String uiid;
if(prefix == null || prefix.length() == 0) {
uiid = name + ".border";
} else {
uiid = name + "." + prefix + "border";
}
iw.addToAppliesToList(uiid);
JDialog dlg = new JDialog(SwingUtilities.windowForComponent(this));
dlg.setLayout(new java.awt.BorderLayout());
dlg.add(java.awt.BorderLayout.CENTER, iw);
dlg.pack();
dlg.setLocationRelativeTo(this);
dlg.setModal(true);
dlg.setVisible(true);
Border b = (Border)resources.getTheme(themeName).get(uiid);
if(b != null) {
currentBorder = b;
((CodenameOneComponentWrapper)borderLabel).getCodenameOneComponent().getStyle().setBorder(b);
borderLabel.repaint();
}
}
public WeaponDataSaveService(
Collection<WeaponPojo> weapons,
String targetDatabase, String targetNamespace, String targetCollection) {
this.weapons = weapons;
this.targetDatabase = targetDatabase;
this.targetNamespace = targetNamespace;
this.targetCollection = targetCollection;
panel = new JXPanel();
panel.setLayout(new MigLayout("wrap 1"));
panel.add(label, "growx, wrap 20");
panel.add(progressBar, "grow, push");
dialog = new JDialog();
dialog.add(panel);
dialog.setSize(300, 120);
Point p = WindowUtils.getPointForCentering(dialog);
dialog.setLocation(p);
dialog.setModal(true);
dialog.setResizable(false);
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
}
public RedisRefreshService(RedisTreeTableModel treeTableModel, String host, int port) {
this.treeTableModel = treeTableModel;
this.host = host;
this.port = port;
panel = new JXPanel();
panel.setLayout(new MigLayout("wrap 1"));
panel.add(label, "growx, wrap 20");
panel.add(progressBar, "grow, push");
dialog = new JDialog();
dialog.add(panel);
dialog.setSize(300, 120);
Point p = WindowUtils.getPointForCentering(dialog);
dialog.setLocation(p);
dialog.setModal(true);
dialog.setResizable(false);
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
}
public StrengthTestService(
StrengthTestConfig config, MyTablePanel tablePanel) {
this.model = model;
this.config = config;
this.count = config.getMaxTry();
this.tablePanel = tablePanel;
panel = new JXPanel();
panel.setLayout(new MigLayout("wrap 1"));
panel.add(label, "growx, wrap 20");
panel.add(progressBar, "grow, push");
dialog = new JDialog();
dialog.add(panel);
dialog.setSize(300, 120);
Point p = WindowUtils.getPointForCentering(dialog);
dialog.setLocation(p);
dialog.setModal(true);
dialog.setResizable(false);
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
model = new StrengthTestResultModel();
tablePanel.setTableModel(model);
}
public WeaponManualDataImportService(
File file,
WeaponTableModel model,
ArrayList<Double> dprList) {
this.importExcelFile = file;
this.weaponModel = model;
this.levelDprList = dprList;
panel = new JXPanel();
panel.setLayout(new MigLayout("wrap 1"));
panel.add(label, "growx, wrap 20");
panel.add(progressBar, "grow, push");
dialog = new JDialog();
dialog.add(panel);
dialog.setSize(300, 120);
Point p = WindowUtils.getPointForCentering(dialog);
dialog.setLocation(p);
dialog.setModal(true);
dialog.setResizable(false);
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
}
public static JDialog getCenterDialog(int width, int height,
JComponent panel, JButton okButton) {
JDialog dialog = new JDialog();
dialog.setLayout(new MigLayout("wrap 1", "[100%]"));
dialog.add(panel, "width 100%, height 90%, grow");
if ( okButton != null ) {
dialog.add(okButton, "align center");
}
dialog.setSize(width, height);
Point cpoint = WindowUtils.getPointForCentering(dialog);
dialog.setLocation(cpoint);
dialog.setModal(true);
return dialog;
}
@Override
protected void process(List<Integer> chunks) {
if ( stage == Stage.GET_NUM_OF_ICONS ) {
panel = new JXPanel();
panel.setLayout(new MigLayout("wrap 1"));
panel.add(label, "growx, wrap 20");
panel.add(progressBar, "grow, push");
dialog = new JDialog();
dialog.add(panel);
dialog.setSize(300, 120);
Point p = WindowUtils.getPointForCentering(dialog);
dialog.setLocation(p);
dialog.setModal(true);
dialog.setResizable(false);
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
dialog.setVisible(true);
label.setText("正在获取图标列表...");
label.setFont(MainFrame.BIG_FONT);
progressBar.setIndeterminate(true);
} else if ( stage == Stage.GOT_NUM_OF_ICONS ) {
label.setFont(MainFrame.BIG_FONT);
label.setText("总图标数量: " + icons.size());
label.repaint();
progressBar.setIndeterminate(false);
progressBar.setMinimum(0);
progressBar.setMaximum(icons.size());
progressBar.setStringPainted(true);
} else if ( stage == Stage.DOWNLOAD_ICONS ) {
if ( chunks != null && chunks.size()>0 ) {
int percent = chunks.get(chunks.size()-1);
progressBar.setValue(percent);
}
} else if ( stage == Stage.INITIAL_EQUIPS ) {
label.setText("正在初始化装备数据...");
progressBar.setIndeterminate(true);
}
}
/**
* Empties the cache: deletes all files in the cache.<br>
* Displays a modal info dialog about the fact that the cache is being emptied.
* @param owner optional owner of the info dialog
*/
protected static void emptyCache_( final String cacheEntity, final Dialog owner, final String infoTextKey, final String cacheFolder ) {
System.out.println( "Clearing " + cacheEntity + " cache..." );
final JDialog infoDialog = owner == null ? new JDialog() : new JDialog( owner );
infoDialog.setModal( true );
infoDialog.setTitle( Language.getText( "general.infoTitle" ) );
final JLabel infoLabel = new JLabel( Language.getText( infoTextKey ) );
infoLabel.setFont( infoLabel.getFont().deriveFont( Font.ITALIC ) );
infoLabel.setBorder( BorderFactory.createEmptyBorder( 25, 35, 25, 35 ) );
infoDialog.getContentPane().add( infoLabel );
infoDialog.pack();
if ( owner == null )
infoDialog.setLocationRelativeTo( null );
else
GuiUtils.centerWindowToWindow( infoDialog, owner );
new NormalThread( cacheEntity + " cache emptier" ) {
@Override
public void run() {
final File[] cacheFiles = new File( cacheFolder ).listFiles();
if ( cacheFiles != null )
for ( final File cacheFile : cacheFiles )
deleteFile( cacheFile );
infoDialog.dispose();
}
}.start();
infoDialog.setVisible( true );
}
void showPasswordDialog(boolean wasWrong) {
WebPanel passPanel = new WebPanel();
WebLabel passLabel = new WebLabel(Tr.tr("Please enter your key password:"));
passPanel.add(passLabel, BorderLayout.NORTH);
final WebPasswordField passField = new WebPasswordField();
passPanel.add(passField, BorderLayout.CENTER);
if (wasWrong) {
WebLabel wrongLabel = new WebLabel(Tr.tr("Wrong password"));
wrongLabel.setForeground(Color.RED);
passPanel.add(wrongLabel, BorderLayout.SOUTH);
}
WebOptionPane passPane = new WebOptionPane(passPanel,
WebOptionPane.QUESTION_MESSAGE,
WebOptionPane.OK_CANCEL_OPTION);
JDialog dialog = passPane.createDialog(mMainFrame, Tr.tr("Enter password"));
dialog.setModal(true);
dialog.addWindowFocusListener(new WindowAdapter() {
@Override
public void windowGainedFocus(WindowEvent e) {
passField.requestFocusInWindow();
}
});
// blocking
LOGGER.info("asking for password…");
dialog.setVisible(true);
Object value = passPane.getValue();
if (value != null && value.equals(WebOptionPane.OK_OPTION))
mControl.connect(passField.getPassword());
}
public void showOptions0() {
IdeOptions o = this; // new IdeOptions(IdeOptions.theCurrentOptions);
JPanel p1 = new JPanel(new GridLayout(1, 1));
p1.add(new JScrollPane(general()));
JPanel p2 = new JPanel(new GridLayout(1, 1));
p2.add(new JScrollPane(onlyColors()));
JPanel p3 = new JPanel(new GridLayout(1, 1));
p3.add(new JScrollPane(outline()));
JTabbedPane jtb = new JTabbedPane();
jtb.add("General", p1);
jtb.add("Colors", p2);
jtb.add("Outline", p3);
CodeTextPanel cc = new CodeTextPanel("", AqlOptions.getMsg());
jtb.addTab("CQL", cc);
jtb.setSelectedIndex(selected_tab);
JPanel oo = new JPanel(new GridLayout(1, 1));
oo.add(jtb);
// oo.setPreferredSize(theD);
// outline at top otherwise weird sizing collapse on screen
JOptionPane pane = new JOptionPane(oo, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null,
new String[] { "OK", "Cancel", "Reset", "Save", "Load", "Delete" }, "OK");
// pane.setPreferredSize(theD);
JDialog dialog = pane.createDialog(null, "Options");
dialog.setModal(false);
dialog.setResizable(true);
dialog.addWindowListener(new WindowAdapter() {
@Override
public void windowDeactivated(WindowEvent e) {
Object ret = pane.getValue();
selected_tab = jtb.getSelectedIndex();
if (ret == "OK") {
theCurrentOptions = o;
notifyListenersOfChange();
} else if (ret == "Reset") {
new IdeOptions().showOptions0();
} else if (ret == "Save") { // save
save(o);
o.showOptions0();
} else if (ret == "Load") { // load
load().showOptions0();
} else if (ret == "Delete") {
delete();
o.showOptions0();
}
}
});
dialog.setPreferredSize(theD);
dialog.pack();
dialog.setLocationRelativeTo(null);
dialog.setVisible(true);
}
@Override
public IExpr evaluate(final IAST ast, EvalEngine engine) {
if (Desktop.isDesktopSupported()) {
IAST dialogNoteBook = null;
if (ast.isAST2() && ast.arg2().isAST(F.DialogNotebook, 2)) {
dialogNoteBook = (IAST) ast.arg2();
} else if (ast.isAST1() && ast.arg1().isAST(F.DialogNotebook, 2)) {
dialogNoteBook = (IAST) ast.arg1();
}
IAST list;
if (dialogNoteBook == null) {
if (ast.isAST1()) {
if (ast.arg1().isList()) {
list = (IAST) ast.arg1();
} else {
list = F.List(ast.arg1());
}
} else {
return F.NIL;
}
} else {
if (dialogNoteBook.arg1().isList()) {
list = (IAST) dialogNoteBook.arg1();
} else {
list = F.List(dialogNoteBook.arg1());
}
}
JDialog dialog = new JDialog();
dialog.setTitle("DialogInput");
dialog.setSize(320, 200);
dialog.setModal(true);
// dialog.setLayout(new FlowLayout(FlowLayout.LEFT));
// dialog.setLayout(new GridLayout(list.argSize(), 1));
IExpr[] result = new IExpr[] { F.NIL };
if (addComponents(dialog, list, dialog, engine, result)) {
dialog.setVisible(true);
if (result[0].isPresent()) {
return result[0];
}
}
}
return F.NIL;
}
public void testDiffView () throws Throwable {
// create a file and initial commit
File file = new File(getWorkTreeDir(), "file.txt");
file.createNewFile();
// chain of change & commit
StringBuilder content = new StringBuilder();
for (int i = 1; i < 10; ++i) {
for (int j = 1; j < 20; ++j) {
content.append("File change number ").append(i).append("_").append(j).append("\n");
}
write(file, content.toString());
System.out.println("Commit nbr. " + i);
commit(wc);
}
// local changes
// changes every few lines
int pos = content.indexOf("\n");
while (pos != -1) {
int nextPos = content.indexOf("\n", pos + 30);
if (nextPos == -1) {
pos = -1;
} else {
String replaceString = "Local change \nLocal change \nLocal change \n";
content.replace(pos + 1, nextPos, replaceString);
pos = nextPos + nextPos - pos + replaceString.length();
// every 5 next lines
for (int i = 0; i < 5 && pos != -1; ++i) {
pos = content.indexOf("\n", pos + 1);
}
}
}
write(file, content.toString());
boolean showing = HgSearchHistorySupport.getInstance(file).searchHistory(100);
assertTrue(showing);
JDialog d = new JDialog((JFrame)null, "Close dialog");
d.setModal(false);
d.setVisible(true);
while (d.isVisible()) {
Thread.sleep(1000);
}
}
/**
* This method is called once the user selects an instance. It writes the instance to an xml file and calls the code generation.
*
* @return <code>true</code>/<code>false</code> if writing instance file and code generation are (un)successful
*/
@Override
public boolean performFinish() {
boolean ret = false;
final CodeGenerators genKind = selectedTask.getCodeGen();
CodeGenerator codeGenerator = null;
String additionalResources = selectedTask.getAdditionalResources();
final LocatorPage currentPage = (LocatorPage) getContainer().getCurrentPage();
IResource targetFile = (IResource) currentPage.getSelectedResource().getFirstElement();
String taskName = selectedTask.getName();
JOptionPane optionPane = new JOptionPane("CogniCrypt is now generating code that implements " + selectedTask.getDescription() + "\ninto file " + ((targetFile != null)
? targetFile.getName()
: "Output.java") + ". This should take no longer than a few seconds.", JOptionPane.INFORMATION_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new Object[] {}, null);
JDialog waitingDialog = optionPane.createDialog("Generating Code");
waitingDialog.setModal(false);
waitingDialog.setVisible(true);
Configuration chosenConfig = null;
try {
switch (genKind) {
case CrySL:
CrySLBasedCodeGenerator.clearParameterCache();
File templateFile = CodeGenUtils.getResourceFromWithin(selectedTask.getCodeTemplate()).listFiles()[0];
codeGenerator = new CrySLBasedCodeGenerator(targetFile);
String projectRelDir = Constants.outerFileSeparator + codeGenerator.getDeveloperProject()
.getSourcePath() + Constants.outerFileSeparator + Constants.PackageName + Constants.outerFileSeparator;
String pathToTemplateFile = projectRelDir + templateFile.getName();
String resFileOSPath = "";
IPath projectPath = targetFile.getProject().getRawLocation();
if (projectPath == null) {
projectPath = targetFile.getProject().getLocation();
}
resFileOSPath = projectPath.toOSString() + pathToTemplateFile;
Files.createDirectories(Paths.get(projectPath.toOSString() + projectRelDir));
Files.copy(templateFile.toPath(), Paths.get(resFileOSPath), StandardCopyOption.REPLACE_EXISTING);
codeGenerator.getDeveloperProject().refresh();
resetAnswers();
chosenConfig = new CrySLConfiguration(resFileOSPath, ((CrySLBasedCodeGenerator) codeGenerator).setUpTemplateClass(pathToTemplateFile));
break;
case XSL:
this.constraints = (this.constraints != null) ? this.constraints : new HashMap<>();
final InstanceGenerator instanceGenerator = new InstanceGenerator(CodeGenUtils.getResourceFromWithin(selectedTask.getModelFile())
.getAbsolutePath(), "c0_" + taskName, selectedTask.getDescription());
instanceGenerator.generateInstances(this.constraints);
// Initialize Code Generation
codeGenerator = new XSLBasedGenerator(targetFile, selectedTask.getCodeTemplate());
chosenConfig = new XSLConfiguration(instanceGenerator.getInstances().values().iterator()
.next(), this.constraints, codeGenerator.getDeveloperProject().getProjectPath() + Constants.innerFileSeparator + Constants.pathToClaferInstanceFile);
break;
default:
return false;
}
ret = codeGenerator.generateCodeTemplates(chosenConfig, additionalResources);
try {
codeGenerator.getDeveloperProject().refresh();
} catch (CoreException e1) {
Activator.getDefault().logError(e1);
}
} catch (Exception ex) {
Activator.getDefault().logError(ex);
} finally {
waitingDialog.setVisible(false);
waitingDialog.dispose();
}
return ret;
}
/** Test method for {@link com.sldeditor.ui.detail.config.sortby.SortByPanel#SortByPanel()}. */
@Test
public void testSortByPanel() {
TestSortByUpdate output = new TestSortByUpdate();
TestSortByPanel panel = new TestSortByPanel(output, 6);
JDialog dialog = new JDialog();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setModal(true);
dialog.add(panel, BorderLayout.CENTER);
dialog.pack();
dialog.setLocation(200, 200);
dialog.setTitle("SortBy Test Dialog");
List<String> fieldList = Arrays.asList("Field1", "Field2", "Field3", "Field4", "Field5");
String selectedFieldList = "Field2 D, Field4 A";
panel.populateFieldNames(fieldList);
panel.setText("");
panel.setText(selectedFieldList);
assertEquals(selectedFieldList, panel.getText());
int[] selectedIndexes = new int[1];
selectedIndexes[0] = 1;
panel.selectDestination(selectedIndexes);
panel.moveDestinationUp();
assertEquals("Field4 A, Field2 D", output.text);
panel.moveDestinationUp();
assertEquals("Field4 A, Field2 D", output.text);
panel.moveDestinationDown();
assertEquals("Field2 D, Field4 A", output.text);
panel.moveDestinationDown();
assertEquals("Field2 D, Field4 A", output.text);
// Move source to destination
int[] selectedSourceIndexes = new int[2];
selectedSourceIndexes[0] = 1;
selectedSourceIndexes[1] = 2;
panel.selectSource(selectedSourceIndexes);
panel.moveSrcToDestination();
assertEquals("Field2 D, Field4 A, Field3 A, Field5 A", output.text);
// Move destination to source
selectedIndexes[0] = 0;
panel.selectDestination(selectedIndexes);
panel.moveDestinationToSource();
assertEquals("Field4 A, Field3 A, Field5 A", output.text);
panel.setSortOrder(1, false);
assertEquals("Field4 A, Field3 D, Field5 A", output.text);
panel.setSortOrder(1, true);
assertEquals("Field4 A, Field3 A, Field5 A", output.text);
// Remove field from data source
fieldList = Arrays.asList("Field1", "Field2", "Field3", "Field4");
panel.populateFieldNames(fieldList);
assertEquals("Field4 A, Field3 A", output.text);
// Increase code coverage
panel.dataSourceLoaded(GeometryTypeEnum.POINT, false);
panel.dataSourceAboutToUnloaded(null);
panel = new TestSortByPanel(null, 6);
panel.sortOrderUpdated();
// If the next is uncommented the unit test stops being unattended
// dialog.setVisible(true);
}
public static int internalShowOptionDialog(final Component parentComponent,
Object message, String title, int optionType, int messageType,
Icon icon, Object[] options, Object initialValue)
throws HeadlessException {
Window parentWindow = internalGetWindowForComponent(parentComponent);
boolean parentIsModal = parentWindow instanceof Dialog
&& ((Dialog)parentWindow).isModal();
int ret = CLOSED_OPTION;
POptionPane pane = new POptionPane(message, messageType,
optionType, icon,
options, initialValue);
pane.setInitialValue(initialValue);
pane.setComponentOrientation(((parentComponent == null)
? getRootFrame() : parentComponent).getComponentOrientation());
int style = internalStyleFromMessageType(messageType);
JDialog dialog = pane.createDialog(parentWindow, parentComponent, title, style);
dialog.setAlwaysOnTop(true);
dialog.setModal(true);
setAllWhite(pane);
// prevent locking of application
if(parentIsModal) {
((Dialog)parentWindow).setModal(false);
}
pane.selectInitialValue();
dialog.toFront();
dialog.setVisible(true);
dialog.dispose();
Object selectedValue = pane.getValue();
if (selectedValue != null) {
if (options != null) {
for (int counter = 0, maxCounter = options.length;
counter < maxCounter; counter++) {
if (options[counter].equals(selectedValue)) {
ret = counter;
}
}
} else {
if (selectedValue instanceof Integer) {
ret = ((Integer) selectedValue);
}
}
}
// prevent locking of application
if(parentIsModal) {
((Dialog)parentWindow).setModal(true);
}
return ret;
}