List of usage examples for javax.swing JOptionPane YES_NO_CANCEL_OPTION
int YES_NO_CANCEL_OPTION
To view the source code for javax.swing JOptionPane YES_NO_CANCEL_OPTION.
Click Source Link
showConfirmDialog
. From source file:se.trixon.jota.client.ui.MainFrame.java
public boolean requestStartJob(Job job) { try {/*from w w w .j a va 2 s.co m*/ JobValidator validator = mManager.getServerCommander().validate(job); if (validator.isValid()) { Object[] options = { Dict.RUN.toString(), Dict.DRY_RUN.toString(), Dict.CANCEL.toString() }; HtmlPanel htmlPanel = new HtmlPanel(job.getSummaryAsHtml()); SwingHelper.makeWindowResizable(htmlPanel); int result = JOptionPane.showOptionDialog(this, htmlPanel, Dict.RUN.toString(), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[1]); if (result > -1 && result < 2) { boolean dryRun = result == 1; mManager.getServerCommander().startJob(job, dryRun); } } else { Message.html(this, Dict.ERROR_VALIDATION.toString(), validator.getSummaryAsHtml()); } } catch (RemoteException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } return false; }
From source file:SeedGenerator.MainForm.java
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing boolean open = false; if (threadsSparql != null) { for (Thread t : threadsSparql) { try { if (((WorkerSparql) t).isAlive()) { open = true;//from w w w . j av a 2s . c o m } } catch (Exception ex) { } } } if (threadsSearchQueue != null) { for (Thread t : threadsSearchQueue) { try { if (((WorkerSearchQueue) t).isAlive()) { open = true; } } catch (Exception ex) { } } } if (threadsAnalysis != null) { for (Thread t : threadsAnalysis) { try { if (((WorkerAnalyze) t).isAlive()) { open = true; } } catch (Exception ex) { } } } if (open) { int safe = JOptionPane.showConfirmDialog(null, "Please close all threads before closing. Do you want to enforce closing?", "Warning", JOptionPane.YES_NO_CANCEL_OPTION); if (safe == JOptionPane.YES_OPTION) { setDefaultCloseOperation(DISPOSE_ON_CLOSE);//yes } else if (safe == JOptionPane.CANCEL_OPTION) { setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);//cancel } else { setDefaultCloseOperation(DISPOSE_ON_CLOSE);//no } } // TODO add your handling code here:// TODO add your handling code here: }
From source file:storybook.SbApp.java
public static void main(String[] args) { String tempDir = System.getProperty("java.io.tmpdir"); String fn = tempDir + File.separator + "storybook.lck"; if (args.length > 0) { for (int i = 0; i < args.length; i++) { if (args[i].equalsIgnoreCase("--trace")) { SbApp.bTrace = true;//w w w . j a v a 2 s. c o m System.out.println("Storybook execution in trace mode"); } if (args[i].equalsIgnoreCase("--hibernate")) { SbApp.bTraceHibernate = true; System.out.println("Hibernate in trace mode"); } if (args[i].equalsIgnoreCase("--dev")) { SbApp.bDevTest = true; System.out.println("Development test"); } if (args[i].equalsIgnoreCase("--msg")) { File f = new File(args[i + 1] + ".properties"); if (!f.exists()) { System.out.println("Msg test file not exists : " + args[i + 1]); } else { SbApp.i18nFile = args[i + 1]; System.out.println("Msg test file is : " + SbApp.i18nFile); } } } } if (!lockInstance(fn)) { Object[] options = { I18N.getMsg("msg.running.remove"), I18N.getMsg("msg.common.cancel") }; int n = JOptionPane.showOptionDialog(null, I18N.getMsg("msg.running.msg"), I18N.getMsg("msg.running.title"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); if (n == 0) { File file = new File(fn); if (file.exists() && file.canWrite()) { if (!file.delete()) { JOptionPane.showMessageDialog(null, "Delete failed", "File\n" + file.getAbsolutePath() + "\ncould not be deleted.", JOptionPane.ERROR_MESSAGE); } } } return; } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { SbApp app = SbApp.getInstance(); app.init(); } }); }
From source file:su.fmi.photoshareclient.ui.PhotoViewDialog.java
private void SaveImageButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_SaveImageButtonMouseClicked JFileChooser fileChooser = new JFileChooser() { // A warning for overweiting existing files @Override//from w w w. j av a2s . com public void approveSelection() { File f = getSelectedFile(); if (f.exists() && getDialogType() == SAVE_DIALOG) { int result = JOptionPane.showConfirmDialog(this, "The file exists, overwrite?", "Existing file", JOptionPane.YES_NO_CANCEL_OPTION); switch (result) { case JOptionPane.YES_OPTION: super.approveSelection(); return; case JOptionPane.NO_OPTION: return; case JOptionPane.CLOSED_OPTION: return; case JOptionPane.CANCEL_OPTION: cancelSelection(); return; } } super.approveSelection(); } }; fileChooser.setDialogTitle("Save image as..."); File rootVolume = File.listRoots()[0]; fileChooser.setSelectedFile(new File(rootVolume.getAbsolutePath(), this.imageLabel.getFileName())); int userSelection = fileChooser.showSaveDialog(this); if (userSelection == JFileChooser.APPROVE_OPTION) { try { File fileToSave = fileChooser.getSelectedFile(); BufferedImage bi = (BufferedImage) this.imageLabel.getImage(); String ext = FilenameUtils.getExtension(fileToSave.getAbsolutePath()); ImageIO.write(bi, ext, fileToSave); } catch (IOException ex) { Logger.getLogger(PhotoViewDialog.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:tauargus.gui.PanelTable.java
private void buttonSuppressActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSuppressActionPerformed JFrame parentFrame = getParentFrame(); SuppressionMethod Soort = SuppressionMethod.GHMITER; if (radioButtonHyperCube.isSelected()) Soort = SuppressionMethod.GHMITER; if (radioButtonModular.isSelected()) Soort = SuppressionMethod.HITAS; if (radioButtonOptimal.isSelected()) Soort = SuppressionMethod.OPTIMAL; if (radioButtonMarginal.isSelected()) Soort = SuppressionMethod.MARGINAL; if (radioButtonNetwork.isSelected()) Soort = SuppressionMethod.NETWORK; if (radioButtonUwe.isSelected()) Soort = SuppressionMethod.UWE;/*from w w w . ja va 2 s .c om*/ if (radioButtonCta.isSelected()) Soort = SuppressionMethod.CTA; if (radioButtonRounding.isSelected()) Soort = SuppressionMethod.ROUNDING; if (Soort.isAdditivityDesirable() && !tableSet.isAdditive) { if (JOptionPane.NO_OPTION == JOptionPane.showConfirmDialog(this, "Table is not additive. Optimisation routines might be tricky\nDo you want to proceed?", "Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE)) { return; } } if (Soort.isUsingSuppliedCostFunction()) { if (tableSet.costFunc == TableSet.COST_DIST && !Soort.canUseDistanceFunction()) { JOptionPane.showMessageDialog(null, "Distance function is not available for this solution"); return; } } CellStatusStatistics statistics = tableSet.getCellStatusStatistics(); if (statistics == null) { return; // TODO Show message } int totalUnsafeCells = statistics.totalPrimaryUnsafe(); if (!Soort.isCosmetic()) { if (totalUnsafeCells == 0) { JOptionPane.showMessageDialog(this, "No unsafe cells found\nNo protection required"); return; } } if (Soort == SuppressionMethod.OPTIMAL && totalUnsafeCells > 50) { if (JOptionPane.NO_OPTION == JOptionPane.showConfirmDialog(this, "This tabel contains " + totalUnsafeCells + " unsafe cells\nthis might take a long time; do you want to proceed?", "Question", JOptionPane.YES_NO_OPTION)) { return; } } if (Soort.isMinMaxTableValueNeeded()) { if (!VraagMinTabVal(Soort, tableSet)) { return; } } switch (Soort) { case ROUNDING: if (Application.solverSelected == Application.SOLVER_CPLEX) { JOptionPane.showMessageDialog(null, "Whether controlled rounding can be used when Cplex is selected as solver, depends on your specific license", "", JOptionPane.ERROR_MESSAGE); } //else DialogRoundingParameters paramsR = new DialogRoundingParameters(parentFrame, true); if (paramsR.showDialog(tableSet) == DialogRoundingParameters.APPROVE_OPTION) { final SwingWorker<Integer, Void> worker = new ProgressSwingWorker<Integer, Void>( ProgressSwingWorker.ROUNDER, "Rounding") { @Override protected Integer doInBackground() throws ArgusException, Exception { super.doInBackground(); OptiSuppress.runRounder(tableSet, getPropertyChangeListener()); return null; } @Override protected void done() { super.done(); try { get(); JOptionPane.showMessageDialog(null, "The table has been rounded\n" + "Number of steps: " + tableSet.roundMaxStep + "\n" + "Max step: " + StrUtils.formatDouble(tableSet.roundMaxJump, tableSet.respVar.nDecimals) + "\n" + "Processing time: " + StrUtils.timeToString(tableSet.processingTime)); ((AbstractTableModel) table.getModel()).fireTableDataChanged(); adjustColumnWidths(); updateSuppressButtons(); } catch (InterruptedException ex) { logger.log(Level.SEVERE, null, ex); } catch (ExecutionException ex) { JOptionPane.showMessageDialog(null, ex.getCause().getMessage()); } } }; worker.execute(); /* try{ OptiSuppress.runRounder(tableSet); JOptionPane.showMessageDialog(null, "The table has been rounded\n" + "Number of steps: " + tableSet.roundMaxStep+"\n"+ "Max step: " + StrUtils.formatDouble(tableSet.roundMaxJump, tableSet.respVar.nDecimals) +"\n"+ "Processing time: " + StrUtils.timeToString(tableSet.processingTime)); ((AbstractTableModel)table.getModel()).fireTableDataChanged(); adjustColumnWidths(); updateSuppressButtons(); } // Anco 1.6 // catch (ArgusException | IOException ex) { catch (ArgusException ex) { JOptionPane.showMessageDialog(this, ex.getMessage());} catch (IOException ex) { JOptionPane.showMessageDialog(this, ex.getMessage()); }*/ } break; case CTA: //do CTA final int i = JOptionPane.showConfirmDialog(parentFrame, "Do you prefer to use the expert version?", "Select CTA version", JOptionPane.YES_NO_CANCEL_OPTION); if ((i == JOptionPane.YES_OPTION) || (i == JOptionPane.NO_OPTION)) { new Thread() { @Override public void run() { try { OptiSuppress.RunCTA(tableSet, (i == JOptionPane.YES_OPTION)); JOptionPane.showMessageDialog(null, "The CTA procedure has been completed\n" + tableSet.nSecond + " cells have been modified\n" + StrUtils.timeToString(tableSet.processingTime) + " needed"); ((AbstractTableModel) table.getModel()).fireTableDataChanged(); adjustColumnWidths(); updateSuppressButtons(); } catch (ArgusException ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); } catch (FileNotFoundException ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); } catch (IOException ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); } } }.start(); } break; case UWE: DialogModularParameters uweParams = new DialogModularParameters(parentFrame, tableSet, false, true); if (uweParams.showDialog() == DialogModularParameters.APPROVE_OPTION) { new Thread() { @Override public void run() { try { OptiSuppress.runUWE(tableSet); JOptionPane.showMessageDialog(null, "The UWE procedure has finished the protection\n" + tableSet.nSecond + " cells have been suppressed\n" + StrUtils.timeToString(tableSet.processingTime) + " needed"); ((AbstractTableModel) table.getModel()).fireTableDataChanged(); adjustColumnWidths(); updateSuppressButtons(); } catch (ArgusException ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); } catch (IOException ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); } } }.start(); } break; case GHMITER: DialogHypercubeParameters paramsG = new DialogHypercubeParameters(parentFrame, true); if (paramsG.showDialog(tableSet) == DialogHypercubeParameters.APPROVE_OPTION) { new Thread() { @Override public void run() { try { GHMiter.RunGHMiter(tableSet); JOptionPane.showMessageDialog(null, "The Hypercube has finished the protection\n" + tableSet.nSecond + " cells have been suppressed\n" + tableSet.ghMiterMessage + StrUtils.timeToString(tableSet.processingTime) + " needed"); // tableSet.suppressed = TableSet.SUP_GHMITER; if (argus.utils.TauArgusUtils.ExistFile(Application.getTempFile("frozen.txt"))) { DialogInfo Info = new DialogInfo(getParentFrame(), true); Info.addLabel("Overview of the frozen cells"); try { Info.addTextFile(Application.getTempFile("frozen.txt")); } catch (ArgusException ex1) { } ; Info.setVisible(true); } ((AbstractTableModel) table.getModel()).fireTableDataChanged(); adjustColumnWidths(); updateSuppressButtons(); } catch (ArgusException ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); if (GHMiter.ShowProto002) { DialogInfo Info = new DialogInfo(getParentFrame(), true); Info.addLabel("Overview of the file PROTO002"); Info.setSize(1000, 500); Info.setLocationRelativeTo(null); try { Info.addTextFile(Application.getTempFile("PROTO002")); } catch (ArgusException ex1) { } ; Info.setVisible(true); } } } }.start(); } // run hypercube method break; /* case HITAS: DialogModularParameters params = new DialogModularParameters(parentFrame, tableSet, false, true); params.showDialog(); try { boolean oke = OptiSuppress.runModular(tableSet); JOptionPane.showMessageDialog(this, "Modular has finished the protection\n" + tableSet.nSecond + " cells have been suppressed\n" + StrUtils.timeToString(tableSet.processingTime) + " needed"); } //|FileNotFoundException catch (ArgusException | IOException ex) { JOptionPane.showMessageDialog(this, ex.getMessage()); } break; */ case HITAS: DialogModularParameters params = new DialogModularParameters(parentFrame, tableSet, false, true); if (params.showDialog() == DialogModularParameters.APPROVE_OPTION) { final SwingWorker<Integer, Void> worker = new ProgressSwingWorker<Integer, Void>( ProgressSwingWorker.DOUBLE, "Modular approach") { @Override protected Integer doInBackground() throws ArgusException, Exception { super.doInBackground(); OptiSuppress.runModular(tableSet, getPropertyChangeListener()); return null; } @Override protected void done() { super.done(); try { get(); JOptionPane.showMessageDialog(null, "Modular has finished the protection\n" + tableSet.nSecond + " cells have been suppressed\n" + StrUtils.timeToString(tableSet.processingTime) + " needed"); tableSet.undoAudit(); ((AbstractTableModel) table.getModel()).fireTableDataChanged(); adjustColumnWidths(); updateSuppressButtons(); } catch (InterruptedException ex) { logger.log(Level.SEVERE, null, ex); } catch (ExecutionException ex) { JOptionPane.showMessageDialog(null, ex.getCause().getMessage()); } } }; worker.execute(); } break; case OPTIMAL: /* params = new DialogModularParameters(parentFrame, tableSet, true, true); params.showDialog(); try{ OptiSuppress.runOptimal(tableSet); JOptionPane.showMessageDialog(null, "Optimal has finished the protection\n" + tableSet.nSecond + " cells have been suppressed\n" + StrUtils.timeToString(tableSet.processingTime) + " needed"); tableSet.hasBeenAudited = false; } catch (ArgusException| IOException ex) {JOptionPane.showMessageDialog(this, ex.getMessage()); } // run optimal */ params = new DialogModularParameters(parentFrame, tableSet, true, true); if (params.showDialog() == DialogModularParameters.APPROVE_OPTION) { final SwingWorker<Void, Void> worker = new ProgressSwingWorker<Void, Void>( ProgressSwingWorker.VALUES, "Optimal approach") { // called in a separate thread... @Override protected Void doInBackground() throws ArgusException, Exception { super.doInBackground(); OptiSuppress.runOptimal(tableSet, getPropertyChangeListener(), checkBoxInverseWeight.isSelected(), false, 1); return null; } // called on the GUI thread @Override protected void done() { super.done(); try { get(); JOptionPane.showMessageDialog(null, "Optimal has finished the protection\n" + tableSet.nSecond + " cells have been suppressed\n" + StrUtils.timeToString(tableSet.processingTime) + " needed"); tableSet.undoAudit(); ((AbstractTableModel) table.getModel()).fireTableDataChanged(); adjustColumnWidths(); updateSuppressButtons(); } catch (InterruptedException ex) { logger.log(Level.SEVERE, null, ex); } catch (ExecutionException ex) { JOptionPane.showMessageDialog(null, ex.getCause().getMessage()); } } }; worker.execute(); } break; case NETWORK: try { OptiSuppress.TestNetwork(tableSet); } catch (ArgusException ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); break; } DialogNetwork paramsN = new DialogNetwork(parentFrame, true, tableSet); if (paramsN.showDialog() == DialogRoundingParameters.APPROVE_OPTION) { new Thread() { @Override public void run() { try { OptiSuppress.RunNetwork(tableSet); JOptionPane.showMessageDialog(null, "The network has finished the protection\n" + tableSet.nSecond + " cells have been suppressed\n" + StrUtils.timeToString(tableSet.processingTime) + " needed"); ((AbstractTableModel) table.getModel()).fireTableDataChanged(); adjustColumnWidths(); updateSuppressButtons(); } catch (ArgusException ex) { JOptionPane.showMessageDialog(null, ex.getMessage()); } } }.start(); } break; case MARGINAL: { JOptionPane.showMessageDialog(null, "The marginal method still has to be implemented"); } } //updateSuppressButtons(); // Needs to be at each try{} of "done"because it will not wait for finishing of ProcessSwingWorker // Suppress(tableIndex, false, Soort); tableSet.undoAudit(); // TODO Optimalisation: Only do this if a suppression method has run //((AbstractTableModel)table.getModel()).fireTableDataChanged(); //adjustColumnWidths(); }
From source file:test.uk.co.modularaudio.util.swing.dialog.TestUseDialogs.java
public void testUseYesNoQuestion() throws Exception { final YesNoQuestionDialog ynd = new YesNoQuestionDialog(); final YesNoQuestionDialogCallback testCallback = new YesNoQuestionDialogCallback() { @Override/*from w w w .j a va2 s . c om*/ public void receiveDialogResultValue(final int value) { log.debug("JUnit test received yes no callback with " + value); } }; final String[] options = new String[] { "YesOption", "NoOption", "CancelOption" }; final String defaultChoice = options[0]; ynd.setValues(null, "Some message", "Some title", JOptionPane.YES_NO_CANCEL_OPTION, options, defaultChoice, testCallback); ynd.go(); }
From source file:tk.tomby.tedit.actions.ExitAction.java
/** * DOCUMENT ME!/*from www . j av a2 s . c om*/ * * @param evt DOCUMENT ME! */ public void actionPerformed(ActionEvent evt) { for (IBuffer buffer : WorkspaceManager.getBufferList()) { if (buffer.isModified()) { if (log.isDebugEnabled()) { log.debug(buffer.getFileName() + "was modified"); } int retval = JOptionPane.showConfirmDialog(WorkspaceManager.getMainFrame(), ResourceManager.getProperty("main.savechanges.title"), buffer.getFileName(), JOptionPane.YES_NO_CANCEL_OPTION); switch (retval) { case JOptionPane.YES_OPTION: if (!buffer.isNew()) { buffer.save(); } else { JFileChooser chooser = new JFileChooser(); if (chooser .showSaveDialog(WorkspaceManager.getMainFrame()) == JFileChooser.APPROVE_OPTION) { buffer.saveAs(chooser.getSelectedFile()); } } break; case JOptionPane.NO_OPTION: break; default: return; } } } if (log.isDebugEnabled()) { log.debug("saving workspace"); } WorkspaceManager.save(); PluginManager.save(); if (log.isDebugEnabled()) { log.debug("exit from application"); } System.exit(0); }
From source file:tvbrowser.TVBrowser.java
/** * Entry point of the application/*from w ww.j a v a2s . c om*/ * @param args The arguments given in the command line. */ public static void main(String[] args) { // Read the command line parameters parseCommandline(args); try { Toolkit.getDefaultToolkit().setDynamicLayout( (Boolean) Toolkit.getDefaultToolkit().getDesktopProperty("awt.dynamicLayoutSupported")); } catch (Exception e) { e.printStackTrace(); } mLocalizer = util.ui.Localizer.getLocalizerFor(TVBrowser.class); // Check whether the TV-Browser was started in the right directory if (!new File("imgs").exists()) { String msg = "Please start TV-Browser in the TV-Browser directory!"; if (mLocalizer != null) { msg = mLocalizer.msg("error.2", "Please start TV-Browser in the TV-Browser directory!"); } JOptionPane.showMessageDialog(null, msg); System.exit(1); } if (mIsTransportable) { System.getProperties().remove("propertiesfile"); } // setup logging // Get the default Logger Logger mainLogger = Logger.getLogger(""); // Use a even simpler Formatter for console logging mainLogger.getHandlers()[0].setFormatter(createFormatter()); if (mIsTransportable) { File settingsDir = new File("settings"); try { File test = File.createTempFile("write", "test", settingsDir); test.delete(); } catch (IOException e) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e1) { //ignore } JTextArea area = new JTextArea(mLocalizer.msg("error.noWriteRightsText", "You are using the transportable version of TV-Browser but you have no writing rights in the settings directory:\n\n{0}'\n\nTV-Browser will be closed.", settingsDir.getAbsolutePath())); area.setFont(new JLabel().getFont()); area.setFont(area.getFont().deriveFont((float) 14).deriveFont(Font.BOLD)); area.setLineWrap(true); area.setWrapStyleWord(true); area.setPreferredSize(new Dimension(500, 100)); area.setEditable(false); area.setBorder(null); area.setOpaque(false); JOptionPane.showMessageDialog(null, area, mLocalizer.msg("error.noWriteRightsTitle", "No write rights in settings directory"), JOptionPane.ERROR_MESSAGE); System.exit(1); } } // Load the settings Settings.loadSettings(); Locale.setDefault(new Locale(Settings.propLanguage.getString(), Settings.propCountry.getString())); if (Settings.propFirstStartDate.getDate() == null) { Settings.propFirstStartDate.setDate(Date.getCurrentDate()); } if (!createLockFile()) { updateLookAndFeel(); showTVBrowserIsAlreadyRunningMessageBox(); } String logDirectory = Settings.propLogdirectory.getString(); if (logDirectory != null) { try { File logDir = new File(logDirectory); logDir.mkdirs(); mainLogger.addHandler( new FileLoggingHandler(logDir.getAbsolutePath() + "/tvbrowser.log", createFormatter())); } catch (IOException exc) { String msg = mLocalizer.msg("error.4", "Can't create log file."); ErrorHandler.handle(msg, exc); } } else { // if no logging is configured, show WARNING or worse for normal usage, show everything for unstable versions if (TVBrowser.isStable()) { mainLogger.setLevel(Level.WARNING); } } // log warning for OpenJDK users if (!isJavaImplementationSupported()) { mainLogger.warning(SUN_JAVA_WARNING); } //Update plugin on version change if (Settings.propTVBrowserVersion.getVersion() != null && VERSION.compareTo(Settings.propTVBrowserVersion.getVersion()) > 0) { updateLookAndFeel(); updatePluginsOnVersionChange(); } // Capture unhandled exceptions //System.setErr(new PrintStream(new MonitoringErrorStream())); String timezone = Settings.propTimezone.getString(); if (timezone != null) { TimeZone.setDefault(TimeZone.getTimeZone(timezone)); } mLog.info("Using timezone " + TimeZone.getDefault().getDisplayName()); // refresh the localizers because we know the language now Localizer.emptyLocalizerCache(); mLocalizer = Localizer.getLocalizerFor(TVBrowser.class); ProgramInfo.resetLocalizer(); ReminderPlugin.resetLocalizer(); Date.resetLocalizer(); ProgramFieldType.resetLocalizer(); // Set the proxy settings updateProxySettings(); // Set the String to use for indicating the user agent in http requests System.setProperty("http.agent", MAINWINDOW_TITLE); Version tmpVer = Settings.propTVBrowserVersion.getVersion(); final Version currentVersion = tmpVer != null ? new Version(tmpVer.getMajor(), tmpVer.getMinor(), Settings.propTVBrowserVersionIsStable.getBoolean()) : tmpVer; /*TODO Create an update service for installed TV data services that doesn't * work with TV-Browser 3.0 and updates for them are known. */ if (!isTransportable() && Launch.isOsWindowsNtBranch() && currentVersion != null && currentVersion.compareTo(new Version(3, 0, true)) < 0) { String tvDataDir = Settings.propTVDataDirectory.getString().replace("/", File.separator); if (!tvDataDir.startsWith(System.getenv("appdata"))) { StringBuilder oldDefaultTvDataDir = new StringBuilder(System.getProperty("user.home")) .append(File.separator).append("TV-Browser").append(File.separator).append("tvdata"); if (oldDefaultTvDataDir.toString().equals(tvDataDir)) { Settings.propTVDataDirectory.setString(Settings.propTVDataDirectory.getDefault()); } } } Settings.propTVBrowserVersion.setVersion(VERSION); Settings.propTVBrowserVersionIsStable.setBoolean(VERSION.isStable()); final Splash splash; if (mShowSplashScreen && Settings.propSplashShow.getBoolean()) { splash = new SplashScreen(Settings.propSplashImage.getString(), Settings.propSplashTextPosX.getInt(), Settings.propSplashTextPosY.getInt(), Settings.propSplashForegroundColor.getColor()); } else { splash = new DummySplash(); } splash.showSplash(); /* Initialize the MarkedProgramsList */ MarkedProgramsList.getInstance(); /*Maybe there are tvdataservices to install (.jar.inst files)*/ PluginLoader.getInstance().installPendingPlugins(); PluginLoader.getInstance().loadAllPlugins(); mLog.info("Loading TV listings service..."); splash.setMessage(mLocalizer.msg("splash.dataService", "Loading TV listings service...")); TvDataServiceProxyManager.getInstance().init(); ChannelList.createForTvBrowserStart(); ChannelList.initSubscribedChannels(); if (!lookAndFeelInitialized) { mLog.info("Loading Look&Feel..."); splash.setMessage(mLocalizer.msg("splash.laf", "Loading look and feel...")); updateLookAndFeel(); } mLog.info("Loading plugins..."); splash.setMessage(mLocalizer.msg("splash.plugins", "Loading plugins...")); try { PluginProxyManager.getInstance().init(); } catch (TvBrowserException exc) { ErrorHandler.handle(exc); } splash.setMessage(mLocalizer.msg("splash.tvData", "Checking TV database...")); mLog.info("Checking TV listings inventory..."); TvDataBase.getInstance().checkTvDataInventory(); mLog.info("Starting up..."); splash.setMessage(mLocalizer.msg("splash.ui", "Starting up...")); Toolkit.getDefaultToolkit().getSystemEventQueue().push(new TextComponentPopupEventQueue()); // Init the UI final boolean fStartMinimized = Settings.propMinimizeAfterStartup.getBoolean() || mMinimized; SwingUtilities.invokeLater(new Runnable() { public void run() { initUi(splash, fStartMinimized); new Thread("Start finished callbacks") { public void run() { setPriority(Thread.MIN_PRIORITY); mLog.info("Deleting expired TV listings..."); TvDataBase.getInstance().deleteExpiredFiles(1, false); // first reset "starting" flag of mainframe mainFrame.handleTvBrowserStartFinished(); // initialize program info for fast reaction to program table click ProgramInfo.getInstance().handleTvBrowserStartFinished(); // load reminders and favorites ReminderPlugin.getInstance().handleTvBrowserStartFinished(); FavoritesPlugin.getInstance().handleTvBrowserStartFinished(); // now handle all plugins and services GlobalPluginProgramFormatingManager.getInstance(); PluginProxyManager.getInstance().fireTvBrowserStartFinished(); TvDataServiceProxyManager.getInstance().fireTvBrowserStartFinished(); // finally submit plugin caused updates to database TvDataBase.getInstance().handleTvBrowserStartFinished(); startPeriodicSaveSettings(); } }.start(); SwingUtilities.invokeLater(new Runnable() { public void run() { ChannelList.completeChannelLoading(); initializeAutomaticDownload(); if (Launch.isOsWindowsNtBranch()) { try { RegistryKey desktopSettings = new RegistryKey(RootKey.HKEY_CURRENT_USER, "Control Panel\\Desktop"); RegistryValue autoEnd = desktopSettings.getValue("AutoEndTasks"); if (autoEnd.getData().equals("1")) { RegistryValue killWait = desktopSettings.getValue("WaitToKillAppTimeout"); int i = Integer.parseInt(killWait.getData().toString()); if (i < 5000) { JOptionPane pane = new JOptionPane(); String cancel = mLocalizer.msg("registryCancel", "Close TV-Browser"); String dontDoIt = mLocalizer.msg("registryJumpOver", "Not this time"); pane.setOptions(new String[] { Localizer.getLocalization(Localizer.I18N_OK), dontDoIt, cancel }); pane.setOptionType(JOptionPane.YES_NO_CANCEL_OPTION); pane.setMessageType(JOptionPane.WARNING_MESSAGE); pane.setMessage(mLocalizer.msg("registryWarning", "The fast shutdown of Windows is activated.\nThe timeout to wait for before Windows is closing an application is too short,\nto give TV-Browser enough time to save all settings.\n\nThe setting hasn't the default value. It was changed by a tool or by you.\nTV-Browser will now try to change the timeout.\n\nIf you don't want to change this timeout select 'Not this time' or 'Close TV-Browser'.")); pane.setInitialValue(mLocalizer.msg("registryCancel", "Close TV-Browser")); JDialog d = pane.createDialog(UiUtilities.getLastModalChildOf(mainFrame), UIManager.getString("OptionPane.messageDialogTitle")); d.setModal(true); UiUtilities.centerAndShow(d); if (pane.getValue() == null || pane.getValue().equals(cancel)) { mainFrame.quit(); } else if (!pane.getValue().equals(dontDoIt)) { try { killWait.setData("5000"); desktopSettings.setValue(killWait); JOptionPane.showMessageDialog( UiUtilities.getLastModalChildOf(mainFrame), mLocalizer.msg("registryChanged", "The timeout was changed successfully.\nPlease reboot Windows!")); } catch (Exception registySetting) { JOptionPane.showMessageDialog( UiUtilities.getLastModalChildOf(mainFrame), mLocalizer.msg("registryNotChanged", "<html>The Registry value couldn't be changed. Maybe you haven't the right to do it.<br>If it is so contact you Administrator and let him do it for you.<br><br><b><Attention:/b> The following description is for experts. If you change or delete the wrong value in the Registry you could destroy your Windows installation.<br><br>To get no warning on TV-Browser start the Registry value <b>WaitToKillAppTimeout</b> in the Registry path<br><b>HKEY_CURRENT_USER\\Control Panel\\Desktop</b> have to be at least <b>5000</b> or the value for <b>AutoEndTasks</b> in the same path have to be <b>0</b>.</html>"), Localizer.getLocalization(Localizer.I18N_ERROR), JOptionPane.ERROR_MESSAGE); } } } } } catch (Throwable registry) { } } if (currentVersion != null && currentVersion.compareTo(new Version(2, 71, false)) < 0) { if (Settings.propProgramPanelMarkedMinPriorityColor.getColor() .equals(Settings.propProgramPanelMarkedMinPriorityColor.getDefaultColor())) { Settings.propProgramPanelMarkedMinPriorityColor.setColor(new Color(255, 0, 0, 30)); } if (Settings.propProgramPanelMarkedMediumPriorityColor.getColor() .equals(Settings.propProgramPanelMarkedMediumPriorityColor.getDefaultColor())) { Settings.propProgramPanelMarkedMediumPriorityColor .setColor(new Color(140, 255, 0, 60)); } if (Settings.propProgramPanelMarkedHigherMediumPriorityColor.getColor().equals( Settings.propProgramPanelMarkedHigherMediumPriorityColor.getDefaultColor())) { Settings.propProgramPanelMarkedHigherMediumPriorityColor .setColor(new Color(255, 255, 0, 60)); } if (Settings.propProgramPanelMarkedMaxPriorityColor.getColor() .equals(Settings.propProgramPanelMarkedMaxPriorityColor.getDefaultColor())) { Settings.propProgramPanelMarkedMaxPriorityColor .setColor(new Color(255, 180, 0, 110)); } } // check if user should select picture settings if (currentVersion != null && currentVersion.compareTo(new Version(2, 22)) < 0) { TvBrowserPictureSettingsUpdateDialog.createAndShow(mainFrame); } else if (currentVersion != null && currentVersion.compareTo(new Version(2, 51, true)) < 0) { Settings.propAcceptedLicenseArrForServiceIds.setStringArray(new String[0]); } if (currentVersion != null && currentVersion.compareTo(new Version(2, 60, true)) < 0) { int startOfDay = Settings.propProgramTableStartOfDay.getInt(); int endOfDay = Settings.propProgramTableEndOfDay.getInt(); if (endOfDay - startOfDay < -1) { Settings.propProgramTableEndOfDay.setInt(startOfDay); JOptionPane.showMessageDialog(UiUtilities.getLastModalChildOf(mainFrame), mLocalizer.msg("timeInfoText", "The time range of the program table was corrected because the defined day was shorter than 24 hours.\n\nIf the program table should show less than 24h use a time filter for that. That time filter can be selected\nto be the default filter by selecting it in the filter settings and pressing on the button 'Default'."), mLocalizer.msg("timeInfoTitle", "Times corrected"), JOptionPane.INFORMATION_MESSAGE); Settings.handleChangedSettings(); } } MainFrame.getInstance().getProgramTableScrollPane().requestFocusInWindow(); } }); } }); // register the shutdown hook Runtime.getRuntime().addShutdownHook(new Thread("Shutdown hook") { public void run() { deleteLockFile(); MainFrame.getInstance().quit(false); } }); }
From source file:uk.ac.kcl.texthunter.core.AnnotationEditor.java
private void quitProgram() { int n;//w w w .ja v a2 s . c om try { if (projectLoaded) { System.out.println("quitting program..."); Object[] options = { "Yes", "No", "Cancel" }; n = JOptionPane.showOptionDialog(null, "Do you wish to save your project before exiting?\n" + projectLocation, "Warning", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (n == 0) { saveProject(); shutDownProcedure(); System.exit(0); } else if (n == 1) { shutDownProcedure(); System.exit(0); } } else { System.exit(0); } } catch (IOException ex) { Logger.getLogger(AnnotationEditor.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:uk.chromis.pos.config.JPanelConfiguration.java
/** * * @return// w w w . java2s .c om */ @Override public boolean deactivate() { boolean haschanged = false; for (PanelConfig c : m_panelconfig) { if (c.hasChanged()) { haschanged = true; } } if (haschanged) { int res = JOptionPane.showConfirmDialog(this, AppLocal.getIntString("message.wannasave"), AppLocal.getIntString("title.editor"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (res == JOptionPane.YES_OPTION) { saveProperties(); return true; } else { return res == JOptionPane.NO_OPTION; } } else { return true; } }