List of usage examples for java.awt EventQueue invokeLater
public static void invokeLater(Runnable runnable)
From source file:us.physion.ovation.ui.editor.PlainTextVisualizationFactory.java
@Override public DataVisualization createVisualization(final Content r) { return new AbstractDataVisualization() { @Override/*from ww w. j a v a2 s .c o m*/ public JComponent generatePanel() { class PlainTextArea extends JTextArea { private boolean scrollableTracksViewportWidth = false; @Override public boolean getScrollableTracksViewportWidth() { return scrollableTracksViewportWidth; } private void setScrollableTracksViewportWidth(boolean b) { if (b == scrollableTracksViewportWidth) { return; } scrollableTracksViewportWidth = b; } private void failed() { setText(Bundle.LBL_TextLoadingFailed(ContentUtils.contentLabel(r))); } @Override public void addNotify() { super.addNotify(); ListenableFuture<File> data; try { data = r.getData(); } catch (ResourceNotFoundException ex) { log.warn("Resource not found", ex); failed(); return; } Futures.addCallback(data, new FutureCallback<File>() { @Override public void onSuccess(File f) { try { FileReader fr = new FileReader(f); try { final String text = IOUtils.toString(fr); EventQueue.invokeLater(new Runnable() { @Override public void run() { setText(text); setCaretPosition(0); repaint(); } }); } finally { IOUtils.closeQuietly(fr); } } catch (IOException ex) { log.warn("Could not load text", ex); failed(); } } @Override public void onFailure(Throwable ex) { log.warn("Could not get file", ex); failed(); } }, loadFileExecutors); } } final PlainTextArea t = new PlainTextArea(); t.setEditable(false); t.setText(Bundle.LBL_TextLoading()); ParentWidthPanel panel = new ParentWidthPanel(); panel.add(new JScrollPane(t), BorderLayout.CENTER); { JToolBar toolbar = new JToolBar(SwingConstants.HORIZONTAL); toolbar.setBackground(Color.WHITE); toolbar.add(new JToggleButton(new AbstractAction(Bundle.LBL_LineWrap()) { @Override public void actionPerformed(ActionEvent e) { boolean selected = ((JToggleButton) e.getSource()).isSelected(); t.setLineWrap(selected); t.setScrollableTracksViewportWidth(selected); t.setCaretPosition(0); t.revalidate(); t.repaint(); } })); panel.add(toolbar, BorderLayout.NORTH); } return panel; } @Override public boolean shouldAdd(Content r) { return false; } @Override public void add(Content r) { throw new UnsupportedOperationException(); } @Override public Iterable<? extends OvationEntity> getEntities() { return Sets.newHashSet((OvationEntity) r); } }; }
From source file:wsattacker.plugin.dos.dosExtension.attackThreads.SendRequestThread.java
@Override public void run() { // do actual sending depending on requestType RequestSender requestSender;/*from w ww .ja v a 2 s . co m*/ if (!useNewMeasure) { requestSender = new RequestSenderImpl(model); } else { requestSender = new Http4RequestSenderImpl(model); } // Start time timeStart = System.currentTimeMillis(); // TODO [CHAL 2013-12-31] we have to use enumeration here // TODO [CHAL 2013-12-31] where is the networkTest??? if (this.requestType.equals("tampered")) { responseString = requestSender.sendTamperedRequest(); } else if (this.requestType.equals("untampered")) { responseString = requestSender.sendUntamperedRequest(); } else if (this.requestType.equals("testProbe")) { responseString = requestSender.sendTestProbeRequest(); } else { throw new EmptyStackException(); } // Stop time timeEnd = System.currentTimeMillis(); // calculate the duration, the RequestSender knows its timing duration = requestSender.getReceiveTime() - requestSender.getSendTime(); // Check for empty Response or SOAP-Fault // - SOAP-Fault check by finding end of closing Tag "Fault>" if (StringUtils.isEmpty(responseString)) { errorFlag = true; } else if (responseString.contains("Fault>")) { faultFlag = true; } // Log time -> done in context of EDT LogRequestRunnable log = new LogRequestRunnable(this.model, this.requestType, timeStart, timeEnd, duration, this.threadNumber, faultFlag, errorFlag, responseString); EventQueue.invokeLater(log); // Update GUI + Counter // - since called via runnable, Method will be executed in EDT -> no // Problems with Syncronization! if (this.requestType.equals("tampered") || this.requestType.equals("untampered")) { UpdateNumberRequestsRunnable update = new UpdateNumberRequestsRunnable(model, requestType); EventQueue.invokeLater(update); } else if (this.requestType.equals("testProbe")) { UpdateNumberProbesRunnable update = new UpdateNumberProbesRunnable(model); EventQueue.invokeLater(update); } else if (this.requestType.equals("networkTest")) { UpdateNumberNetworktestProbesRunnable update = new UpdateNumberNetworktestProbesRunnable(model); EventQueue.invokeLater(update); } // Log completion Result.getGlobalResult().add(new ResultEntry(ResultLevel.Trace, getName(), "Done Sending " + this.requestType + "-Request in " + duration + " ns")); }
From source file:jrrombaldo.pset.PSETMain.java
private static void startGuiVersion(final String domain) { /* Set the Nimbus look and feel */ /*/*from w w w . j a va 2 s.com*/ * If Nimbus (introduced in Java SE 6) is not available, stay with the * default look and feel. For details see * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf. * html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) { ex.printStackTrace(); } /* Create and display the form */ // Java 8 required // java.awt.EventQueue.invokeLater(() -> { // new WebSearchMainForm(domain).setVisible(true); // }); EventQueue.invokeLater(new Runnable() { @Override public void run() { try { new WebSearchMainForm(domain).setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); }
From source file:org.pdfsam.App.java
@EventListener public void openPath(OpenFileRequest event) { EventQueue.invokeLater(() -> doOpen(event)); }
From source file:org.sbml.bargraph.MainWindow.java
/** * Testing harness./* www . java2 s . c o m*/ * @param args */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { @Override public void run() { try { MainWindow mainWindow = new MainWindow(null); mainWindow.initAndShow(); } catch (Exception e) { e.printStackTrace(); } } }); }
From source file:com.antelink.sourcesquare.gui.controller.SourceSquareController.java
public void display() { EventQueue.invokeLater(new Runnable() { @Override/*from ww w . ja va 2s .c o m*/ public void run() { try { SourceSquareController.this.view.setVisible(true); } catch (Exception e) { logger.error("Error launching the UI", e); } } }); }
From source file:ca.uhn.hl7v2.testpanel.ui.ActivityDetailsCellRenderer.java
@Override public Component getTableCellRendererComponent(final JTable theTable, Object theValue, boolean theIsSelected, boolean theHasFocus, final int theRow, int theColumn) { super.getTableCellRendererComponent(theTable, theValue, theIsSelected, theHasFocus, theRow, theColumn); if (theValue instanceof ActivityInfo) { renderInfo(theTable, theValue, theRow); } else if (theValue instanceof ActivityMessage) { renderMessage(theTable, theValue, theRow, theIsSelected); } else if (theValue instanceof ActivityBytesBase) { renderBytes(theTable, theValue, theRow); } else if (theValue instanceof ActivityValidationOutcome) { renderValidation(theTable, (ActivityValidationOutcome) theValue, theRow); }//from w ww .j av a 2s .c o m // int prefHeight = getPreferredSize().height; // prefHeight = Math.max(prefHeight, 10); // if (prefHeight != theTable.getRowHeight(theRow)) { // ourLog.trace("Setting height of row {} to {}", theRow, prefHeight); // theTable.setRowHeight(theRow, prefHeight); // } // EventQueue.invokeLater(new Runnable() { // public void run() { // int minWidth = getPreferredSize().width + 200; // // if (minWidth > theTable.getColumnModel().getColumn(2).getWidth()) { // theTable.getColumnModel().getColumn(2).setMinWidth(getPreferredSize().width); // theTable.getColumnModel().getColumn(2).setMaxWidth(getPreferredSize().width); // theTable.getColumnModel().getColumn(2).setPreferredWidth(getPreferredSize().width); // } // }}); // ourLog.info("Rendering row {}", theRow); // EventQueue.invokeLater(new Runnable() { // public void run() { // getTablePanel(). // JScrollBar vsb = myscrollPane.getVerticalScrollBar(); // vsb.setValue(vsb.getMaximum()); // ourLog.info("Setting scrollbar to bottom: {}", vsb.getMaximum()); // } // }); if (myScrollToBottom) { EventQueue.invokeLater(new Runnable() { public void run() { JScrollBar vsb = getTablePanel().getScrollPane().getVerticalScrollBar(); int newValue = vsb.getMaximum(); int existingValue = vsb.getValue(); if (newValue != existingValue) { vsb.setValue(newValue); ourLog.debug("Setting scrollbar to bottom, from {} to {}", existingValue, newValue); } if (theRow == getTablePanel().getTableModel().getRowCount() - 1) { myScrollToBottom = false; } } }); } return this; }
From source file:InterruptibleSocketTest.java
/** * Connects to the test server, using interruptible I/O *///w w w . ja v a2 s.c om public void connectInterruptibly() throws IOException { messages.append("Interruptible:\n"); SocketChannel channel = SocketChannel.open(new InetSocketAddress("localhost", 8189)); try { in = new Scanner(channel); while (!Thread.currentThread().isInterrupted()) { messages.append("Reading "); if (in.hasNextLine()) { String line = in.nextLine(); messages.append(line); messages.append("\n"); } } } finally { channel.close(); EventQueue.invokeLater(new Runnable() { public void run() { messages.append("Channel closed\n"); interruptibleButton.setEnabled(true); blockingButton.setEnabled(true); } }); } }
From source file:net.brtly.monkeyboard.gui.MasterControlPanel.java
public MasterControlPanel(JFrame frame) { _frame = frame;//from w w w.j a v a 2 s . co m initWindowListener(frame); JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar); JMenu mnActions = new JMenu("Actions"); menuBar.add(mnActions); JMenu mnDebug = new JMenu("Debug"); mnActions.add(mnDebug); JMenuItem mntmAddPluginpanel = new JMenuItem("Request null PluginPanel"); mntmAddPluginpanel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.out.println("Requesting null PluginPanel"); // TODO } }); mnDebug.add(mntmAddPluginpanel); JMenu mnOptions = new JMenu("Options"); menuBar.add(mnOptions); _viewMenu = new JMenu("Views"); _viewMenu.addMenuListener(new MenuListener() { @Override public void menuCanceled(MenuEvent arg0) { } @Override public void menuDeselected(MenuEvent arg0) { } @Override public void menuSelected(MenuEvent arg0) { updateViewMenu(); } }); menuBar.add(_viewMenu); // INITIALIZE MANAGERS // TODO: maybe call this in the Runnable and fire an event when finished _eventBus = new SwingEventBus(); _eventBus.register(this); DeviceManager.init(_eventBus); _pluginManager = new PluginManager(_eventBus); _pluginManager.loadPlugins(); // create the status bar panel and shove it down the bottom of the frame statusPanel = new StatusBar(frame); _frame.getContentPane().add(statusPanel, BorderLayout.SOUTH); _dockController = new CControl(frame); _frame.getContentPane().add(_dockController.getContentArea(), BorderLayout.CENTER); _panelFactory = new PluginPanelDockableFactory(_pluginManager); _dockController.addMultipleDockableFactory(PluginPanelDockableFactory.ID, _panelFactory); _dockController.createWorkingArea("root"); updateViewMenu(); EventQueue.invokeLater(new Runnable() { @Override public void run() { DeviceManager.start(null); } }); _runOnClose.add(new Runnable() { public void run() { _dockController.destroy(); DeviceManager.stop(); DeviceManager.shutdown(); System.exit(0); } }); }
From source file:com.ln.gui.Main.java
public void gg() { EventQueue.invokeLater(new Runnable() { public void run() { try { f.setState(NORMAL);/*from w w w. j a va 2 s .c om*/ f.setAlwaysOnTop(true); if (Configuration.popup == 1) { JOptionPane.showMessageDialog(rootPane, ee, "Event Starting!", JOptionPane.INFORMATION_MESSAGE); } f.setAlwaysOnTop(false); } catch (Exception e) { } } }); }