org.openide.util.Utilities Java Examples

The following examples show how to use org.openide.util.Utilities. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Util.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Tries to set default L&F according to platform.
 * Uses:
 *   Metal L&F on Linux and Solaris
 *   Windows L&F on Windows
 *   Aqua L&F on Mac OS X
 *   System L&F on other OS
 */
public static void setDefaultLookAndFeel () {
    String uiClassName;
    if (Utilities.isWindows()) {
        uiClassName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"; //NOI18N
    } else if (Utilities.isMac()) {
        uiClassName = "com.apple.laf.AquaLookAndFeel"; //NOI18N
    } else if (Utilities.isUnix()) {
        uiClassName = "javax.swing.plaf.metal.MetalLookAndFeel"; //NOI18N
    } else {
        uiClassName = UIManager.getSystemLookAndFeelClassName();
    }
    if (uiClassName.equals(UIManager.getLookAndFeel().getClass().getName())) {
        //Desired L&F is already set
        return;
    }
    try {
        UIManager.setLookAndFeel(uiClassName);
    } catch (Exception ex) {
        System.err.println("Cannot set L&F " + uiClassName); //NOI18N
        System.err.println("Exception:" + ex.getMessage()); //NOI18N
        ex.printStackTrace();
    }
}
 
Example #2
Source File: FilesystemHandler.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Tries to determine if the <code>file</code> is supposed to be really removed by svn or not.<br/>
 * i.e. unversioned files should not be removed at all.
 * @param file file sheduled for removal
 * @return <code>true</code> if the <code>file</code> shall be really removed, <code>false</code> otherwise.
 */
private boolean shallRemove(SvnClient client, File file) throws SVNClientException {
    boolean retval = true;
    if (!"true".equals(System.getProperty("org.netbeans.modules.subversion.deleteMissingFiles", "false"))) { //NOI18N
        // prevents automatic svn remove for those who dislike such behavior
        Subversion.LOG.log(Level.FINE, "File {0} deleted externally, metadata not repaired (org.netbeans.modules.subversion.deleteMissingFiles=false by default)", new String[] {file.getAbsolutePath()}); //NOI18N
        retval = false;
    } else {
        ISVNStatus status = getStatus(client, file);
        if (!SVNStatusKind.MISSING.equals(status.getTextStatus())) {
            Subversion.LOG.fine(" shallRemove: skipping delete due to correct metadata");
            retval = false;
        } else if (Utilities.isMac() || Utilities.isWindows()) {
            String existingFilename = FileUtils.getExistingFilenameInParent(file);
            if (existingFilename != null) {
                retval = false;
            }
        }
    }
    return retval;
}
 
Example #3
Source File: JavadocForBinaryImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Find Javadoc roots for classpath extensions ("wrapped" JARs) of the project
 * added by naming convention <tt>&lt;jar name&gt;-javadoc(.zip)</tt>
 * See issue #66275
 * @param binaryRoot
 * @return
 */
private Result findForCPExt(URL binaryRoot) {
    URL jar = FileUtil.getArchiveFile(binaryRoot);
    if (jar == null)
        return null;    // not a class-path-extension
    File binaryRootF = Utilities.toFile(URI.create(jar.toExternalForm()));
    // XXX this will only work for modules following regular naming conventions:
    String n = binaryRootF.getName();
    if (!n.endsWith(".jar")) { // NOI18N
        // ignore
        return null;
    }
    // convention-over-cfg per mkleint's suggestion: <jarname>-javadoc(.zip) folder or ZIP
    File jFolder = new File(binaryRootF.getParentFile(), 
            n.substring(0, n.length() - ".jar".length()) + "-javadoc");
    if (jFolder.isDirectory()) {
            return new R(new URL[]{FileUtil.urlForArchiveOrDir(jFolder)});
    } else {
        File jZip = new File(jFolder.getAbsolutePath() + ".zip");
        if (jZip.isFile()) {
            return new R(new URL[]{FileUtil.urlForArchiveOrDir(jZip)});
        }
    }
    return null;
}
 
Example #4
Source File: ChromeBrowser.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a new instance of BrowserImpl implementation.
 * @throws UnsupportedOperationException when method is called and OS is not Windows.
 * @return browserImpl implementation of browser.
 */
@Override
public HtmlBrowser.Impl createHtmlBrowserImpl() {
    ExtBrowserImpl impl = null;

    if (org.openide.util.Utilities.isWindows ()) {
        impl = new NbDdeBrowserImpl (this);
    } else if (Utilities.isMac()) {
        impl = new MacBrowserImpl(this);
    } else if (Utilities.isUnix() && !Utilities.isMac()) {
        impl = new UnixBrowserImpl(this);
    } else {
        throw new UnsupportedOperationException (NbBundle.
                getMessage(FirefoxBrowser.class, "MSG_CannotUseBrowser"));  // NOI18N
    }
    
    return impl;
}
 
Example #5
Source File: EditorContextDispatcher.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private EditorContextDispatcher() {
    refreshProcessor = new RequestProcessor("Refresh Editor Context", 1);   // NOI18N
    
    resFileObject = Utilities.actionsGlobalContext().lookupResult(FileObject.class);
    EditorLookupListener ell = new EditorLookupListener(FileObject.class);
    resFileObject.addLookupListener(ell);
    ell.lookupChanged(false); // To initialize data
    
    erListener = new EditorRegistryListener();
    EditorRegistry.addPropertyChangeListener(WeakListeners.propertyChange(erListener, EditorRegistry.class));
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            // To initialize data:
            ((EditorRegistryListener) erListener).update(false);
        }
    });
    
}
 
Example #6
Source File: SourceForBinaryQueryTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testSFBQDelegatingImpl2 () throws Exception {
    DelegatingSFBImpl.impl = new LeafSFBQImpl();
    MockServices.setServices(DelegatingSFBImpl.class);
    SourceForBinaryQuery.Result2 res = SourceForBinaryQuery.findSourceRoots2(br1.toURL());
    assertNotNull(res);
    assertEquals(1, res.getRoots().length);
    assertEquals(Collections.singletonList(sr1), Arrays.asList(res.getRoots()));
    assertFalse(res.preferSources());
    
    res = SourceForBinaryQuery.findSourceRoots2(br2.toURL());
    assertNotNull(res);
    assertEquals(1, res.getRoots().length);
    assertEquals(Collections.singletonList(sr2), Arrays.asList(res.getRoots()));
    assertTrue(res.preferSources());
    
    res = SourceForBinaryQuery.findSourceRoots2(Utilities.toURI(getWorkDir()).toURL());
    assertNotNull(res);
    assertEquals(0, res.getRoots().length);
    assertFalse(res.preferSources());
}
 
Example #7
Source File: CategoryDescriptor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private MouseListener createMouseListener() {
    return new MouseAdapter() {
        public void mouseClicked(MouseEvent event) {
            if (SwingUtilities.isRightMouseButton(event)) {
                JComponent comp = (JComponent)event.getSource();
                Item item = null;
                if (comp instanceof JList) {
                    JList list = (JList)comp;
                    Point p = event.getPoint();
                    int index = list.locationToIndex(p);
                    if (index >= 0 && !list.getCellBounds(index, index).contains(p)) {
                        index = -1;
                    }
                    if (index >= 0) {
                        item = (Item)list.getModel().getElementAt(index);
                    }
                }
                Action[] actions = null == item ? category.getActions() : item.getActions();
                JPopupMenu popup = Utilities.actionsToPopup( actions, getComponent() );
                Utils.addCustomizationMenuItems( popup, getPalettePanel().getController(), getPalettePanel().getSettings() );
                popup.show(comp, event.getX(), event.getY());
            }
        }
    };
}
 
Example #8
Source File: ContextActionTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testContextInstancesDoNotInterfereWithEachOtherOrParent() throws Exception {
    System.out.println("testContextInstancesDoNotInterfereWithEachOtherOrParent");
    A a = new A();
    assertNull(Utilities.actionsGlobalContext().lookup(String.class)); //sanity check
    assertEquals("A", a.getValue(Action.NAME));
    Action a1 = a.createContextAwareInstance(Lookup.EMPTY);
    assertFalse(a.isEnabled());
    assertEquals("A", a1.getValue(Action.NAME));
    Action a2 = a.createContextAwareInstance(Lookups.fixed("testGeneralBehavior"));
    assertTrue(a2.isEnabled());
    assertFalse(a.isEnabled());
    setContent("foo");
    assertTrue(a.isEnabled());
    assertFalse(a1.isEnabled());
    assertTrue(a2.isEnabled());
    clearContent();
    assertFalse(a.isEnabled());
    assertTrue(a2.isEnabled());
}
 
Example #9
Source File: OrderingItemPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void check() {
    if (desc == null)
        return;

    NotificationLineSupport supp = desc.getNotificationLineSupport();
    if (rbName.isSelected()) {
        String s = tfNameRef.getText();
        if (s == null || s.length() < 1) {
            supp.setInformationMessage(NbBundle.getMessage(OrderingItemPanel.class, "ERR_NO_NAME"));
            desc.setValid(false);
            return;
        }
        if (!Utilities.isJavaIdentifier(s)) {
            supp.setErrorMessage(NbBundle.getMessage(OrderingItemPanel.class, "ERR_WRONG_NAME"));
            desc.setValid(false);
            return;
        }
    }
    supp.clearMessages();
    desc.setValid(true);
}
 
Example #10
Source File: HudsonGitSCMTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testForFolder() throws Exception {
    TestFileUtils.writeFile(new File(getWorkDir(), ".git/config"),
              "[core]\n"
            + "\trepositoryformatversion = 0\n"
            + "[remote \"origin\"]\n"
            + "\tfetch = +refs/heads/*:refs/remotes/origin/*\n"
            + "\turl = [email protected]:x/y.git\n"
            + "[branch \"master\"]\n"
            + "\tremote = origin\n"
            + "\tmerge = refs/heads/master\n");
    // ref: http://www.kernel.org/pub/software/scm/git/docs/git-clone.html#_git_urls_a_id_urls_a
    assertEquals("ssh://[email protected]/x/y.git", String.valueOf(HudsonGitSCM.getRemoteOrigin(Utilities.toURI(getWorkDir()), null)));
    HudsonSCM.Configuration cfg = new HudsonGitSCM().forFolder(getWorkDir());
    assertNotNull(cfg);
    Document doc = XMLUtil.createDocument("whatever", null, null, null);
    cfg.configure(doc);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XMLUtil.write(doc, baos, "UTF-8");
    String text = baos.toString("UTF-8");
    assertTrue(text, text.contains("x/y.git"));
}
 
Example #11
Source File: Win32Protect.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public @Override boolean enabled() {
    if (!Utilities.isWindows()) {
        LOG.fine("not running on Windows");
        return false;
    }
    if (Boolean.getBoolean("netbeans.keyring.no.native")) {
        LOG.fine("native keyring integration disabled");
        return false;
    }
    try {
        if (CryptLib.INSTANCE == null) {
            LOG.fine("loadLibrary -> null");
            return false;
        }
        return true;
    } catch (Throwable t) {
        LOG.log(Level.FINE, null, t);
        return false;
    }
}
 
Example #12
Source File: URLsAreEqualTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testURLsAreEqual() throws Exception {
    final File wd = new File(getWorkDir(), "work#dir");
    wd.mkdirs();
    
    File jar = new File(wd, "default-package-resource.jar");
    
    URL orig = new URL("jar:" + Utilities.toURI(jar) + "!/package/resource.txt");
    URLConnection conn = orig.openConnection();
    assertFalse("JDK connection: " + conn, conn.getClass().getName().startsWith("org.netbeans"));
    
    
    TestFileUtils.writeZipFile(jar, "package/resource.txt:content", "root.txt:empty");
    JarClassLoader jcl = new JarClassLoader(Collections.singletonList(jar), new ProxyClassLoader[0]);

    URL root = jcl.getResource("root.txt");
    URL u = new URL(root, "/package/resource.txt");
    assertNotNull("Resource found", u);
    URLConnection uC = u.openConnection();
    assertTrue("Our connection: " + uC, uC.getClass().getName().startsWith("org.netbeans"));

    assertEquals("Both URLs are equal", u, orig);
    assertEquals("Equality is symetrical", orig, u);
}
 
Example #13
Source File: CompileClassPathImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
URI[] createPath() {
    List<URI> lst = new ArrayList<>();
    boolean broken = getCompileArtifacts(getMavenProject().getOriginalMavenProject(), lst);
    if(addOutputDir) {
        lst.add(Utilities.toURI(getProject().getProjectWatcher().getOutputDirectory(false)));
    }
    
    if (incomplete != broken) {
        incomplete = broken;
        firePropertyChange(PROP_FLAGS, null, null);
    }
    URI[] uris = new URI[lst.size()];
    uris = lst.toArray(uris);
    return uris;
}
 
Example #14
Source File: FilterTopComponent.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void resultChanged(LookupEvent lookupEvent) {
    setChain(Utilities.actionsGlobalContext().lookup(FilterChain.class));
/*
EditorTopComponent tc = EditorTopComponent.getActive();
if (tc != null) {
setChain(tc.getFilterChain());
}*/
}
 
Example #15
Source File: CountingSecurityManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean startsWith(String ths, String with) {
    if (Utilities.isWindows()) {
        return ths.toUpperCase().startsWith(with.toUpperCase());
    } else {
        return ths.startsWith(with);
    }
}
 
Example #16
Source File: XMLHintPreferences.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static HintPreferencesProviderImpl from(@NonNull URI settings) {
    Reference<HintPreferencesProviderImpl> ref = uri2Cache.get(settings);
    HintPreferencesProviderImpl cachedResult = ref != null ? ref.get() : null;
    
    if (cachedResult != null) return cachedResult;
    
    Document doc = null;
    File file = Utilities.toFile(settings); //XXX: non-file:// scheme
    
    if (file.canRead()) {
        try(InputStream in = new BufferedInputStream(new FileInputStream(file))) {
            doc = XMLUtil.parse(new InputSource(in), false, false, null, EntityCatalog.getDefault());
        } catch (SAXException | IOException ex) {
            LOG.log(Level.FINE, null, ex);
        }
    }
    
    if (doc == null) {
        doc = XMLUtil.createDocument("configuration", null, "-//NetBeans//DTD Tool Configuration 1.0//EN", "http://www.netbeans.org/dtds/ToolConfiguration-1_0.dtd");
    }
    
    synchronized (uri2Cache) {
        ref = uri2Cache.get(settings);
        cachedResult = ref != null ? ref.get() : null;

        if (cachedResult != null) return cachedResult;
        
        uri2Cache.put(settings, new CleaneableSoftReference(cachedResult = new HintPreferencesProviderImpl(settings, doc), settings));
    }
    
    return cachedResult;
}
 
Example #17
Source File: ShellConstructor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static String quoteSpaces(String val, String quote) {
    if (Utilities.isWindows()) {
        //since #228901 always quote
        //#208065 not only space but a few other characters are to be quoted..
        //if (val.indexOf(' ') != -1 || val.indexOf('=') != -1 || val.indexOf(";") != -1 || val.indexOf(",") != -1) { //NOI18N
            return quote + val + quote;
        //}
    }
    return val;
}
 
Example #18
Source File: WorkspaceParser.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void parseJSFLibraryRegistryV2() throws IOException {
    if (!workspace.getUserJSFLibraries().exists()) {
        return;
    }
    Document xml;
    try {
        xml = XMLUtil.parse(new InputSource(Utilities.toURI(workspace.getUserJSFLibraries()).toString()), false, true, XMLUtil.defaultErrorHandler(), null);
    } catch (SAXException e) {
        IOException ioe = (IOException) new IOException(workspace.getUserJSFLibraries() + ": " + e.toString()).initCause(e); // NOI18N
        throw ioe;
    }
    
    Element root = xml.getDocumentElement();
    if (!"JSFLibraryRegistry".equals(root.getLocalName()) || // NOI18N
        !JSF_LIB_NS.equals(root.getNamespaceURI())) {
        return;
    }
    for (Element el : XMLUtil.findSubElements(root)) {
        String libraryName = el.getAttribute("Name"); // NOI18N
        List<String> jars = new ArrayList<String>();
        for (Element file : XMLUtil.findSubElements(el)) {
            String path = file.getAttribute("SourceLocation"); // NOI18N
            if (!"false".equals(file.getAttribute("RelativeToWorkspace"))) { // NOI18N
                path = new File(workspace.getDirectory(), path).getPath();
            }
            jars.add(path);
        }
        // TODO: in Ganymede Javadoc/sources customization does not seem to be persisted. eclipse defect??
        workspace.addUserLibrary(libraryName, jars, null, null);
    }
}
 
Example #19
Source File: KillAction.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
private void refreshJvms() throws IOException {
    String javaSub = Utilities.isWindows() ? "bin\\java.exe" : "bin/java"; // NOI18N
    File java = new File(System.getProperty("java.home"), javaSub); // NOI18N

    if (java.isFile()) {
        String command[] = {java.getAbsolutePath(), "-version"};
        Runtime.getRuntime().exec(command);
    }
}
 
Example #20
Source File: CountingSecurityManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean inSubtree(String file, String dir) {
    if (Utilities.isWindows()) {
        file = file.replace(File.separatorChar, '/').toLowerCase(Locale.ENGLISH);
        dir = dir.replace(File.separatorChar, '/').toLowerCase(Locale.ENGLISH);
    }
    return file.startsWith(dir);
}
 
Example #21
Source File: WindowsSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void init() {
    init(null);

    if (Utilities.isWindows()) {
        if (activeShell == null) {
            log.fine("WindowsSupport: no shell found"); // NOI18N
        } else {
            log.log(Level.FINE, "WindowsSupport: found {0} shell in {1}", new Object[]{activeShell.type, activeShell.bindir.getAbsolutePath()}); // NOI18N
        }
    }
}
 
Example #22
Source File: PersistenceManagerBeanDataNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public PersistenceManagerBeanDataNode(SunResourceDataObject obj, PersistenceManagerBean key) {
    super(obj);
    setIconBaseWithExtension("org/netbeans/modules/j2ee/sun/share/resources/ResNodeNodeIcon.gif"); //NOI18N
    setShortDescription (NbBundle.getMessage (PersistenceManagerBeanDataNode.class, "DSC_PersistenceManagerNode"));//NOI18N
    resource = key;
    
    key.addPropertyChangeListener(this);
    Class<?> clazz = key.getClass ();
    try{
        createProperties(key, Utilities.getBeanInfo(clazz));
    } catch (Exception e){
        e.printStackTrace();
    }
    
}
 
Example #23
Source File: AbstractAddMethodStrategy.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected static MethodsNode getMethodsNode() {
    Node[] nodes = Utilities.actionsGlobalContext().lookup(new Lookup.Template<Node>(Node.class)).allInstances().toArray(new Node[0]);
    if (nodes.length != 1) {
        return null;
    }
    return nodes[0].getLookup().lookup(MethodsNode.class);
}
 
Example #24
Source File: PlatformSourceForBinaryQueryTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testTwoPlatformsoverSameSDKPlatformChange() throws Exception {
    final File binDir = new File(getWorkDir(),"boot");  //NOI18N
    binDir.mkdir();
    final File jdocFile1 = new File(getWorkDir(),"src1");   //NOI18N
    jdocFile1.mkdir();
    final File jdocFile2 = new File(getWorkDir(),"src2");  //NOI18N
    jdocFile2.mkdir();
    final TestJavaPlatformProvider provider = TestJavaPlatformProvider.getDefault();
    provider.reset();
    final URL binRoot = Utilities.toURI(binDir).toURL();
    final ClassPath bootCp = ClassPathSupport.createClassPath(binRoot);
    final ClassPath src1 = ClassPathSupport.createClassPath(Utilities.toURI(jdocFile1).toURL());
    final ClassPath src2 = ClassPathSupport.createClassPath(Utilities.toURI(jdocFile2).toURL());
    final TestJavaPlatform platform1 = new TestJavaPlatform("platform1", bootCp);   //NOI18N
    final TestJavaPlatform platform2 = new TestJavaPlatform("platform2", bootCp);   //NOI18N
    platform1.setSources(src1);
    platform2.setSources(src2);
    provider.addPlatform(platform1);
    provider.addPlatform(platform2);

    final SourceForBinaryQuery.Result result1 = SourceForBinaryQuery.findSourceRoots(binRoot);
    assertEquals(Arrays.asList(src1.getRoots()), Arrays.asList(result1.getRoots()));

    provider.removePlatform(platform1);
    assertEquals(Arrays.asList(src2.getRoots()), Arrays.asList(result1.getRoots()));

    final SourceForBinaryQuery.Result result2 = SourceForBinaryQuery.findSourceRoots(binRoot);
    assertEquals(Arrays.asList(src2.getRoots()), Arrays.asList(result2.getRoots()));

    provider.insertPlatform(platform2, platform1);
    assertEquals(Arrays.asList(src1.getRoots()), Arrays.asList(result1.getRoots()));
    assertEquals(Arrays.asList(src1.getRoots()), Arrays.asList(result2.getRoots()));
}
 
Example #25
Source File: Hk2JavaEEPlatformImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void addURL(final Collection<URL> urls, final File file ){
    if ( file == null || !file.exists()) {
        return;
    }
    try {
        urls.add(Utilities.toURI(file).toURL());
    } catch (MalformedURLException ex) {
        // ignore the file
    }
}
 
Example #26
Source File: AutomaticRegistration.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Registers the server instance file object and set the default properties.
 *
 * @param serverInstanceDir /J2EE/InstalledServers folder
 * @param url server instance url/ID
 * @param displayName display name
 */
private static boolean registerServerInstanceFO(FileObject serverInstanceDir, String url,
        String displayName, String serverRoot, String domainRoot, String domainName,
        String port, String username, String password, String javaOpts, Version version) {

    String name = FileUtil.findFreeFileName(serverInstanceDir, "weblogic_autoregistered_instance", null); // NOI18N
    FileObject instanceFO;
    try {
        instanceFO = serverInstanceDir.createData(name);
        instanceFO.setAttribute(InstanceProperties.URL_ATTR, url);
        instanceFO.setAttribute(InstanceProperties.USERNAME_ATTR, username);
        instanceFO.setAttribute(InstanceProperties.PASSWORD_ATTR, password);
        instanceFO.setAttribute(InstanceProperties.DISPLAY_NAME_ATTR, displayName);
        instanceFO.setAttribute(InstanceProperties.HTTP_PORT_NUMBER, port);
        instanceFO.setAttribute(WLPluginProperties.SERVER_ROOT_ATTR, serverRoot);
        instanceFO.setAttribute(WLPluginProperties.DOMAIN_ROOT_ATTR, domainRoot);
        instanceFO.setAttribute(WLPluginProperties.DEBUGGER_PORT_ATTR,
                WLInstantiatingIterator.DEFAULT_DEBUGGER_PORT);
        instanceFO.setAttribute(WLPluginProperties.PROXY_ENABLED,
                WLInstantiatingIterator.DEFAULT_PROXY_ENABLED);
        instanceFO.setAttribute(WLPluginProperties.DOMAIN_NAME, domainName);
        instanceFO.setAttribute(WLPluginProperties.PORT_ATTR, port);
        if (javaOpts != null) {
            instanceFO.setAttribute(WLPluginProperties.JAVA_OPTS, javaOpts);
        }
        if (Utilities.isMac()) {
            StringBuilder memOpts = new StringBuilder(WLInstantiatingIterator.DEFAULT_MAC_MEM_OPTS_HEAP);
            if (version != null && !JDK8_ONLY_SERVER_VERSION.isBelowOrEqual(version)) {
                memOpts.append(' '); // NOI18N
                memOpts.append(WLInstantiatingIterator.DEFAULT_MAC_MEM_OPTS_PERM);
            }
            instanceFO.setAttribute(WLPluginProperties.MEM_OPTS, memOpts.toString());
        }
        return true;
    } catch (IOException e) {
        LOGGER.log(Level.INFO, "Cannot register the default WebLogic server."); // NOI18N
        LOGGER.log(Level.INFO, null, e);
    }
    return false;
}
 
Example #27
Source File: KeyStrokeUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Get human-readable name for a {@link KeyStroke}.
 */
public static String getKeyStrokeAsText(@NonNull KeyStroke keyStroke) {
    int modifiers = keyStroke.getModifiers ();
    StringBuilder sb = new StringBuilder ();
    if ((modifiers & InputEvent.CTRL_DOWN_MASK) > 0) {
        sb.append(EMACS_CTRL);
    }
    if ((modifiers & InputEvent.ALT_DOWN_MASK) > 0) {
        sb.append(STRING_ALT);
    }
    if ((modifiers & InputEvent.SHIFT_DOWN_MASK) > 0) {
        sb.append (EMACS_SHIFT);
    }
    if ((modifiers & InputEvent.META_DOWN_MASK) > 0) {
        sb.append(STRING_META);
    }
    if (keyStroke.getKeyCode () != KeyEvent.VK_SHIFT &&
        keyStroke.getKeyCode () != KeyEvent.VK_CONTROL &&
        keyStroke.getKeyCode () != KeyEvent.VK_META &&
        keyStroke.getKeyCode () != KeyEvent.VK_ALT &&
        keyStroke.getKeyCode () != KeyEvent.VK_ALT_GRAPH) {
        sb.append (Utilities.keyToString (
            KeyStroke.getKeyStroke (keyStroke.getKeyCode (), 0)
        ));
    }
    return sb.toString ();
}
 
Example #28
Source File: UINodeTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static final java.awt.image.BufferedImage createBufferedImage(int width, int height) {
    if (Utilities.isMac()) {
        return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE);
    }

    ColorModel model = colorModel(java.awt.Transparency.TRANSLUCENT);
    java.awt.image.BufferedImage buffImage = new java.awt.image.BufferedImage(
            model, model.createCompatibleWritableRaster(width, height), model.isAlphaPremultiplied(), null
        );

    return buffImage;
}
 
Example #29
Source File: JSEApplicationClassChooser.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Returns error message or null if no error occurred
 */
String isNewClassValid() {
    if(!radioButtonNewClass.isSelected()) {
        return null;
    }
    if (!Utilities.isJavaIdentifier(getNewClassName())) {
        return NbBundle.getMessage(JSEApplicationClassChooser.class, "WARN_Provide_Java_Class_Name"); // NOI18N
    }
    return FXMLTemplateWizardIterator.canUseFileName(FileUtil.toFile(support.getCurrentChooserFolder()), getNewClassName() + JAVA_FILE_EXTENSION);
}
 
Example #30
Source File: ProjectOpenedHookImplTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testRegistrationOfSubmodules() throws Exception { // #200445
    TestFileUtils.writeFile(d, "pom.xml", "<project xmlns='http://maven.apache.org/POM/4.0.0'><modelVersion>4.0.0</modelVersion>" +
            "<groupId>g</groupId><artifactId>p</artifactId><version>0</version>" +
            "<packaging>pom</packaging><profiles><profile><id>special</id><modules><module>p2</module></modules></profile></profiles>" +
            "</project>");
    TestFileUtils.writeFile(d, "p2/pom.xml", "<project xmlns='http://maven.apache.org/POM/4.0.0'><modelVersion>4.0.0</modelVersion>" +
            "<parent><groupId>g</groupId><artifactId>p</artifactId><version>0</version></parent><artifactId>p2</artifactId>" +
            "<packaging>pom</packaging><modules><module>m</module></modules>" +
            "</project>");
    TestFileUtils.writeFile(d, "p2/m/pom.xml", "<project xmlns='http://maven.apache.org/POM/4.0.0'><modelVersion>4.0.0</modelVersion>" +
            "<groupId>g</groupId><properties><my.name>m</my.name></properties><artifactId>${my.name}</artifactId><version>0</version>" +
            "</project>");
    Project p = ProjectManager.getDefault().findProject(d);
    ProjectOpenedHookImpl pohi = new ProjectOpenedHookImpl((NbMavenProjectImpl) p);
    pohi.projectOpened();
    try {
        File repo = EmbedderFactory.getProjectEmbedder().getLocalRepositoryFile();
        File mArt = new File(repo, "g/m/0/m-0.jar");
        // XXX verify that p2 has not yet been loaded
        Project m = FileOwnerQuery.getOwner(Utilities.toURI(mArt));
        assertNotNull(m);
        assertEquals(d.getFileObject("p2/m"), m.getProjectDirectory());
        File p2Art = new File(repo, "g/p2/0/p2-0.pom");
        Project p2 = FileOwnerQuery.getOwner(Utilities.toURI(p2Art));
        assertNotNull(p2);
        assertEquals(d.getFileObject("p2"), p2.getProjectDirectory());
    } finally {
        pohi.projectClosed();
    }
}