List of usage examples for javax.swing JOptionPane QUESTION_MESSAGE
int QUESTION_MESSAGE
To view the source code for javax.swing JOptionPane QUESTION_MESSAGE.
Click Source Link
From source file:com.hexidec.ekit.component.PropertiesDialog.java
public PropertiesDialog(Window parent, String[] fields, String[] types, String[] values, String title, boolean bModal) { super(parent, title); setModal(bModal);/* www.ja va2 s. c o m*/ htInputFields = new Hashtable<String, JComponent>(); final Object[] buttonLabels = { Translatrix.getTranslationString("DialogAccept"), Translatrix.getTranslationString("DialogCancel") }; List<Object> panelContents = new ArrayList<Object>(); for (int iter = 0; iter < fields.length; iter++) { String fieldName = fields[iter]; String fieldType = types[iter]; JComponent fieldComponent; JComponent panelComponent = null; if (fieldType.equals("text") || fieldType.equals("integer")) { fieldComponent = new JTextField(3); if (values[iter] != null && values[iter].length() > 0) { ((JTextField) (fieldComponent)).setText(values[iter]); } if (fieldType.equals("integer")) { ((AbstractDocument) ((JTextField) (fieldComponent)).getDocument()) .setDocumentFilter(new DocumentFilter() { @Override public void insertString(FilterBypass fb, int offset, String text, AttributeSet attrs) throws BadLocationException { replace(fb, offset, 0, text, attrs); } @Override public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException { if (StringUtils.isNumeric(text)) { super.replace(fb, offset, length, text, attrs); } } }); } } else if (fieldType.equals("bool")) { fieldComponent = new JCheckBox(fieldName); if (values[iter] != null) { ((JCheckBox) (fieldComponent)).setSelected(values[iter] == "true"); } panelComponent = fieldComponent; } else if (fieldType.equals("combo")) { fieldComponent = new JComboBox(); if (values[iter] != null) { StringTokenizer stParse = new StringTokenizer(values[iter], ",", false); while (stParse.hasMoreTokens()) { ((JComboBox) (fieldComponent)).addItem(stParse.nextToken()); } } } else { fieldComponent = new JTextField(3); } htInputFields.put(fieldName, fieldComponent); if (panelComponent == null) { panelContents.add(fieldName); panelContents.add(fieldComponent); } else { panelContents.add(panelComponent); } } jOptionPane = new JOptionPane(panelContents.toArray(), JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, buttonLabels, buttonLabels[0]); setContentPane(jOptionPane); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); jOptionPane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { String prop = e.getPropertyName(); if (isVisible() && (e.getSource() == jOptionPane) && (prop.equals(JOptionPane.VALUE_PROPERTY) || prop.equals(JOptionPane.INPUT_VALUE_PROPERTY))) { Object value = jOptionPane.getValue(); if (value == JOptionPane.UNINITIALIZED_VALUE) { return; } if (value.equals(buttonLabels[0])) { setVisible(false); } else { setVisible(false); } } } }); this.pack(); setLocation(SwingUtilities.getPointForCentering(this, parent)); }
From source file:com.qspin.qtaste.ui.testcampaign.TestCampaignMainPanel.java
public void genUI() { TestCampaignTreeModel model = new TestCampaignTreeModel("Test Campaign"); treeTable = new JTreeTable(model); FormLayout layout = new FormLayout("6px, pref, 6px, pref, 6px, pref, 6px, pref, 6px, pref, 6px:grow", "6px, fill:pref, 6px"); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); int colIndex = 2; JLabel label = new JLabel("Campaign:"); saveMetaCampaignButton.setIcon(ResourceManager.getInstance().getImageIcon("icons/save_32")); saveMetaCampaignButton.setToolTipText("Save campaign"); saveMetaCampaignButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (selectedCampaign == null) { logger.warn("No Campaign created"); return; }/*from w ww. ja va2 s . co m*/ treeTable.save(selectedCampaign.getFileName(), selectedCampaign.getCampaignName()); } }); addNewMetaCampaignButton.setIcon(ResourceManager.getInstance().getImageIcon("icons/add")); addNewMetaCampaignButton.setToolTipText("Define a new campaign"); addNewMetaCampaignButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String newCampaign = JOptionPane.showInputDialog(null, "New campaign creation:", "Campaign name:", JOptionPane.QUESTION_MESSAGE); if (newCampaign != null && newCampaign.length() > 0) { int index = addTestCampaign(newCampaign); metaCampaignComboBox.setSelectedIndex(index); MetaCampaignFile currentSelectedCampaign = (MetaCampaignFile) metaCampaignComboBox .getSelectedItem(); selectedCampaign = currentSelectedCampaign; if (selectedCampaign != null) { treeTable.save(selectedCampaign.getFileName(), selectedCampaign.getCampaignName()); } metaCampaignComboBox.validate(); metaCampaignComboBox.repaint(); } } }); // get last selected campaign GUIConfiguration guiConfiguration = GUIConfiguration.getInstance(); String lastSelectedCampaign = guiConfiguration.getString(LAST_SELECTED_CAMPAIGN_PROPERTY); // add campaigns found in the list MetaCampaignFile[] campaigns = populateCampaignList(); builder.add(label, cc.xy(colIndex, 2)); colIndex += 2; builder.add(metaCampaignComboBox, cc.xy(colIndex, 2)); colIndex += 2; // add test campaign mouse listener, for the Rename and Remove actions TestcampaignMouseListener testcampaignMouseListener = new TestcampaignMouseListener(); java.awt.Component[] mTestcampaignListComponents = metaCampaignComboBox.getComponents(); for (int i = 0; i < mTestcampaignListComponents.length; i++) { mTestcampaignListComponents[i].addMouseListener(testcampaignMouseListener); } metaCampaignComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { MetaCampaignFile currentSelectedCampaign = (MetaCampaignFile) metaCampaignComboBox .getSelectedItem(); if (currentSelectedCampaign != selectedCampaign) { selectedCampaign = currentSelectedCampaign; if (selectedCampaign != null) { treeTable.removeAll(); if (new File(selectedCampaign.getFileName()).exists()) { treeTable.load(selectedCampaign.getFileName()); } GUIConfiguration guiConfiguration = GUIConfiguration.getInstance(); guiConfiguration.setProperty(LAST_SELECTED_CAMPAIGN_PROPERTY, selectedCampaign.getCampaignName()); try { guiConfiguration.save(); } catch (ConfigurationException ex) { logger.error("Error while saving GUI configuration: " + ex.getMessage(), ex); } } else { treeTable.removeAll(); } } } }); boolean setLastSelectedCampaign = false; if (lastSelectedCampaign != null) { // select last selected campaign for (int i = 0; i < campaigns.length; i++) { if (campaigns[i].getCampaignName().equals(lastSelectedCampaign)) { metaCampaignComboBox.setSelectedIndex(i); setLastSelectedCampaign = true; break; } } } if (!setLastSelectedCampaign && metaCampaignComboBox.getItemCount() > 0) { metaCampaignComboBox.setSelectedIndex(0); } runMetaCampaignButton.setIcon(ResourceManager.getInstance().getImageIcon("icons/running_32")); runMetaCampaignButton.setToolTipText("Run campaign"); runMetaCampaignButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { if (selectedCampaign == null) { logger.warn("No Campaign created"); return; } // first save the current campaign if needed if (treeTable.hasChanged()) { treeTable.save(selectedCampaign.getFileName(), selectedCampaign.getCampaignName()); } // set SUT version TestBedConfiguration.setSUTVersion(parent.getSUTVersion()); testExecutionHandler = new CampaignExecutionThread(selectedCampaign.getFileName()); Thread t = new Thread(testExecutionHandler); t.start(); // set the window to test result // TO DO } catch (Exception ex) { // logger.error(ex.getMessage(), ex); } } }); builder.add(addNewMetaCampaignButton, cc.xy(colIndex, 2)); colIndex += 2; builder.add(saveMetaCampaignButton, cc.xy(colIndex, 2)); colIndex += 2; builder.add(runMetaCampaignButton, cc.xy(colIndex, 2)); colIndex += 2; JScrollPane sp = new JScrollPane(treeTable); this.add(builder.getPanel(), BorderLayout.NORTH); this.add(sp); }
From source file:com.sec.ose.osi.ui.ApplicationCloseMgr.java
public void run() { log.debug("run() start"); boolean loop = true; int queueSize = IdentifyQueue.getInstance().size(); log.info("Trying to Sending item to Protex Server - Identify Queue Size: " + queueSize); long startTime = System.currentTimeMillis(); while (loop) { // block BackgroundJobManager.getInstance().requestStopIdentifyThread(); long endTime = System.currentTimeMillis(); long timeDuration = endTime - startTime; if (timeDuration % 100 == 0) System.out.println("delayTime : " + timeDuration); if (timeDuration >= TIME_LIMIT) { log.error("TIME_LIMIT_EXCEED during completing sending items to Protex server "); loop = false;/*from w w w . j ava2s. c o m*/ aDialogDiaplayerThread.closeDialog(); String exitMessage = "OSI fails to sync with Protex Server.\n" + "Please contact to OSI Development Team to resolve this problem."; String[] button = { "OK" }; JOptionPane.showOptionDialog( // block null, exitMessage, "Exit", JOptionPane.YES_OPTION, JOptionPane.QUESTION_MESSAGE, null, button, "OK"); continue; } else { boolean isAllidentifyThreadStopped = BackgroundJobManager.getInstance() .isAllIdentifyThreadReadyStatus(); if (isAllidentifyThreadStopped) { queueSize = IdentifyQueue.getInstance().size(); log.info("OSI succeeds to sync with Protex Server. - Identify Queue Size: " + queueSize + " / " + timeDuration + " ms."); loop = false; aDialogDiaplayerThread.closeDialog(); } } try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } log.debug("run() end"); }
From source file:edu.ku.brc.specify.tasks.InteractionsProcessor.java
/** * Asks where the source of the Loan Preps should come from. * @return the source enum//w w w . ja va 2 s. c o m */ protected ASK_TYPE askSourceOfPreps(final boolean hasInfoReqs, final boolean hasColObjRS, final T currPrepProvider) { String label; if (hasInfoReqs && hasColObjRS) { label = getResourceString("NEW_INTER_USE_RS_IR"); } else if (hasInfoReqs) { label = getResourceString("NEW_INTER_USE_IR"); } else { label = getResourceString("NEW_INTER_USE_RS"); } boolean isForAcc = isFor == forAcc; Object[] options = new Object[!isForAcc || (isForAcc && ((!hasInfoReqs && !hasColObjRS) || currPrepProvider != null)) ? 2 : 3]; Integer dosOpt = null; Integer rsOpt = null; Integer noneOpt = null; if (!isForAcc || currPrepProvider != null) { options[0] = label; options[1] = getResourceString("NEW_INTER_ENTER_CATNUM"); rsOpt = JOptionPane.YES_OPTION; dosOpt = JOptionPane.NO_OPTION; } else { if (options.length == 2) { options[0] = getResourceString("NEW_INTER_ENTER_CATNUM"); options[1] = getResourceString("NEW_INTER_EMPTY"); dosOpt = JOptionPane.YES_OPTION; noneOpt = JOptionPane.NO_OPTION; } else { options[0] = label; options[1] = getResourceString("NEW_INTER_ENTER_CATNUM"); options[2] = getResourceString("NEW_INTER_EMPTY"); rsOpt = JOptionPane.YES_OPTION; dosOpt = JOptionPane.NO_OPTION; noneOpt = JOptionPane.CANCEL_OPTION; } } int userChoice = JOptionPane.showOptionDialog(UIRegistry.getTopWindow(), getResourceString("NEW_INTER_CHOOSE_RSOPT"), getResourceString("NEW_INTER_CHOOSE_RSOPT_TITLE"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (userChoice == dosOpt) { return ASK_TYPE.EnterDataObjs; } else if (rsOpt != null && userChoice == rsOpt) { return ASK_TYPE.ChooseRS; } else if (noneOpt != null && userChoice == noneOpt) { return ASK_TYPE.None; } return ASK_TYPE.Cancel; }
From source file:calendarexportplugin.exporter.GoogleExporter.java
public boolean exportPrograms(Program[] programs, CalendarExportSettings settings, AbstractPluginProgramFormating formatting) { try {//from w w w. j a va2s. c o m boolean uploadedItems = false; mPassword = IOUtilities.xorDecode(settings.getExporterProperty(PASSWORD), 345903).trim(); if (!settings.getExporterProperty(STORE_PASSWORD, false)) { if (!showLoginDialog(settings)) { return false; } } if (!settings.getExporterProperty(STORE_SETTINGS, false)) { if (!showCalendarSettings(settings)) { return false; } } GoogleService myService = new GoogleService("cl", "tvbrowser-tvbrowsercalenderplugin-" + CalendarExportPlugin.getInstance().getInfo().getVersion().toString()); myService.setUserCredentials(settings.getExporterProperty(USERNAME).trim(), mPassword); URL postUrl = new URL("http://www.google.com/calendar/feeds/" + settings.getExporterProperty(SELECTED_CALENDAR) + "/private/full"); SimpleDateFormat formatDay = new SimpleDateFormat("yyyy-MM-dd"); formatDay.setTimeZone(TimeZone.getTimeZone("GMT")); SimpleDateFormat formatTime = new SimpleDateFormat("HH:mm:ss"); formatTime.setTimeZone(TimeZone.getTimeZone("GMT")); ParamParser parser = new ParamParser(); for (Program program : programs) { final String title = parser.analyse(formatting.getTitleValue(), program); // First step: search for event in calendar boolean createEvent = true; CalendarEventEntry entry = findEntryForProgram(myService, postUrl, title, program); if (entry != null) { int ret = JOptionPane.showConfirmDialog(null, mLocalizer.msg("alreadyAvailable", "already available", program.getTitle()), mLocalizer.msg("title", "Add event?"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (ret != JOptionPane.YES_OPTION) { createEvent = false; } } // add event to calendar if (createEvent) { EventEntry myEntry = new EventEntry(); myEntry.setTitle(new PlainTextConstruct(title)); String desc = parser.analyse(formatting.getContentValue(), program); myEntry.setContent(new PlainTextConstruct(desc)); Calendar c = CalendarToolbox.getStartAsCalendar(program); DateTime startTime = new DateTime(c.getTime(), c.getTimeZone()); c = CalendarToolbox.getEndAsCalendar(program); DateTime endTime = new DateTime(c.getTime(), c.getTimeZone()); When eventTimes = new When(); eventTimes.setStartTime(startTime); eventTimes.setEndTime(endTime); myEntry.addTime(eventTimes); if (settings.getExporterProperty(REMINDER, false)) { int reminderMinutes = 0; try { reminderMinutes = settings.getExporterProperty(REMINDER_MINUTES, 0); } catch (NumberFormatException e) { e.printStackTrace(); } if (settings.getExporterProperty(REMINDER_ALERT, false)) { addReminder(myEntry, reminderMinutes, Reminder.Method.ALERT); } if (settings.getExporterProperty(REMINDER_EMAIL, false)) { addReminder(myEntry, reminderMinutes, Reminder.Method.EMAIL); } if (settings.getExporterProperty(REMINDER_SMS, false)) { addReminder(myEntry, reminderMinutes, Reminder.Method.SMS); } } if (settings.isShowBusy()) { myEntry.setTransparency(BaseEventEntry.Transparency.OPAQUE); } else { myEntry.setTransparency(BaseEventEntry.Transparency.TRANSPARENT); } // Send the request and receive the response: myService.insert(postUrl, myEntry); uploadedItems = true; } } if (uploadedItems) { JOptionPane.showMessageDialog(CalendarExportPlugin.getInstance().getBestParentFrame(), mLocalizer.msg("exportDone", "Google Export done."), mLocalizer.msg("export", "Export"), JOptionPane.INFORMATION_MESSAGE); } return true; } catch (AuthenticationException e) { ErrorHandler.handle(mLocalizer.msg("loginFailure", "Problems during login to Service.\nMaybe bad username or password?"), e); settings.setExporterProperty(STORE_PASSWORD, false); } catch (Exception e) { ErrorHandler.handle(mLocalizer.msg("commError", "Error while communicating with Google!"), e); } return false; }
From source file:gdt.jgui.entity.JEntityStructurePanel.java
/** * The default constructor./* w ww .j av a 2 s . c o m*/ */ public JEntityStructurePanel() { setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); scrollPane = new JScrollPane(); add(scrollPane); popup = new JPopupMenu(); popup.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { popup.removeAll(); JMenuItem facetsItem = new JMenuItem("Facets"); popup.add(facetsItem); facetsItem.setHorizontalTextPosition(JMenuItem.RIGHT); facetsItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // System.out.println("EntityStructurePanel:renderer:component locator$="+nodeLocator$); JEntityFacetPanel efp = new JEntityFacetPanel(); String efpLocator$ = efp.getLocator(); Properties locator = Locator.toProperties(selection$); String entihome$ = locator.getProperty(Entigrator.ENTIHOME); String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY); efpLocator$ = Locator.append(efpLocator$, Entigrator.ENTIHOME, entihome$); efpLocator$ = Locator.append(efpLocator$, EntityHandler.ENTITY_KEY, entityKey$); JConsoleHandler.execute(console, efpLocator$); } }); JMenuItem copyItem = new JMenuItem("Copy"); popup.add(copyItem); copyItem.setHorizontalTextPosition(JMenuItem.RIGHT); copyItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { console.clipboard.clear(); String locator$ = (String) node.getUserObject(); if (locator$ != null) console.clipboard.putString(locator$); } }); if (!isFirst) { popup.addSeparator(); JMenuItem excludeItem = new JMenuItem("Exclude"); popup.add(excludeItem); excludeItem.setHorizontalTextPosition(JMenuItem.RIGHT); excludeItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Exclude ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { try { Properties locator = Locator.toProperties(selection$); String entihome$ = locator.getProperty(Entigrator.ENTIHOME); String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY); Entigrator entigrator = console.getEntigrator(entihome$); Sack component = entigrator.getEntityAtKey(entityKey$); String[] sa = entigrator.ent_listContainers(component); if (sa != null) { Sack container; for (String aSa : sa) { container = entigrator.getEntityAtKey(aSa); if (container != null) entigrator.col_breakRelation(container, component); } } JConsoleHandler.execute(console, JEntityStructurePanel.this.locator$); } catch (Exception ee) { Logger.getLogger(JEntityStructurePanel.class.getName()).info(ee.toString()); } } } }); JMenuItem deleteItem = new JMenuItem("Delete"); popup.add(deleteItem); deleteItem.setHorizontalTextPosition(JMenuItem.RIGHT); deleteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Delete ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { try { Properties locator = Locator.toProperties(selection$); String entihome$ = locator.getProperty(Entigrator.ENTIHOME); String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY); Entigrator entigrator = console.getEntigrator(entihome$); Sack component = entigrator.getEntityAtKey(entityKey$); entigrator.deleteEntity(component); JConsoleHandler.execute(console, JEntityStructurePanel.this.locator$); } catch (Exception ee) { Logger.getLogger(JEntityStructurePanel.class.getName()).info(ee.toString()); } } } }); } if (hasToInclude()) { popup.addSeparator(); JMenuItem includeItem = new JMenuItem("Include"); popup.add(includeItem); includeItem.setHorizontalTextPosition(JMenuItem.RIGHT); includeItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { include(); JConsoleHandler.execute(console, JEntityStructurePanel.this.locator$); } }); } } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { } @Override public void popupMenuCanceled(PopupMenuEvent e) { // TODO Auto-generated method stub } }); }
From source file:ca.uviccscu.lp.server.main.ShutdownListener.java
@Override public void windowClosing(WindowEvent e) { if (Shared.hashInProgress) { JOptionPane.showMessageDialog(null, "Closing not allowed - stop or finish hashing first!", "Hash in progress!", JOptionPane.WARNING_MESSAGE); } else {/*w ww . ja v a 2 s . co m*/ SwingWorker worker = new SwingWorker<Void, Void>() { @Override public Void doInBackground() { try { int ans1 = JOptionPane.showConfirmDialog(null, "Are you sure you want to shutdown? " + "Clients will switch to passive mode until restarted.", "Confirmation", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (ans1 == JOptionPane.OK_OPTION) { l.debug("MainFrame window closing requested"); MainFrame.lockInterface(); MainFrame.setReportingActive(); MainFrame.updateTask("Shutting down", true); MainFrame.updateProgressBar(0, 0, 0, "Shutting down settings manager!", true, true); l.trace("Shutting down settings manager and saving session"); int ans2 = JOptionPane.showConfirmDialog(null, "Do you want to save the games list", "Save confirmation", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (ans2 == JOptionPane.OK_OPTION) { SettingsManager.showSaveSettingsDialog(); } SettingsManager.shutdown(); l.trace("OK"); l.trace("Stopping net manager"); MainFrame.updateProgressBar(0, 0, 0, "Shutting down net manager!", true, true); ServerNetManager.shutdown(); l.trace("OK"); l.trace("Shutting down tracker manager - might have errors here!"); MainFrame.updateProgressBar(0, 0, 0, "Shutting down azureus - might take a while!", true, true); //Errors due to Azureus stupid shutdown thread killing routine(see AzureusCoreImpl) //Basically it kills all other threads it doesnt recognise on JVM and then terminates //Not designed to work with other application, and so it also kills the shutdown thread = BAD //Library modified to prevent system shutdown, but exceptions still coming - irrelevant TrackerManager.shutdown(); Thread.yield(); l.trace("OK"); Thread.yield(); Thread.sleep(5000); while (!Shared.azShutdownDone) { try { l.trace("Awaiting az shutdown"); Thread.sleep(500); } catch (InterruptedException ex) { l.error("Az shutdown monitor interrupted", ex); } } MainFrame.updateProgressBar(0, 0, 0, "Cleaning temporary files - might take a while!", true, true); File f = new File(Shared.workingDirectory); /* //delete until files unlocked or timeout if (!deleteFolder(f, true, 3000, 15000)) { l.trace("Advanced file deletion measures required"); releaseLocks(); deleteFolder(f, false, 0, 0); //Advanced thread killing, stolen from azureus...except now it kills itself l.error("Delete timeout - attempting threadicide"); l.trace("Starting thread killing"); //First kill azureus SM - allows to do whatever we want with threads l.trace("Removed SM"); System.setSecurityManager(null); // ThreadGroup tg = Thread.currentThread().getThreadGroup(); while (tg.getParent() != null) { tg = tg.getParent(); } Thread[] threads = new Thread[tg.activeCount() + 1024]; tg.enumerate(threads, true); //VERY BAD WAY TO STOP THREAD BUT NO CHOICE - need to release the file locks for (int i = 0; i < threads.length; i++) { Thread th = threads[i]; if (th != null && th != Thread.currentThread() && AEThread2.isOurThread(th)) { l.trace("Stopping " + th.getName()); try { th.stop(); l.trace("ok"); } catch (SecurityException e) { l.trace("Stop vetoed by SM", e); } } } // deleteFolder(f, false, 0, 0); l.error("Trying to stop more threads, list:"); //List remaining threads ThreadGroup tg2 = Thread.currentThread().getThreadGroup(); while (tg2.getParent() != null) { tg2 = tg2.getParent(); } //Object o = new Object(); //o.notifyAll(); Thread[] threads2 = new Thread[tg2.activeCount() + 1024]; tg2.enumerate(threads2, true); //VERY BAD WAY TO STOP THREAD BUT NO CHOICE - need to release the file locks for (int i = 0; i < threads2.length; i++) { Thread th = threads2[i]; if (th != null) { l.trace("Have thread: " + th.getName()); if (th != null && th != Thread.currentThread() && (AEThread2.isOurThread(th) || isAzThread(th))) { l.trace("Stopping " + th.getName()); try { th.stop(); l.trace("ok"); } catch (SecurityException e) { l.trace("Stop vetoed by SM", e); } } } } try { Utils.cleanupDir(); l.trace("OK"); } catch (IOException e) { l.trace("Cleaning failed after more thread cleanup", e); Thread.yield(); } threadCleanup(f); l.error("Last resort - scheduling delete on JVM exit - might FAIL, CHECK MANUALLY"); try { FileUtils.forceDeleteOnExit(f); } catch (IOException iOException) { l.fatal("All delete attempts failed - clean manually"); } } File test = new File("C:\\AZTest\\AZ\\logs\\debug_1.log"); test.deleteOnExit(); try { Thread.sleep(30000); } catch (InterruptedException ex) { java.util.logging.Logger.getLogger(ShutdownListener.class.getName()).log(Level.SEVERE, null, ex); } * */ threadReadout(); try { Utils.cleanupDir(); l.trace("OK"); } catch (IOException e) { l.trace("Cleaning failed - expected due to stupid Azureus file lock", e); Thread.yield(); } System.exit(0); return null; } else { return null; } } catch (Exception ex) { l.fatal("Exception during shutdown!!!", ex); //just end it System.exit(4); return null; } } }; worker.execute(); } }
From source file:de.ipk_gatersleben.ag_nw.graffiti.plugins.gui.webstart.KgmlEdMain.java
/** * Constructs a new instance of the editor. *///from w ww . ja va2s. co m public KgmlEdMain(final boolean showMainFrame, String applicationName, String[] args) { // URL config, final ThreadSafeOptions tso = new ThreadSafeOptions(); SplashScreenInterface splashScreen = new DBEsplashScreen(applicationName, "", new Runnable() { public void run() { if (showMainFrame) { ClassLoader cl = this.getClass().getClassLoader(); String path = this.getClass().getPackage().getName().replace('.', '/'); ImageIcon icon = new ImageIcon(cl.getResource(path + "/ipklogo16x16_5.png")); final MainFrame mainFrame = MainFrame.getInstance(); mainFrame.setIconImage(icon.getImage()); Thread t = new Thread(new Runnable() { public void run() { long waitTime = 0; long start = System.currentTimeMillis(); do { if (ErrorMsg.getAppLoadingStatus() == ApplicationStatus.ADDONS_LOADED) break; try { Thread.sleep(50); } catch (InterruptedException e) { } waitTime = System.currentTimeMillis() - start; } while (waitTime < 2000); SplashScreenInterface ss = (SplashScreenInterface) tso.getParam(0, null); ss.setVisible(false); mainFrame.setVisible(true); } }, "wait for add-on initialization"); t.start(); } } }); tso.setParam(0, splashScreen); ClassLoader cl = this.getClass().getClassLoader(); String path = this.getClass().getPackage().getName().replace('.', '/'); ImageIcon icon = new ImageIcon(cl.getResource(path + "/ipklogo16x16_5.png")); ((DBEsplashScreen) splashScreen).setIconImage(icon.getImage()); splashScreen.setVisible(true); GravistoMainHelper.createApplicationSettingsFolder(splashScreen); if (!(new File(ReleaseInfo.getAppFolderWithFinalSep() + "license_kegg_accepted")).exists() && !(new File(ReleaseInfo.getAppFolderWithFinalSep() + "license_kegg_rejected")).exists()) { ReleaseInfo.setIsFirstRun(true); splashScreen.setVisible(false); splashScreen.setText("Request KEGG License Status"); JOptionPane.showMessageDialog(null, "<html><h3>KEGG License Status Evaluation</h3>" + "While " + DBEgravistoHelper.DBE_GRAVISTO_VERSION + " is available as a academic research tool at no cost to commercial and non-commercial users, for using<br>" + "KEGG related functions, it is necessary for all users to adhere to the KEGG license.<br>" + "For using " + DBEgravistoHelper.DBE_GRAVISTO_VERSION + " you need also be aware of information about licenses and conditions for<br>" + "usage, listed at the program info dialog and the " + DBEgravistoHelper.DBE_GRAVISTO_VERSION + " website (" + ReleaseInfo.getAppWebURL() + ").<br><br>" + DBEgravistoHelper.DBE_GRAVISTO_VERSION + " does not distribute information from KEGG but contains functionality for the online-access to information from KEGG wesite.<br><br>" + "<b>Before these functions are available to you, you should carefully read the following license information<br>" + "and decide if it is legit for you to use the KEGG related program functions. If you choose not to use the KEGG functions<br>" + "all other features of this application are still available and fully working.", DBEgravistoHelper.DBE_GRAVISTO_VERSION + " Program Features Initialization", JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(null, "<html><h3>KEGG License Status Evaluation</h3>" + MenuItemInfoDialog.getKEGGlibText(), DBEgravistoHelper.DBE_GRAVISTO_VERSION + " Program Features Initialization", JOptionPane.INFORMATION_MESSAGE); int result = JOptionPane.showConfirmDialog(null, "<html><h3>Enable KEGG functions?", DBEgravistoHelper.DBE_GRAVISTO_VERSION + " Program Features Initialization", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result == JOptionPane.YES_OPTION) { try { new File(ReleaseInfo.getAppFolderWithFinalSep() + "license_kegg_accepted").createNewFile(); } catch (IOException e) { ErrorMsg.addErrorMessage(e); } } if (result == JOptionPane.NO_OPTION) { try { new File(ReleaseInfo.getAppFolderWithFinalSep() + "license_kegg_rejected").createNewFile(); } catch (IOException e) { ErrorMsg.addErrorMessage(e); } } if (result == JOptionPane.CANCEL_OPTION) { JOptionPane.showMessageDialog(null, "Startup aborted.", DBEgravistoHelper.DBE_GRAVISTO_VERSION + " Program Features Initialization", JOptionPane.INFORMATION_MESSAGE); System.exit(0); } splashScreen.setVisible(true); } GravistoMainHelper.initApplicationExt(args, splashScreen, cl, null, null); }
From source file:me.ryandowling.allmightybot.AllmightyBot.java
public AllmightyBot() { if (Files.exists(Utils.getSettingsFile())) { try {/* ww w. j a v a 2 s . co m*/ this.settings = GSON.fromJson(FileUtils.readFileToString(Utils.getSettingsFile().toFile()), Settings.class); } catch (IOException e) { e.printStackTrace(); } } else { this.settings = new Settings(); } if (!this.settings.hasInitialSetupBeenCompleted()) { String input = null; input = JOptionPane.showInputDialog(null, "Please enter the username of the Twitch user " + "to act " + "as the bot", "Twitch Username", JOptionPane.QUESTION_MESSAGE); if (input == null) { logger.error("Failed to input proper things when setting up! Do it properly next time!"); System.exit(0); } settings.setTwitchUsername(input); input = JOptionPane.showInputDialog(null, "Please enter the IRC oauth token of the Twitch user " + "acting as the bot", "Twitch Token", JOptionPane.QUESTION_MESSAGE); if (input == null) { logger.error("Failed to input proper things when setting up! Do it properly next time!"); System.exit(0); } settings.setTwitchToken(input); input = JOptionPane.showInputDialog(null, "Please enter the API token of the Twitch user " + "acting " + "as the bot", "Twitch API Token", JOptionPane.QUESTION_MESSAGE); if (input == null) { logger.error("Failed to input proper things when setting up! Do it properly next time!"); System.exit(0); } settings.setTwitchApiToken(input); input = JOptionPane.showInputDialog(null, "Please enter the API client ID of the application using " + "the Twitch API", "Twitch API Client ID", JOptionPane.QUESTION_MESSAGE); if (input == null) { logger.error("Failed to input proper things when setting up! Do it properly next time!"); System.exit(0); } settings.setTwitchApiClientID(input); input = JOptionPane.showInputDialog(null, "Please enter the username of the Twitch user whose " + "channel you wish to join! Must be in all lowercase", "User To Join", JOptionPane.QUESTION_MESSAGE); if (input == null) { logger.error("Failed to input proper things when setting up! Do it properly next time!"); System.exit(0); } settings.setTwitchChannel(input); input = JOptionPane.showInputDialog(null, "Please enter the name of the caster to display when " + "referencing them", "Casters Name", JOptionPane.QUESTION_MESSAGE); if (input == null) { logger.error("Failed to input proper things when setting up! Do it properly next time!"); System.exit(0); } settings.setCastersName(input); input = JOptionPane.showInputDialog(null, "How often do you want to run the timed messages (in " + "minutes)?", "Timed Messages", JOptionPane.QUESTION_MESSAGE); try { settings.setTimedMessagesInterval(Integer.parseInt(input) * 60); } catch (NumberFormatException e) { input = null; } input = JOptionPane.showInputDialog(null, "How long do you want to time people out for when they post " + "links after 1 warning (in minutes)?", "Spam Timeouts", JOptionPane.QUESTION_MESSAGE); try { settings.setLinkTimeoutLength1(Integer.parseInt(input) * 60); } catch (NumberFormatException e) { input = null; } input = JOptionPane.showInputDialog(null, "How long do you want to time people out for when they post " + "links after 2 and more warnings (in minutes)?", "Spam Timeouts", JOptionPane.QUESTION_MESSAGE); try { settings.setLinkTimeoutLength2(Integer.parseInt(input) * 60); } catch (NumberFormatException e) { input = null; } if (input == null) { logger.error("Failed to input proper things when setting up! Do it properly next time!"); System.exit(0); } int reply = JOptionPane.showConfirmDialog(null, "Do you want the bot to announce itself on join " + "(message " + "customisable in the lang.json file after startup)?", "Self Announce", JOptionPane.YES_NO_OPTION); if (reply != JOptionPane.YES_OPTION) { settings.setAnnounceOnJoin(false); } this.settings.initialSetupComplete(); this.firstTime = true; } }
From source file:VoteDialog.java
private JPanel createSimpleDialogBox() { final int numButtons = 4; JRadioButton[] radioButtons = new JRadioButton[numButtons]; final ButtonGroup group = new ButtonGroup(); JButton voteButton = null;// w w w .j av a 2 s.c o m final String defaultMessageCommand = "default"; final String yesNoCommand = "yesno"; final String yeahNahCommand = "yeahnah"; final String yncCommand = "ync"; radioButtons[0] = new JRadioButton("<html>Candidate 1: <font color=red>Sparky the Dog</font></html>"); radioButtons[0].setActionCommand(defaultMessageCommand); radioButtons[1] = new JRadioButton("<html>Candidate 2: <font color=green>Shady Sadie</font></html>"); radioButtons[1].setActionCommand(yesNoCommand); radioButtons[2] = new JRadioButton("<html>Candidate 3: <font color=blue>R.I.P. McDaniels</font></html>"); radioButtons[2].setActionCommand(yeahNahCommand); radioButtons[3] = new JRadioButton( "<html>Candidate 4: <font color=maroon>Duke the Java<font size=-2><sup>TM</sup></font size> Platform Mascot</font></html>"); radioButtons[3].setActionCommand(yncCommand); for (int i = 0; i < numButtons; i++) { group.add(radioButtons[i]); } // Select the first button by default. radioButtons[0].setSelected(true); voteButton = new JButton("Vote"); voteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String command = group.getSelection().getActionCommand(); // ok dialog if (command == defaultMessageCommand) { JOptionPane.showMessageDialog(frame, "This candidate is a dog. Invalid vote."); // yes/no dialog } else if (command == yesNoCommand) { int n = JOptionPane.showConfirmDialog(frame, "This candidate is a convicted felon. \nDo you still want to vote for her?", "A Follow-up Question", JOptionPane.YES_NO_OPTION); if (n == JOptionPane.YES_OPTION) { setLabel("OK. Keep an eye on your wallet."); } else if (n == JOptionPane.NO_OPTION) { setLabel("Whew! Good choice."); } else { setLabel("It is your civic duty to cast your vote."); } // yes/no (with customized wording) } else if (command == yeahNahCommand) { Object[] options = { "Yes, please", "No, thanks" }; int n = JOptionPane.showOptionDialog(frame, "This candidate is deceased. \nDo you still want to vote for him?", "A Follow-up Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (n == JOptionPane.YES_OPTION) { setLabel("I hope you don't expect much from your candidate."); } else if (n == JOptionPane.NO_OPTION) { setLabel("Whew! Good choice."); } else { setLabel("It is your civic duty to cast your vote."); } // yes/no/cancel (with customized wording) } else if (command == yncCommand) { Object[] options = { "Yes!", "No, I'll pass", "Well, if I must" }; int n = JOptionPane.showOptionDialog(frame, "Duke is a cartoon mascot. \nDo you " + "still want to cast your vote?", "A Follow-up Question", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]); if (n == JOptionPane.YES_OPTION) { setLabel("Excellent choice."); } else if (n == JOptionPane.NO_OPTION) { setLabel("Whatever you say. It's your vote."); } else if (n == JOptionPane.CANCEL_OPTION) { setLabel("Well, I'm certainly not going to make you vote."); } else { setLabel("It is your civic duty to cast your vote."); } } return; } }); System.out.println("calling createPane"); return createPane(simpleDialogDesc + ":", radioButtons, voteButton); }