public static void main(String[] args) throws Exception { createUI(); Robot robot = new Robot(); robot.waitForIdle(); Rectangle rect = window.getBounds(); rect.x += rect.width - 10; rect.y += rect.height - 10; robot.delay(1000); Color c = robot.getPixelColor(rect.x, rect.y); try { if (!c.equals(Color.RED)) { throw new RuntimeException("Test Failed"); } } finally { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { background.dispose(); window.dispose(); } }); } }
public boolean postProcessKeyEvent(KeyEvent ev) { if (ev.isConsumed()) return false; if (processShortcut(ev)) return true; Window w = SwingUtilities.windowForComponent(ev.getComponent()); if (w instanceof Dialog && !WindowManagerImpl.isSeparateWindow(w)) return false; JFrame mw = (JFrame)WindowManagerImpl.getInstance().getMainWindow(); if (w == mw) { return false; } JMenuBar mb = mw.getJMenuBar(); if (mb == null) return false; boolean pressed = (ev.getID() == KeyEvent.KEY_PRESSED); boolean res = invokeProcessKeyBindingsForAllComponents(ev, mw, pressed); if (res) ev.consume(); return res; }
private void tMacrosTableChanged(final TableModelEvent evt) { SwingUtilities.invokeLater(new Runnable() { public void run() { if (evt.getType() == TableModelEvent.INSERT) { tMacros.getSelectionModel().setSelectionInterval(evt.getFirstRow(), evt.getFirstRow()); } else if (evt.getType() == TableModelEvent.DELETE) { // try the next row after the deleted one int tableRow = evt.getLastRow(); if (tableRow < tMacros.getModel().getRowCount()) { tMacros.getSelectionModel().setSelectionInterval(tableRow, tableRow); } else { // try the previous row tableRow = evt.getFirstRow() - 1; if (tableRow >= 0) { tMacros.getSelectionModel().setSelectionInterval(tableRow, tableRow); } else { tMacros.getSelectionModel().clearSelection(); } } } } }); }
public static void selectAndExpandProject( final Project p ) { if( p == null) return; // invoke later to select the being opened project if the focus is outside ProjectTab SwingUtilities.invokeLater(new Runnable() { final ExplorerManager.Provider ptLogial = findDefault(ProjectTab_ID_LOGICAL); public void run() { Node root = ptLogial.getExplorerManager().getRootContext(); // Node projNode = root.getChildren ().findChild( p.getProjectDirectory().getName () ); Node projNode = root.getChildren().findChild( ProjectUtils.getInformation( p ).getName() ); if ( projNode != null ) { try { ptLogial.getExplorerManager().setSelectedNodes( new Node[] { projNode } ); } catch (Exception ignore) { // may ignore it } } } }); }
public static void main(final String[] args) throws Exception { CountDownLatch go = new CountDownLatch(1); Robot r = new Robot(); SwingUtilities.invokeLater(() -> System.out.println("some work")); Thread t = new Thread(() -> { synchronized (WAIT_LOCK) { go.countDown(); try { Thread.sleep(30000); passed = false; } catch (InterruptedException e) { System.out.println("e = " + e); } } }); t.start(); go.await(); r.waitForIdle(); t.interrupt(); if (!passed) { throw new RuntimeException("Test failed"); } }
void init() { isInitialized = true; fileListModel.clear(); fileList.setEnabled(!isInitialized); if (isInitialized) { PROCESSOR.post(new Runnable() { public void run() { SessionStorage _storage = getStorage(); final Collection<FileObject> files = getFiles(_storage); SwingUtilities.invokeLater(new Runnable() { public void run() { fileList.setEnabled(true); for (FileObject fo : files) fileListModel.addElement(fo); } }); } }); } }
public void startProgress() { SwingUtilities.invokeLater(new Runnable() { public void run() { ProgressHandle progress = getProgressHandle(); // NOI18N JComponent bar = ProgressHandleFactory.createProgressComponent(progress); stopButton = new JButton(org.openide.util.NbBundle.getMessage(RepositoryStep.class, "BK2022")); // NOI18N stopButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cancel(); } }); progressComponent = new JPanel(); progressComponent.setLayout(new BorderLayout(6, 0)); progressLabel = new JLabel(); progressLabel.setText(getDisplayName()); progressComponent.add(progressLabel, BorderLayout.NORTH); progressComponent.add(bar, BorderLayout.CENTER); progressComponent.add(stopButton, BorderLayout.LINE_END); WizardStepProgressSupport.super.startProgress(); panel.setVisible(true); panel.add(progressComponent); panel.revalidate(); } }); }
private static void executeTest() throws Exception { Point point = Util.getCenterPoint(menu); performMouseOperations(point); point = Util.getCenterPoint(menuItem); performMouseOperations(point); point = Util.getCenterPoint(menu); performMouseOperations(point); point = Util.getCenterPoint(menuItem); performMouseOperations(point); SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { internalFrame = desktopPane.getSelectedFrame(); internalFrame.doDefaultCloseAction(); internalFrame = desktopPane.getSelectedFrame(); } }); robot.delay(2000); if (internalFrame == null) { dispose(); throw new RuntimeException("Test Failed"); } }
public static void main(String[] args) throws Exception { // Create Robot testRobot = new Robot(); // Create test UI String lookAndFeelString = "javax.swing.plaf.nimbus.NimbusLookAndFeel"; SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { try { constructTestUI(lookAndFeelString); } catch (Exception ex) { throw new RuntimeException("Exception creating test UI"); } } }); testRobot.waitForIdle(); testRobot.delay(200); // Run test method testScrollBarThumbPainter(); // Dispose test UI disposeTestUI(); }
public static void main(String args[]) throws Exception { final CountDownLatch latch = new CountDownLatch(1); test = new TestUI(latch); SwingUtilities.invokeAndWait(() -> { try { test.createUI(); } catch (Exception ex) { throw new RuntimeException("Exception while creating UI"); } }); boolean status = latch.await(2, TimeUnit.MINUTES); if (!status) { System.out.println("Test timed out."); } if (test.testResult == false) { disposeUI(); throw new RuntimeException("Test Failed."); } }
public void doZoom(Point2D p, double factor) { LatLon dest = new LatLon(Angle.fromDegrees(p.getY()), Angle.fromDegrees(p.getX())); double wwzoom = 2785 * Math.pow(factor, -.8311) * 10000; final OrbitView view = (OrbitView) wwd.getView(); FlyToOrbitViewAnimator fto = FlyToOrbitViewAnimator.createFlyToOrbitViewAnimator( view, view.getCenterPosition(), new Position(dest, 0), view.getHeading(), Angle.fromDegrees(0), view.getPitch(), Angle.fromDegrees(0), view.getZoom(), wwzoom, 5000, WorldWind.CONSTANT); //was true view.addAnimator(fto); SwingUtilities.invokeLater(new Runnable() { public void run() { ((MapApp)getApp()).getFrame().toFront(); view.firePropertyChange(AVKey.VIEW, null, view); } }); }
public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); } catch (Exception e) {} JFrame frame = new JFrame("JavaFX 2.0 in Swing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JApplet applet = new SwingInterop(); applet.init(); frame.setContentPane(applet.getContentPane()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); applet.start(); } }); }
/** called when Observable changes (pot changes) */ @Override public void update(final Observable observable, final Object obj) { if (observable instanceof IPot) { // log.info("observable="+observable); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { // don't do the following - it sometimes prevents display updates or results in double updates // slider.setValueIsAdjusting(true); // try to prevent a new event from the slider updateAppearance(); } }); } }
/** * Builds the specific fields for the selected input method */ private synchronized void buildSpecificFields() { SwingUtilities.invokeLater(() -> { if (findId("editor") != null) { remove((java.awt.Component) findId("editor")); } Component editor = null; if (input == null) { editor = Panels.create(); } else { if (input instanceof MultiFileInput) { editor = buildMultiFile(); } if (input instanceof WebcamInput) { editor = Panels.create(); } } put(editor.id("editor")); revalidate(); }); }
@Override public void actionPerformed(ActionEvent e) { Runnable runner = new Runnable() { @Override public void run() { TreePath[] paths = resourcesTree.getSelectionPaths(); for(TreePath path : paths) { final Object value = ((DefaultMutableTreeNode) path.getLastPathComponent()).getUserObject(); if(value instanceof Handle) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new CloseViewAction((Handle)value).actionPerformed(null); }}); } } } }; Thread thread = new Thread(runner, "CloseViewsForSelectedResourcesAction"); thread.setPriority(Thread.MIN_PRIORITY); thread.start(); }
public static void main(String[] args){ SwingUtilities.invokeLater(new Runnable() { public void run() { ModelSpeciesSelection modelSpeciesSelection = new ModelSpeciesSelection(); ModelSelectedSpecies modelSelectedSpecies = new ModelSelectedSpecies(); ViewSpeciesSelection s = new ViewSpeciesSelection(modelSpeciesSelection,modelSelectedSpecies); ControllerSpeciesSelection sa = new ControllerSpeciesSelection(s,modelSpeciesSelection,modelSelectedSpecies); JFrame frame = new JFrame(); frame.add(s); frame.setVisible(true); frame.setResizable(true); frame.setMinimumSize(new Dimension(750,700)); frame.setBounds(0, 0,750, 700); } }); }
public static void main(String[] args) throws Exception { JColorChooser chooser = new JColorChooser(); AbstractColorChooserPanel[] panels = chooser.getChooserPanels(); chooser.setChooserPanels(new AbstractColorChooserPanel[] { panels[1] }); JDialog dialog = show(chooser); pause(DELAY); dialog.dispose(); pause(DELAY); Test4177735 test = new Test4177735(); SwingUtilities.invokeAndWait(test); if (test.count != 0) { throw new Error("JColorChooser leaves " + test.count + " threads running"); } }
private void updateServer() { int curPort = Integer.parseInt(Settings.get().get(Settings.PORT, Settings.PORT_DEFAULT)); if (curPort != port) { port = curPort; if (server != null) { server.shutdown(); } server = Server.start(callback, port); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { updateLabel(); } }); } }
public void select(String path) { Node nodeToSelect = getTemplateNode(path); if (nodeToSelect != null) { try { manager.setSelectedNodes (new Node[]{ nodeToSelect }); view.expandNode(nodeToSelect); } catch (PropertyVetoException ex) { Logger.getLogger(TemplatesPanel.class.getName()).log(Level.FINE, ex.getLocalizedMessage (), ex); } } SwingUtilities.invokeLater (new Runnable () { @Override public void run() { view.requestFocus (); } }); }
public int addTabFrame(TabFrame tabFrame) { addTab(tabFrame.getTitleText(), tabFrame); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { revalidate(); repaint(); int c = getTabCount(); setSelectedIndex(c - 1); } }); int i = getTabCount() - 1; setTabComponentAt(i, new ButtonTabComponent(this, menu)); closeOthers.setEnabled(getTabCount() > 1); return i; }
private void checkServicesModel() { if (SaasServicesModel.getInstance().getState() != State.READY) { setErrorMessage(NbBundle.getMessage(AddWebServiceDlg.class, "INIT_WEB_SERVICES_MANAGER")); disableAllControls(); RequestProcessor.getDefault().post(new Runnable() { @Override public void run() { SaasServicesModel.getInstance().initRootGroup(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { enableAllControls(); enableControls(); checkValues(); } }); } }); } }
@BeforeMethod public void showDialog() throws Throwable { JavaElementFactory.add(JFileChooser.class, JFileChooserJavaElement.class); SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { frame = new JFrame(JFileChooserJavaElementTest.class.getSimpleName()); frame.setName("frame-" + JFileChooserJavaElementTest.class.getSimpleName()); frame.getContentPane().add(new FileChooserDemo(), BorderLayout.CENTER); frame.pack(); frame.setVisible(true); frame.setAlwaysOnTop(true); File file = new File(System.getProperty("java.home")); System.setProperty("marathon.project.dir", file.getPath()); } }); driver = new JavaAgent(); }
private static Point getClickPoint(boolean parent) throws Exception { Point points[] = new Point[1]; SwingUtilities.invokeAndWait(() -> { JComponent comp = parent ? menu : menu.getItem(0); Point point = comp.getLocationOnScreen(); Rectangle bounds = comp.getBounds(); point.x += bounds.getWidth() / 2; point.y += bounds.getHeight() / 2; points[0] = point; }); return points[0]; }
public void init() { loadAppletParameters(); // Execute a job on the event-dispatching thread: // creating this applet's GUI. try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { createGUI(); } }); } catch (Exception e) { System.err.println("createGUI didn't successfully complete"); } // Set up timer to drive animation events. timer = new Timer(speed, this); timer.setInitialDelay(pause); timer.start(); // Start loading the images in the background. worker.execute(); }
@Override public void resourceUnloaded(CreoleEvent e) { final Resource res = e.getResource(); if(res instanceof DocumentExporter) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { // TODO Auto-generated method stub JMenuItem item = itemByResource.get(res); if(item != null) { remove(item); itemByResource.remove(res); } if(getItemCount() == 2) { remove(1); } } }); } }
public void testNullChangePerformedAndReflectedInPropertySheet() throws Exception { System.err.println(".testNullChangePerformedAndReflectedInPropertySheet"); int count = ps.table.getRowCount(); assertTrue("Property sheet should contain three rows ", count==3); L l = new L(); tn.addPropertyChangeListener(l); SwingUtilities.invokeAndWait(new Runnable() { public void run() { tn.replaceProps(); } }); Thread.sleep(500); // SwingUtilities.invokeAndWait (new Runnable(){public void run() {System.currentTimeMillis();}}); l.assertEventReceived(); assertTrue("Should only be one property", tn.getPropertySets()[0].getProperties().length == 1); sleep(); ensurePainted(ps); int rc = ps.table.getRowCount(); assertTrue("Property sheet should now only show 2 rows, not " + rc, rc == 2); }
public static void main(String[] args) throws Exception { SwingUtilities.invokeAndWait(() -> { try { UIManager.setLookAndFeel(new MetalLookAndFeel()); } catch (Exception e) { throw new RuntimeException(e); } if (!testSliderThumb(true)) { throw new RuntimeException("Horizontal Slider Thumb is not scaled!"); } if (!testSliderThumb(false)) { throw new RuntimeException("Vertical Slider Thumb is not scaled!"); } }); }
@Override public void run() { if (SwingUtilities.isEventDispatchThread()) { Map<String, String> userDefinedBuildArgs = component.getBuildArgs(); // Submit changes iff user haven't start filling arguments table yet. if (userDefinedBuildArgs == null || userDefinedBuildArgs.isEmpty()) { Map<String, String> filtered = filterMacros(dockerfileDetail.getBuildArgs()); component.setBuildArgs(filtered); wizard.putProperty(BuildImageWizard.BUILD_ARGUMENTS_PROPERTY, filtered); } } else { try { // null is OK DockerInstance instance = (DockerInstance) wizard.getProperty(BuildImageWizard.INSTANCE_PROPERTY); dockerfileDetail = new DockerAction(instance).getDetail(fo); SwingUtilities.invokeLater(this); } catch (IOException ex) { Logger.getLogger(BuildOptionsPanel.class.getName()).log(Level.INFO, "Can't parse dockerfile: {0}", ex.toString()); } } }
public void setProgress(int markerId) { final Marker marker = markers == null ? null : markers[markerId]; if (marker != null) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { progress.setString(marker.message); progress.setValue(marker.count); } }); if (PRINT_TIMES) { System.err.println((System.currentTimeMillis() - startTime) // OK + " " + marker.message); } } else { if (PRINT_TIMES) { System.err.println((System.currentTimeMillis() - startTime) + " ??"); // OK } } }
public @Override int getResponseCode() throws IOException { System.out.println("connecting "+toString()+" ... isEDT = "+SwingUtilities.isEventDispatchThread()); // Thread.dumpStack(); if (sIn != null) { try { sIn.acquire(); if (sOut != null) { sOut.release(); } System.out.println("aquired in lock, released out "+toString()); } catch (InterruptedException ex) { ex.printStackTrace(); fail(ex.getMessage()); } sIn.release(); } System.out.println("... connected "+toString()); return super.getResponseCode(); }
public void updateSetView(final boolean reset) { SwingUtilities.invokeLater(new Runnable() { public void run() { if(!jwtArea.getText().equals(jwtIM.getJWTJSON())){ jwtArea.setText(jwtIM.getJWTJSON()); } keyField.setText(jwtIM.getJWTKey()); if(reset){ rdbtnDontModifySignature.setSelected(true); keyField.setText(""); keyField.setEnabled(false); } jwtArea.setCaretPosition(0); lblProblem.setText(jwtIM.getProblemDetail()); if(jwtIM.getcFW().isCookie()){ lblCookieFlags.setText(jwtIM.getcFW().toHTMLString()); }else{ lblCookieFlags.setText(""); } lbRegisteredClaims.setText(jwtIM.getTimeClaimsAsText()); } }); }
public static void main(final String[] args) throws InvocationTargetException, InterruptedException { SwingUtilities.invokeAndWait(() -> { frame = new JFrame(); frame.add(new JButton() { @Override protected void paintComponent(final Graphics g) { Graphics gg = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB).createGraphics(); super.paintComponent(gg); gg.dispose(); } }); frame.setSize(300, 300); frame.setLocationRelativeTo(null); frame.setVisible(true); }); sleep(); SwingUtilities.invokeAndWait(() -> { if (frame != null) { frame.dispose(); } }); }
@Test public void testOverridenGetTargetNames() throws Exception { assertNotNull(ap); final Logger log = Logger.getLogger(ActionProviderSupport.class.getName()); final Level origLevel = log.getLevel(); final MockHandler handler = new MockHandler(); log.setLevel(Level.FINE); log.addHandler(handler); try { SwingUtilities.invokeAndWait(() -> { ap.invokeAction(ActionProvider.COMMAND_CLEAN, Lookup.EMPTY); }); assertEquals("1", handler.props.get("a")); //NOI18N assertEquals("2", handler.props.get("b")); //NOI18N } finally { log.setLevel(origLevel); log.removeHandler(handler); } }
/** * @param args */ public static void main(final String[] vargs) throws Exception { final ArgumentsParser args = ArgumentsParser.load(vargs); args.require(ArgumentsParser.PARAM_CATALOG); // Procedure catalog_proc = args.catalog_db.getProcedures().get("slev"); // Statement catalog_stmt = catalog_proc.getStatements().get("GetStockCount"); // String jsonString = Encoder.hexDecodeToString(catalog_stmt.getMs_fullplan()); // JSONObject jsonObject = new JSONObject(jsonString); // System.err.println(jsonObject.toString(2)); javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { CatalogViewer viewer = new CatalogViewer(args); viewer.setVisible(true); } // RUN }); }
@Override void initialize(final Element element, CompilationController info) { final String labelText = UIUtilities.createHeader((PackageElement) element, info.getElements().isDeprecated(element), false, false, true); final Icon labelIcon = ElementIcons.getElementIcon(element.getKind(), element.getModifiers()); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Dimension preferredSize = label.getPreferredSize(); label.setText(labelText); label.setIcon(labelIcon); label.setPreferredSize(preferredSize); label.setMinimumSize(preferredSize); } }); }
void displaySwitch(final int stage) { SwingUtilities.invokeLater(new Runnable() { public void run() { if (stage == 0) { setQuestionText("Analyze textures to narrow down profile options."); } if (stage == 2) { setQuestionText("Pick profiles that makes sense for your variant."); } textures.setVisible(stage == 0); analyze.setVisible(stage == 0); progress.setVisible(stage == 1); progressLabel.setVisible(stage == 1); targetProfiles.setVisible(stage == 2); potentialProfiles.setVisible(stage == 2); exception.setVisible(stage == 3); partialMatch.setVisible(stage == 2); } }); }
private List<ItemDef> getCollections() { try { final List<ItemDef> collections = data.getSoapSession().getContributableCollections(); final List<ItemDef> filteredCollections = new ArrayList<ItemDef>(); for( ItemDef collection : collections ) { if( !collection.isSystem() ) { filteredCollections.add(collection); } } Collections.sort(filteredCollections, new NumberStringComparator<ItemDef>()); return filteredCollections; } catch( Exception e ) { JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(this), "Error retrieving Item Definitions from the server.", "Error", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } return null; }
@Override protected void componentActivated () { if( null != browserComponent ) { HtmlBrowser.Impl impl = browserComponent.getBrowserImpl(); if( null != impl ) { Component c = impl.getComponent(); if( null != c ) c.requestFocusInWindow(); } } super.componentActivated (); SwingUtilities.invokeLater( new Runnable() { @Override public void run() { setEnableHome(enableHome); setEnableLocation(enableLocation); setToolbarVisible(toolbarVisible); setStatusLineVisible(statusVisible); if( null != urlToLoad ) { setURL(urlToLoad); } urlToLoad = null; } }); }
public static void setCaretOffset(Context context, final int offset) throws Exception { final JEditorPane pane = context.getInstance(JEditorPane.class); StringBuilder sb = null; if (context.isLogOp()) { sb = context.logOpBuilder(); sb.append("SET_CARET_OFFSET: ").append(pane.getCaretPosition()).append(" => ").append(offset).append("\n"); } SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { pane.setCaretPosition(offset); } }); if (context.isLogOp()) { debugCaret(sb, pane); context.logOp(sb); } }
@Override public void eventDispatched(AWTEvent e) { if (e instanceof MouseEvent) { MouseEvent me = (MouseEvent) e; if (!SwingUtilities.isDescendingFrom(me.getComponent(), target)) { return; } if (me.getID() == MouseEvent.MOUSE_RELEASED) { // stop when mouse released mouseOnScreenPoint = null; if (timer.isRunning()) { timer.stop(); } } else if (me.getID() == MouseEvent.MOUSE_DRAGGED && me.getComponent() == target) { mouseOnScreenPoint = me.getLocationOnScreen(); } else if (me.getID() == MouseEvent.MOUSE_PRESSED && me.getComponent() == target) { mouseOnScreenPoint = me.getLocationOnScreen(); timer.start(); } } }