@Override protected void setAndLoadPreferenceFile() { File sharedConfig = null; try { sharedConfig = FileUtil.getFile(FileUtil.PROFILE + Profile.SHARED_CONFIG); if (!sharedConfig.canRead()) { sharedConfig = null; } } catch (FileNotFoundException ex) { // ignore - this only means that sharedConfig does not exist. } super.setAndLoadPreferenceFile(); if (sharedConfig == null && configOK == true && configDeferredLoadOK == true) { // this was logged in the super method if (!GraphicsEnvironment.isHeadless()) { JOptionPane.showMessageDialog( sp, Bundle.getMessage( "SingleConfigMigratedToSharedConfig", ProfileManager.getDefault().getActiveProfile().getName()), jmri.Application.getApplicationName(), JOptionPane.INFORMATION_MESSAGE); } } }
static { /* ensure that the necessary native libraries are loaded */ Toolkit.loadLibraries(); if (!GraphicsEnvironment.isHeadless()) { initIDs(); } }
/** * Asks user to perform "save layer" operations (save on disk and/or upload data to server) before * data layers deletion. * * @param selectedLayers The layers to check. Only instances of {@link AbstractModifiableLayer} * are considered. * @param reason the cause for requesting an action on unsaved modifications * @return {@code true} if there was nothing to save, or if the user wants to proceed to save * operations. {@code false} if the user cancels. * @since 11093 */ public static boolean saveUnsavedModifications( Iterable<? extends Layer> selectedLayers, Reason reason) { if (!GraphicsEnvironment.isHeadless()) { SaveLayersDialog dialog = new SaveLayersDialog(Main.parent); List<AbstractModifiableLayer> layersWithUnmodifiedChanges = new ArrayList<>(); for (Layer l : selectedLayers) { if (!(l instanceof AbstractModifiableLayer)) { continue; } AbstractModifiableLayer odl = (AbstractModifiableLayer) l; if (odl.isModified() && ((!odl.isSavable() && !odl.isUploadable()) || odl.requiresSaveToFile() || (odl.requiresUploadToServer() && !odl.isUploadDiscouraged()))) { layersWithUnmodifiedChanges.add(odl); } } dialog.prepareForSavingAndUpdatingLayers(reason); if (!layersWithUnmodifiedChanges.isEmpty()) { dialog.getModel().populate(layersWithUnmodifiedChanges); dialog.setVisible(true); switch (dialog.getUserAction()) { case PROCEED: return true; case CANCEL: default: return false; } } } return true; }
protected void uninstallDefaults() { super.uninstallDefaults(); if (!GraphicsEnvironment.isHeadless()) { getComponent().setDragEnabled(oldDragState); } }
/** * Direct access to resources. * * @param resource resource URL * @return FXML loader */ @ThreadPolicy(ThreadPolicy.ThreadId.ANY) private FXMLLoader getFXMLLoader(final URL resource) { if (GraphicsEnvironment.isHeadless()) { return null; } return new GuiFXMLLoader(resource, (FXMLListener) getGuiController()); }
@Test public void testGetLeaves() throws Exception { Assume.assumeTrue(!GraphicsEnvironment.isHeadless()); final CatalogTree catalogTree = new CatalogTree(null, new DefaultAppContext(""), null); List<InvDataset> datasets = new ArrayList<InvDataset>(); InvCatalog catalog = new InvCatalogImpl("catalogName", "1.0", new URI("http://x.y")); final InvDataset rootDataset = createDataset(catalog, "first", "OPENDAP"); rootDataset.getDatasets().add(createDataset(catalog, "second", "OPENDAP")); rootDataset.getDatasets().add(createDataset(catalog, "third", "OPENDAP")); datasets.add(rootDataset); catalogTree.setNewRootDatasets(datasets); OpendapLeaf[] leaves = catalogTree.getLeaves(); Arrays.sort( leaves, new Comparator<OpendapLeaf>() { @Override public int compare(OpendapLeaf o1, OpendapLeaf o2) { return o1.getName().compareTo(o2.getName()); } }); assertEquals(2, leaves.length); assertEquals("second", leaves[0].getName()); assertEquals("third", leaves[1].getName()); }
public void addServerTypeToSnooper(PlayerUsageSnooper playerSnooper) { playerSnooper.addStatToSnooper("singleplayer", Boolean.valueOf(this.isSinglePlayer())); playerSnooper.addStatToSnooper("server_brand", this.getServerModName()); playerSnooper.addStatToSnooper( "gui_supported", GraphicsEnvironment.isHeadless() ? "headless" : "supported"); playerSnooper.addStatToSnooper("dedicated", Boolean.valueOf(this.isDedicatedServer())); }
public void b(MojangStatisticsGenerator mojangstatisticsgenerator) { mojangstatisticsgenerator.b("singleplayer", Boolean.valueOf(this.S())); mojangstatisticsgenerator.b("server_brand", this.getServerModName()); mojangstatisticsgenerator.b( "gui_supported", GraphicsEnvironment.isHeadless() ? "headless" : "supported"); mojangstatisticsgenerator.b("dedicated", Boolean.valueOf(this.ad())); }
/** * Attempts to find and activate a service which provides a UI that we can use. * * @param pm The plugin manager to use to load plugins * @param cm The config manager to use to retrieve settings */ protected static void loadUI(final PluginManager pm, final ConfigManager cm) { final List<Service> uis = pm.getServicesByType("ui"); final String desired = cm.getOption("general", "ui"); // First try: go for our desired service type for (Service service : uis) { if (service.getName().equals(desired) && service.activate()) { return; } } // Second try: go for any service type for (Service service : uis) { if (service.activate()) { return; } } if (!GraphicsEnvironment.isHeadless()) { // Show a dialog informing the user that no UI was found. NoUIDialog.displayBlocking(); return; } // Can't find any throw new IllegalStateException("No UIs could be loaded"); }
protected void installDefaults() { if (!GraphicsEnvironment.isHeadless()) { oldDragState = getComponent().getDragEnabled(); getComponent().setDragEnabled(true); } super.installDefaults(); }
@Test public void testCtor() { Assume.assumeFalse(GraphicsEnvironment.isHeadless()); InstanceManager.setDefault( IEEE802154SystemConnectionMemo.class, new IEEE802154SystemConnectionMemo()); IEEE802154MonFrame action = new IEEE802154MonFrame(); Assert.assertNotNull("exists", action); }
public void testMethodCallInSuper() throws Exception { // todo[yole] make this test work in headless if (!GraphicsEnvironment.isHeadless()) { Class cls = loadAndPatchClass("TestMethodCallInSuper.form", "MethodCallInSuperTest"); JDialog instance = (JDialog) cls.newInstance(); assertEquals(1, instance.getContentPane().getComponentCount()); } }
public LGuiStream(int width, int height) { if (GraphicsEnvironment.isHeadless()) { L.og("INTERNAL L ERROR: creating new LGuiStream on headless system "); } this.width = width; this.height = height; }
protected void setDragOffset(Point p) { if (!GraphicsEnvironment.isHeadless()) { if (this.dragWindow == null) { this.dragWindow = createDragWindow(this.toolBar); } this.dragWindow.setOffset(p); } }
private static void warn(String msg, List<SaveLayerInfo> infos, String title) { JPanel panel = new LayerListWarningMessagePanel(msg, infos); // For unit test coverage in headless mode if (!GraphicsEnvironment.isHeadless()) { JOptionPane.showConfirmDialog( Main.parent, panel, title, JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE); } }
/** * Store the contents of a WarrantManager. * * @param o Object to store, of type warrantManager * @return Element containing the complete info */ public Element store(Object o) { Element warrants = new Element("warrants"); warrants.setAttribute("class", "jmri.jmrit.logix.configurexml.WarrantManagerXml"); if (!GraphicsEnvironment.isHeadless()) { storeNXParams(warrants); } WarrantManager manager = (WarrantManager) o; Iterator<String> iter = manager.getSystemNameList().iterator(); while (iter.hasNext()) { String sname = iter.next(); Warrant warrant = manager.getBySystemName(sname); String uname = warrant.getUserName(); if (log.isDebugEnabled()) log.debug("Warrant: sysName= " + sname + ", userName= "******"warrant"); elem.setAttribute("systemName", sname); if (uname == null) uname = ""; if (uname.length() > 0) { elem.setAttribute("userName", uname); } if (warrant instanceof SCWarrant) { elem.setAttribute("wtype", "SC"); elem.setAttribute("timeToPlatform", "" + ((SCWarrant) warrant).getTimeToPlatform()); } else { elem.setAttribute("wtype", "normal"); } String comment = warrant.getComment(); if (comment != null) { Element c = new Element("comment"); c.addContent(comment); elem.addContent(c); } List<BlockOrder> orders = warrant.getBlockOrders(); for (int j = 0; j < orders.size(); j++) { elem.addContent(storeOrder(orders.get(j), "blockOrder")); } BlockOrder viaOrder = warrant.getViaOrder(); if (viaOrder != null) { elem.addContent(storeOrder(viaOrder, "viaOrder")); } BlockOrder avoidOrder = warrant.getAvoidOrder(); if (avoidOrder != null) { elem.addContent(storeOrder(avoidOrder, "avoidOrder")); } List<ThrottleSetting> throttleCmds = warrant.getThrottleCommands(); for (int j = 0; j < throttleCmds.size(); j++) { elem.addContent(storeCommand(throttleCmds.get(j), "throttleCommand")); } elem.addContent(storeTrain(warrant, "train")); // and put this element out warrants.addContent(elem); } return warrants; }
@Test public void testCtor() { Assume.assumeFalse(GraphicsEnvironment.isHeadless()); // infrastructure objects XNetInterfaceScaffold tc = new XNetInterfaceScaffold(new LenzCommandStation()); LV102Frame f = new LV102Frame(); Assert.assertNotNull(f); }
/** Constructor. */ protected HIDServiceImpl() { try { robot = new Robot(); nativeKeyboard = new NativeKeyboard(); } catch (Throwable e) { if (!GraphicsEnvironment.isHeadless()) logger.error("Error when creating Robot/NativeKeyboard instance", e); } }
public MapTransform() { adjustExtent = true; if (!GraphicsEnvironment.isHeadless()) { this.dpi = Toolkit.getDefaultToolkit().getScreenResolution(); } else { LOGGER.trace(I18N.tr("Headless graphics environment, set current DPI to 96.0")); this.dpi = DEFAULT_DPI; } }
@Test public void test_main_online() throws IOException { URL online = new URL("http://luckydonald.github.io/OfflineData.bin"); if (GraphicsEnvironment.isHeadless()) { this.binFileReader = new BinFileReader(online); } else { this.binFileReader = new BinFileReaderGui(online); } do_read_from_bin(); }
@Before public void setUp() throws Exception { // Do not run on headless environment Assume.assumeTrue(!GraphicsEnvironment.isHeadless()); container = new SwingXulLoader().loadXul("resource/documents/menulist.xul"); doc = container.getDocumentRoot(); list = (XulMenuList) doc.getElementById("list"); }
public static void info(final String msg) { if (GraphicsEnvironment.isHeadless()) { System.out.println("+++ " + msg + " +++"); } else { if (instance == null) { instance = new StartUpMonitor(); pwnSplashScreen(); setApplicationType(); } instance.render(msg); } }
/** * Returns an point which has been adjusted to take into account of the desktop bounds, taskbar * and multi-monitor configuration. * * <p>This adustment may be cancelled by invoking the application with * -Djavax.swing.adjustPopupLocationToFit=false */ Point adjustPopupLocationToFitScreen(int xPosition, int yPosition) { Point popupLocation = new Point(xPosition, yPosition); if (popupPostionFixDisabled == true || GraphicsEnvironment.isHeadless()) { return popupLocation; } // Get screen bounds Rectangle scrBounds; GraphicsConfiguration gc = getCurrentGraphicsConfiguration(popupLocation); Toolkit toolkit = Toolkit.getDefaultToolkit(); if (gc != null) { // If we have GraphicsConfiguration use it to get screen bounds scrBounds = gc.getBounds(); } else { // If we don't have GraphicsConfiguration use primary screen scrBounds = new Rectangle(toolkit.getScreenSize()); } // Calculate the screen size that popup should fit Dimension popupSize = JPopupMenu.this.getPreferredSize(); long popupRightX = (long) popupLocation.x + (long) popupSize.width; long popupBottomY = (long) popupLocation.y + (long) popupSize.height; int scrWidth = scrBounds.width; int scrHeight = scrBounds.height; if (!canPopupOverlapTaskBar()) { // Insets include the task bar. Take them into account. Insets scrInsets = toolkit.getScreenInsets(gc); scrBounds.x += scrInsets.left; scrBounds.y += scrInsets.top; scrWidth -= scrInsets.left + scrInsets.right; scrHeight -= scrInsets.top + scrInsets.bottom; } int scrRightX = scrBounds.x + scrWidth; int scrBottomY = scrBounds.y + scrHeight; // Ensure that popup menu fits the screen if (popupRightX > (long) scrRightX) { popupLocation.x = scrRightX - popupSize.width; if (popupLocation.x < scrBounds.x) { popupLocation.x = scrBounds.x; } } if (popupBottomY > (long) scrBottomY) { popupLocation.y = scrBottomY - popupSize.height; if (popupLocation.y < scrBounds.y) { popupLocation.y = scrBounds.y; } } return popupLocation; }
static { JAWTJNILibLoader.loadAWTImpl(); JAWTJNILibLoader.loadNativeWindow("awt"); headlessMode = GraphicsEnvironment.isHeadless(); boolean ok = false; Class jC = null; Method m = null; if (!headlessMode) { try { jC = Class.forName("com.jogamp.opengl.impl.awt.Java2D"); m = jC.getMethod("isQueueFlusherThread", null); ok = true; } catch (Exception e) { } } j2dClazz = jC; isQueueFlusherThread = m; j2dExist = ok; AccessController.doPrivileged( new PrivilegedAction() { public Object run() { try { sunToolkitClass = Class.forName("sun.awt.SunToolkit"); sunToolkitAWTLockMethod = sunToolkitClass.getDeclaredMethod("awtLock", new Class[] {}); sunToolkitAWTLockMethod.setAccessible(true); sunToolkitAWTUnlockMethod = sunToolkitClass.getDeclaredMethod("awtUnlock", new Class[] {}); sunToolkitAWTUnlockMethod.setAccessible(true); } catch (Exception e) { // Either not a Sun JDK or the interfaces have changed since 1.4.2 / 1.5 } return null; } }); boolean _hasSunToolkitAWTLock = false; if (null != sunToolkitAWTLockMethod && null != sunToolkitAWTUnlockMethod) { try { sunToolkitAWTLockMethod.invoke(null, null); sunToolkitAWTUnlockMethod.invoke(null, null); _hasSunToolkitAWTLock = true; } catch (Exception e) { } } hasSunToolkitAWTLock = _hasSunToolkitAWTLock; // useSunToolkitAWTLock = hasSunToolkitAWTLock; useSunToolkitAWTLock = false; }
public static boolean canRunTest(@NotNull Class testCaseClass) { if (GraphicsEnvironment.isHeadless()) { for (Class<?> clazz = testCaseClass; clazz != null; clazz = clazz.getSuperclass()) { if (clazz.getAnnotation(SkipInHeadlessEnvironment.class) != null) { System.out.println( "Class '" + testCaseClass.getName() + "' is skipped because it requires working UI environment"); return false; } } } return true; }
private void createImage() { if (GraphicsEnvironment.isHeadless()) { image = new BufferedImage(coverageWidth, coverageHeight, BufferedImage.TYPE_4BYTE_ABGR); } else { image = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice() .getDefaultConfiguration() .createCompatibleImage(coverageWidth, coverageHeight, Transparency.TRANSLUCENT); } image.setAccelerationPriority(1f); graphics = image.createGraphics(); }
static { /* ensure that the necessary native libraries are loaded */ NativeLibLoader.loadLibraries(); if (!GraphicsEnvironment.isHeadless()) { initIDs(); } final Toolkit tk = Toolkit.getDefaultToolkit(); if (tk instanceof SunToolkit) { cachedNumberOfButtons = ((SunToolkit) tk).getNumberOfButtons(); } else { // It's expected that some toolkits (Headless, // whatever besides SunToolkit) could also operate. cachedNumberOfButtons = 3; } }
@Test public void test_main_offline() throws IOException { File offline = new File("OfflineData.bin"); if (offline.exists() && !offline.isDirectory()) { this.getLogger().info("OfflineData.bin file exists."); if (GraphicsEnvironment.isHeadless()) { this.binFileReader = new BinFileReader(offline); } else { this.binFileReader = new BinFileReaderGui(offline); } do_read_from_bin(); System.out.println(""); } else { getLogger().warning("No OfflineData.bin file!"); } }
public static void assumeNotHeadless() { boolean headless = true; try { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); headless = ge.isHeadless(); } catch (Exception e) { e.printStackTrace(); } catch (Error e) { // Really not sure why this ever happens, maybe just jenkins issues e.printStackTrace(); } if (headless) { System.out.println("You are trying to start a GUI in a headless environment. Aborting test"); } org.junit.Assume.assumeTrue(!headless); }
/** * Get the default instance of the NXFrame. * * @return the default instance or null if in headless mode */ public static NXFrame getDefault() { if (GraphicsEnvironment.isHeadless()) { return null; } NXFrame instance = InstanceManager.getOptionalDefault(NXFrame.class) .orElseGet( () -> { return InstanceManager.setDefault(NXFrame.class, new NXFrame()); }); if (!instance.isVisible()) { instance.setTrainInfo(null); instance.clearRoute(); } return instance; }