List of usage examples for javax.swing JProgressBar setPreferredSize
@BeanProperty(preferred = true, description = "The preferred size of the component.") public void setPreferredSize(Dimension preferredSize)
From source file:org.ash.history.detail.DetailsPanelH.java
/** * Creates the progress bar./*from w ww.j a v a2 s. co m*/ * * @param msg the msg * * @return the j panel */ private JPanel createProgressBar(String msg) { JProgressBar progress = ProgressBarUtil.createJProgressBar(msg); progress.setPreferredSize(new Dimension(250, 30)); JPanel panel = new JPanel(); panel.add(progress); return panel; }
From source file:DownloadDialog.java
/******************************************************************** * Constructor: DownloadDialog//from ww w .j ava 2s.c o m * Purpose: constructor for download, with necessary references /*******************************************************************/ public DownloadDialog(final MainApplication context, Scheduler scheduler_Ref, JList courseListSelected_Ref, JList courseListAll_Ref) { // Basic setup for dialog setModalityType(Dialog.ModalityType.APPLICATION_MODAL); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); setTitle(TITLE); // Setup proper references this.scheduler = scheduler_Ref; this.courseListSelected = courseListSelected_Ref; this.courseListAll = courseListAll_Ref; // Store available terms storeTerms(); // Constraints GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.insets = new Insets(10, 10, 10, 10); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 0; c.gridwidth = 2; // Main panel panel = new JPanel(new GridBagLayout()); // Add term select box termCB = new JComboBox(termsName.toArray()); panel.add(termCB, c); // Setup username and password labels JLabel userL = new JLabel("Username:"); JLabel passL = new JLabel("Password:"); c.gridwidth = 1; c.gridx = 0; c.weightx = 0; // Add user label c.gridy = 1; c.insets = new Insets(5, 10, 0, 10); panel.add(userL, c); // Add password label c.gridy = 2; c.insets = new Insets(0, 10, 5, 10); panel.add(passL, c); // Setup user and pass text fields user = new JTextField(); pass = new JPasswordField(); c.weightx = 1; c.gridx = 1; // Add user field c.gridy = 1; c.insets = new Insets(5, 10, 2, 10); panel.add(user, c); // Add pass field c.gridy = 2; c.insets = new Insets(2, 10, 5, 10); panel.add(pass, c); // Setup login button JButton login = new JButton("Login"); login.addActionListener(this); c.insets = new Insets(10, 10, 10, 10); c.gridx = 0; c.gridy = 3; c.gridwidth = 2; c.weightx = 1; panel.add(login, c); // Add panel to main box add(panel); // Pack the components and give userbox focus pack(); user.requestFocus(); // Create worker to download courses worker = new SwingWorker<Void, Void>() { protected Void doInBackground() throws Exception { // Reset courses scheduler.resetCourses(); // Constraints GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.insets = new Insets(10, 10, 10, 10); c.gridx = 0; c.weightx = 1; c.weighty = 0; // Remove all elements panel.removeAll(); // Add status JLabel status = new JLabel("Connecting..."); c.gridy = 0; panel.add(status, c); // Add progress bar JProgressBar progressBar = new JProgressBar(0, SUBJECTS.length); c.gridy = 1; panel.add(progressBar, c); progressBar.setPreferredSize(new Dimension(275, 12)); // Revalidate, repaint, and pack //revalidate(); repaint(); pack(); try { // Create client DefaultHttpClient client = new DefaultHttpClient(); // Setup and execute initial login HttpGet initialLogin = new HttpGet("http://jweb.kettering.edu/cku1/twbkwbis.P_ValLogin"); HttpResponse response = client.execute(initialLogin); HTMLParser.parse(response); // Get current term String term = termsValue.get(termCB.getSelectedIndex()); // Consume entity (cookies) HttpEntity entity = response.getEntity(); if (entity != null) entity.consumeContent(); // Create post for login HttpPost login = new HttpPost("http://jweb.kettering.edu/cku1/twbkwbis.P_ValLogin"); // Parameters List<NameValuePair> parameters = new ArrayList<NameValuePair>(); parameters.add(new BasicNameValuePair("sid", user.getText())); parameters.add(new BasicNameValuePair("PIN", pass.getText())); login.setEntity(new UrlEncodedFormEntity(parameters)); login.setHeader("Referer", "http://jweb.kettering.edu/cku1/twbkwbis.P_ValLogin"); // Login ! response = client.execute(login); // Store proper cookies List<Cookie> cookies = client.getCookieStore().getCookies(); // Start off assuming logging in failed boolean loggedIn = false; // Check cookies for successful login for (int i = 0; i < cookies.size(); i++) if (cookies.get(i).getName().equals("SESSID")) loggedIn = true; // Success? if (loggedIn) { // Consumption of feed HTMLParser.parse(response); // Execute GET class list page HttpGet classList = new HttpGet( "http://jweb.kettering.edu/cku1/bwskfcls.p_sel_crse_search"); classList.setHeader("Referer", "https://jweb.kettering.edu/cku1/twbkwbis.P_GenMenu"); response = client.execute(classList); HTMLParser.parse(response); // Execute GET for course page HttpGet coursePage = new HttpGet( "http://jweb.kettering.edu/cku1/bwckgens.p_proc_term_date?p_calling_proc=P_CrseSearch&p_term=" + term); coursePage.setHeader("Referer", "http://jweb.kettering.edu/cku1/bwskfcls.p_sel_crse_search"); response = client.execute(coursePage); HTMLParser.parse(response); // Download every subject's data for (int index = 0; index < SUBJECTS.length; index++) { // Don't download if cancel was pressed if (isCancelled()) break; // Update status, progress bar, then store course String subject = SUBJECTS[index]; status.setText("Downloading " + subject); progressBar.setValue(index); scheduler.storeDynamicCourse(subject, client, term); } // Update course list data courseListAll.setListData(scheduler.getCourseIDs().toArray()); // Clear course list data String[] empty = {}; courseListSelected.setListData(empty); context.updatePermutations(); context.updateSchedule(); // Dispose of dialog if cancelled if (!isCancelled()) { dispose(); } } // Invalid login? else { // Update status status.setText("Invalid login."); } } // Failed to download? catch (Exception exc) { // Show stack trace, and update status exc.printStackTrace(); status.setText("Failed downloading."); } return null; } }; // Setup window close event to be same as cancel this.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { // Cancel all downloads then dispose worker.cancel(true); dispose(); } }); // Make sure dialog is visible setLocationRelativeTo(context); setVisible(true); }
From source file:org.gofleet.module.routing.RoutingMap.java
private void newPlan(LatLon from) { JDialog d = new JDialog(basicWindow.getFrame(), "Generating New Plan"); try {/*from w ww . j a v a 2 s . com*/ JFileChooser fc = new JFileChooser(); fc.addChoosableFileFilter(new RoutingFilter()); fc.setAcceptAllFileFilterUsed(true); int returnVal = fc.showOpenDialog(basicWindow.getFrame()); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); log.debug("Opening: " + file.getName()); JProgressBar progressBar = new JProgressBar(0, getNumberLines(file) * 2); progressBar.setValue(0); progressBar.setPreferredSize(new Dimension(150, 50)); progressBar.setStringPainted(true); d.add(progressBar); d.pack(); d.setVisible(true); TSPPlan[] param = processFile(file, progressBar); Map<String, String> values = getValues(from); double[] origin = new double[2]; origin[0] = new Double(values.get("origin_x")); origin[1] = new Double(values.get("origin_y")); TSPPlan[] res = calculateRouteOnWS(new Integer(values.get("maxDistance")), new Integer(values.get("maxTime")), origin, new Integer(values.get("startTime")), param, new Integer(values.get("timeSpentOnStop"))); progressBar.setValue(progressBar.getMaximum() - res.length); processTSPPlan(res, progressBar); } else { log.trace("Open command cancelled by user."); } } catch (Throwable t) { log.error("Error computing new plan", t); JOptionPane.showMessageDialog(basicWindow.getFrame(), "<html><p>" + i18n.getString("Main.Error") + ":</p><p>" + t.toString() + "</p><html>", i18n.getString("Main.Error"), JOptionPane.ERROR_MESSAGE); } finally { d.setVisible(false); d.dispose(); } }
From source file:pl.otros.logview.gui.LogViewMainFrame.java
public LogViewMainFrame(DataConfiguration c) throws InitializationException { super();//from w w w . java2 s .co m this.configuration = c; this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); String title = "OtrosLogViewer"; try { title += ' ' + VersionUtil.getRunningVersion(); } catch (Exception e) { LOGGER.warning("Can't load version of running OLV"); } this.setTitle(title); try { String iconPath = "img/otros/logo16.png"; if (System.getProperty("os.name").contains("Linux")) { iconPath = "img/otros/logo64.png"; } BufferedImage icon = ImageIO.read(this.getClass().getClassLoader().getResourceAsStream(iconPath)); this.setIconImage(icon); } catch (Exception e1) { LOGGER.warning("Can't load icon: " + e1.getMessage()); } Exception modalDisplayException = null; // If non-terminal load problem occurs, queue to display for user on // top of the app UI. try { OtrosSplash.setMessage("Loading plugins"); LvDynamicLoader.getInstance().setStatusObserver(OtrosSplash.getSplashStatusObserver()); LvDynamicLoader.getInstance().loadAll(); OtrosSplash.setMessage("Loading plugins loaded"); } catch (IOException e) { LOGGER.severe("Problem with loading automatic markers, filter or log importers: " + e.getMessage()); modalDisplayException = e; } catch (InitializationException ie) { // Details should have been logged at lower level modalDisplayException = ie; } OtrosSplash.setMessage("Initializing GUI"); allPluginables = AllPluginables.getInstance(); logImportersContainer = allPluginables.getLogImportersContainer(); messageColorizercontainer = allPluginables.getMessageColorizers(); searchResultColorizer = (SearchResultColorizer) messageColorizercontainer .getElement(SearchResultColorizer.class.getName()); cardLayout = new CardLayout(); cardLayoutPanel = new JPanel(cardLayout); JLabel statusLabel = new JLabel(" "); observer = new JLabelStatusObserver(statusLabel); logsTabbedPane = new JTabbedPane(); enableDisableComponetsForTabs = new EnableDisableComponetsForTabs(logsTabbedPane); logsTabbedPane.addChangeListener(enableDisableComponetsForTabs); otrosApplication = new OtrosApplication(); otrosApplication.setAllPluginables(AllPluginables.getInstance()); otrosApplication.setApplicationJFrame(this); otrosApplication.setConfiguration(configuration); otrosApplication.setjTabbedPane(logsTabbedPane); otrosApplication.setStatusObserver(observer); otrosApplication.setOtrosVfsBrowserDialog(new JOtrosVfsBrowserDialog(getVfsFavoritesConfiguration())); otrosApplication.setServices(new ServicesImpl(otrosApplication)); SingleInstanceRequestResponseDelegate.getInstance().setOtrosApplication(otrosApplication); ToolTipManager.sharedInstance().setDismissDelay(5000); JProgressBar heapBar = new JProgressBar(); heapBar.setPreferredSize(new Dimension(190, 15)); new Thread(new MemoryUsedStatsUpdater(heapBar, 1500), "MemoryUsedUpdater").start(); JPanel statusPanel = new JPanel(new MigLayout("fill", "[fill, push, grow][right][right]", "[]")); statusPanel.add(statusLabel); final JButton ideConnectedLabel = new JButton(Ide.IDEA.getIconDiscounted()); statusPanel.add(ideConnectedLabel); statusPanel.add(new JButton(new SwitchAutoJump(otrosApplication))); statusPanel.add(heapBar); initMenu(); initToolbar(); addEmptyViewListener(); addMenuBarReloadListener(); otrosApplication.setSearchField(searchField); cardLayoutPanel.add(logsTabbedPane, CARD_LAYOUT_LOGS_TABLE); EmptyViewPanel emptyViewPanel = new EmptyViewPanel(otrosApplication); final JScrollPane jScrollPane = new JScrollPane(emptyViewPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { jScrollPane.getVerticalScrollBar().setValue(0); } }); cardLayoutPanel.add(jScrollPane, CARD_LAYOUT_EMPTY); cardLayout.show(cardLayoutPanel, CARD_LAYOUT_EMPTY); enableDisableComponetsForTabs.stateChanged(null); Container cp = getContentPane(); cp.setLayout(new BorderLayout()); cp.add(toolBar, BorderLayout.NORTH); cp.add(cardLayoutPanel, BorderLayout.CENTER); cp.add(statusPanel, BorderLayout.SOUTH); initGlobalHotKeys(); initPosition(); if (configuration.getBoolean(ConfKeys.LOAD_EXPERIMENTAL_FEATURES, false)) { initExperimental(); } setTransferHandler(new DragAndDropFilesHandler(otrosApplication)); initPlugins(); OtrosSplash.hide(); setVisible(true); if (modalDisplayException != null) JOptionPane.showMessageDialog(this, "Problem with loading automatic markers," + "filter or log importers:\n" + modalDisplayException.getMessage(), "Initialization Error", JOptionPane.ERROR_MESSAGE); // Check new version on start if (c.getBoolean(ConfKeys.VERSION_CHECK_ON_STARTUP, true)) { new ChekForNewVersionOnStartupAction(otrosApplication).actionPerformed(null); } new TipOfTheDay(c).showTipOfTheDayIfNotDisabled(this); Toolkit.getDefaultToolkit().getSystemEventQueue().push(new EventQueueProxy()); ListUncaughtExceptionHandlers listUncaughtExceptionHandlers = new ListUncaughtExceptionHandlers(// new LoggingExceptionHandler(), // new ShowErrorDialogExceptionHandler(otrosApplication), // new StatusObserverExceptionHandler(observer)); Thread.setDefaultUncaughtExceptionHandler(listUncaughtExceptionHandlers); ListeningScheduledExecutorService listeningScheduledExecutorService = otrosApplication.getServices() .getTaskSchedulerService().getListeningScheduledExecutorService(); listeningScheduledExecutorService.scheduleAtFixedRate( new IdeAvailabilityCheck(ideConnectedLabel, otrosApplication.getServices().getJumpToCodeService()), 5, 5, TimeUnit.SECONDS); ideConnectedLabel.addActionListener(new IdeIntegrationConfigAction(otrosApplication)); }
From source file:xtrememp.update.SoftwareUpdate.java
public static void showCheckForUpdatesDialog() { checkForUpdatesDialog = new JDialog(XtremeMP.getInstance().getMainFrame(), tr("Dialog.SoftwareUpdate"), true);/* ww w. ja va 2 s . co m*/ JPanel panel = new JPanel(new BorderLayout(0, 10)); panel.add(new JLabel(tr("Dialog.SoftwareUpdate.CheckingForUpdates")), BorderLayout.CENTER); JProgressBar progressBar = new JProgressBar(); progressBar.setIndeterminate(true); progressBar.setPreferredSize(new Dimension(250, 20)); panel.add(progressBar, BorderLayout.SOUTH); JButton cancelButton = new JButton(tr("Button.Cancel")); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (checkForUpdatesWorker != null && !checkForUpdatesWorker.isDone()) { checkForUpdatesWorker.cancel(true); } checkForUpdatesDialog.dispose(); } }); JOptionPane optionPane = new JOptionPane(panel, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null, new Object[] { cancelButton }, cancelButton); checkForUpdatesDialog.setContentPane(optionPane); checkForUpdatesDialog.pack(); checkForUpdatesDialog.setResizable(false); checkForUpdatesDialog.setLocationRelativeTo(checkForUpdatesDialog.getParent()); checkForUpdatesDialog.getRootPane().setDefaultButton(cancelButton); checkForUpdatesDialog.setVisible(true); }