http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/remoting/ide/api/src/org/netbeans/modules/jackpot30/remotingapi/options/IndexPanel.java ---------------------------------------------------------------------- diff --git a/remoting/ide/api/src/org/netbeans/modules/jackpot30/remotingapi/options/IndexPanel.java b/remoting/ide/api/src/org/netbeans/modules/jackpot30/remotingapi/options/IndexPanel.java new file mode 100644 index 0000000..45f50f5 --- /dev/null +++ b/remoting/ide/api/src/org/netbeans/modules/jackpot30/remotingapi/options/IndexPanel.java @@ -0,0 +1,370 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ +package org.netbeans.modules.jackpot30.remotingapi.options; + +import java.io.IOException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import javax.swing.DefaultCellEditor; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.table.AbstractTableModel; +import org.netbeans.api.progress.aggregate.AggregateProgressFactory; +import org.netbeans.api.progress.aggregate.AggregateProgressHandle; +import org.netbeans.api.progress.aggregate.ProgressContributor; +import org.netbeans.modules.jackpot30.remoting.api.LocalServer; +import org.netbeans.modules.jackpot30.remoting.api.RemoteIndex; +import org.netbeans.modules.jackpot30.remoting.api.RemoteIndex.UseLocalCache; +import org.openide.DialogDescriptor; +import org.openide.DialogDisplayer; +import org.openide.execution.ExecutionEngine; +import org.openide.util.Exceptions; +import org.openide.util.Lookup; +import org.openide.windows.InputOutput; + +final class IndexPanel extends javax.swing.JPanel { + + private final IndexOptionsPanelController controller; + + IndexPanel(IndexOptionsPanelController controller) { + this.controller = controller; + initComponents(); + indices.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + public void valueChanged(ListSelectionEvent e) { + enableDisable(); + } + }); + JComboBox cacheEditor = new JComboBox(UseLocalCache.values()); + indices.setDefaultEditor(UseLocalCache.class, new DefaultCellEditor(cacheEditor)); + enableDisable(); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents + private void initComponents() { + + javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane(); + indices = new javax.swing.JTable(); + addButton = new javax.swing.JButton(); + removeButton = new javax.swing.JButton(); + editButton = new javax.swing.JButton(); + synchronizeOffline = new javax.swing.JButton(); + + indices.setModel(new javax.swing.table.DefaultTableModel( + new Object [][] { + {null, null, null, null}, + {null, null, null, null}, + {null, null, null, null}, + {null, null, null, null} + }, + new String [] { + "Title 1", "Title 2", "Title 3", "Title 4" + } + )); + jScrollPane1.setViewportView(indices); + + org.openide.awt.Mnemonics.setLocalizedText(addButton, org.openide.util.NbBundle.getMessage(IndexPanel.class, "IndexPanel.addButton.text")); // NOI18N + addButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + addButtonActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(removeButton, org.openide.util.NbBundle.getMessage(IndexPanel.class, "IndexPanel.removeButton.text")); // NOI18N + removeButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + removeButtonActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(editButton, org.openide.util.NbBundle.getMessage(IndexPanel.class, "IndexPanel.editButton.text")); // NOI18N + editButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + editButtonActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(synchronizeOffline, org.openide.util.NbBundle.getMessage(IndexPanel.class, "IndexPanel.synchronizeOffline.text", new Object[] {})); // NOI18N + synchronizeOffline.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + synchronizeOfflineActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(removeButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(addButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(editButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(synchronizeOffline, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 306, Short.MAX_VALUE) + .addGroup(layout.createSequentialGroup() + .addComponent(addButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(editButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(removeButton) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(synchronizeOffline))) + .addContainerGap()) + ); + }// </editor-fold>//GEN-END:initComponents + + private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed + addEditIndex(false); + }//GEN-LAST:event_addButtonActionPerformed + + private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editButtonActionPerformed + addEditIndex(true); + }//GEN-LAST:event_editButtonActionPerformed + + private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed + TableModelImpl model = (TableModelImpl) indices.getModel(); + + model.indices.remove(indices.getSelectedRow()); + model.fireTableDataChanged(); + }//GEN-LAST:event_removeButtonActionPerformed + + private void synchronizeOfflineActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_synchronizeOfflineActionPerformed + ExecutionEngine.getDefault().execute("Synchronizing remote indices", new Runnable() { + @Override public void run() { + TableModelImpl model = (TableModelImpl) indices.getModel(); + Collection<RemoteIndex> indices = new ArrayList<RemoteIndex>(model.indices); + + for (Iterator<RemoteIndex> it = indices.iterator(); it.hasNext();) { + if (it.next().useLocalCache == UseLocalCache.NEVER) { + it.remove(); + } + } + + ProgressContributor[] contributors = new ProgressContributor[indices.size()]; + + for (int i = 0; i < indices.size(); i++) { + contributors[i] = AggregateProgressFactory.createProgressContributor(String.valueOf(i)); + } + + AggregateProgressHandle h = AggregateProgressFactory.createHandle("Synchronizing remote indices", contributors, null, null); + + h.start(); + + try { + int i = 0; + + for (RemoteIndex idx : indices) { + try { + Lookup.getDefault().lookup(LocalServer.class).downloadIndex(idx, contributors[i++]); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + } finally { + h.finish(); + } + } + }, InputOutput.NULL); + + }//GEN-LAST:event_synchronizeOfflineActionPerformed + + private void addEditIndex(boolean edit) { + JButton okButton = new JButton("OK"); + CustomizeRemoteIndex panel = new CustomizeRemoteIndex(okButton); + DialogDescriptor dd = new DialogDescriptor(panel, edit ? "Edit Index" : "Add Index", true, new Object[] {okButton, DialogDescriptor.CANCEL_OPTION}, okButton, DialogDescriptor.DEFAULT_ALIGN, null, null); + + dd.setClosingOptions(null); + panel.setNotificationSupport(dd.createNotificationLineSupport()); + + TableModelImpl model = (TableModelImpl) indices.getModel(); + + if (edit) { + panel.setIndex(model.indices.get(indices.getSelectedRow())); + } + + if (DialogDisplayer.getDefault().notify(dd) == okButton) { + RemoteIndex remoteIndex = panel.getIndex(); + + if (edit) { + int index = indices.getSelectedRow(); + + model.indices.remove(index); + model.indices.add(index, remoteIndex); + } else { + model.indices.add(remoteIndex); + } + + model.fireTableDataChanged(); + } + } + + private void enableDisable() { + if (indices.getSelectedRow() != (-1)) { + editButton.setEnabled(true); + removeButton.setEnabled(true); + } else { + editButton.setEnabled(false); + removeButton.setEnabled(false); + } + + if (indices.getModel() instanceof TableModelImpl) { + TableModelImpl model = (TableModelImpl) indices.getModel(); + boolean enableDownload = false; + + for (RemoteIndex idx : model.indices) { + enableDownload |= idx.useLocalCache != UseLocalCache.NEVER; + } + + synchronizeOffline.setEnabled(enableDownload); + } + } + + void load() { + TableModelImpl model = new TableModelImpl(); + + for (RemoteIndex idx : RemoteIndex.loadIndices(true)) { + model.indices.add(idx); + } + + indices.setModel(model); + model.fireTableStructureChanged(); + } + + void store() { + TableModelImpl model = (TableModelImpl) indices.getModel(); + + RemoteIndex.saveIndices(model.indices); + } + + boolean valid() { + // TODO check whether form is consistent and complete + return true; + } + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton addButton; + private javax.swing.JButton editButton; + private javax.swing.JTable indices; + private javax.swing.JButton removeButton; + private javax.swing.JButton synchronizeOffline; + // End of variables declaration//GEN-END:variables + + private static final class TableModelImpl extends AbstractTableModel { + + private final List<RemoteIndex> indices = new ArrayList<RemoteIndex>(); + + public int getRowCount() { + return indices.size(); + } + + public int getColumnCount() { + return 5; + } + + public String getColumnName(int columnIndex) { + switch (columnIndex) { + case 0: return ""; + case 1: return "Local folder"; + case 2: return "Remote URL"; + case 3: return "Remote project"; + case 4: return "Use local cache"; + default: throw new IllegalStateException(); + } + } + + public Class<?> getColumnClass(int columnIndex) { + return columnIndex == 0 ? Boolean.class : columnIndex != 4 ? String.class : UseLocalCache.class; + } + + public Object getValueAt(int rowIndex, int columnIndex) { + RemoteIndex idx = indices.get(rowIndex); + + switch (columnIndex) { + case 0: return idx.enabled; + case 1: + URL localFolder = idx.getLocalFolder(); + return localFolder != null ? Utils.toDisplayName(localFolder) : ""; + case 2: return idx.remote.toExternalForm(); + case 3: return idx.remoteSegment; + case 4: return idx.useLocalCache; + default: throw new IllegalStateException(); + } + } + + @Override + public void setValueAt(Object aValue, int rowIndex, int columnIndex) { + RemoteIndex idx = indices.get(rowIndex); + + if (columnIndex == 0) { + idx = RemoteIndex.create(aValue instanceof Boolean ? (Boolean) aValue : true, idx.useLocalCache, idx.getLocalFolder(), idx.remote, idx.remoteSegment); + } else { + idx = RemoteIndex.create(idx.enabled, aValue instanceof UseLocalCache ? (UseLocalCache) aValue : UseLocalCache.NEVER, idx.getLocalFolder(), idx.remote, idx.remoteSegment); + } + indices.set(rowIndex, idx); + } + + @Override + public boolean isCellEditable(int rowIndex, int columnIndex) { + return columnIndex == 0 || columnIndex == 4; + } + + } +}
http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/remoting/ide/api/src/org/netbeans/modules/jackpot30/remotingapi/options/Utils.java ---------------------------------------------------------------------- diff --git a/remoting/ide/api/src/org/netbeans/modules/jackpot30/remotingapi/options/Utils.java b/remoting/ide/api/src/org/netbeans/modules/jackpot30/remotingapi/options/Utils.java new file mode 100644 index 0000000..a7234ee --- /dev/null +++ b/remoting/ide/api/src/org/netbeans/modules/jackpot30/remotingapi/options/Utils.java @@ -0,0 +1,90 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2011 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2011 Sun Microsystems, Inc. + */ +package org.netbeans.modules.jackpot30.remotingapi.options; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.net.URLStreamHandler; + +/** + * + * @author lahvac + */ +public class Utils { + + public static String toDisplayName(URL url) { + if ("file".equals(url.getProtocol())) { + return url.getPath(); + } else { + return url.toExternalForm(); + } + } + + public static URL fromDisplayName(String path) { + try { + return new URL(path); + } catch (MalformedURLException ex) { + try { + if (path.isEmpty()) return File.listRoots()[0].toURI().toURL(); + //local FS path? + return new URL("file://" + path); + } catch (MalformedURLException ex1) { + try { + //no handler? + return new URL(null, path, new FakeURLStreamHandler()); + } catch (MalformedURLException ex2) { + //giving up + throw new IllegalStateException(ex2); + } + } + } + } + + private static final class FakeURLStreamHandler extends URLStreamHandler { + @Override protected URLConnection openConnection(URL u) throws IOException { + throw new UnsupportedOperationException("Not supported yet."); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/remoting/ide/browsing/build.xml ---------------------------------------------------------------------- diff --git a/remoting/ide/browsing/build.xml b/remoting/ide/browsing/build.xml new file mode 100644 index 0000000..90c61ff --- /dev/null +++ b/remoting/ide/browsing/build.xml @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2009-2017 Oracle and/or its affiliates. All rights reserved. + +Oracle and Java are registered trademarks of Oracle and/or its affiliates. +Other names may be trademarks of their respective owners. + +The contents of this file are subject to the terms of either the GNU +General Public License Version 2 only ("GPL") or the Common +Development and Distribution License("CDDL") (collectively, the +"License"). You may not use this file except in compliance with the +License. You can obtain a copy of the License at +http://www.netbeans.org/cddl-gplv2.html +or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the +specific language governing permissions and limitations under the +License. When distributing the software, include this License Header +Notice in each file and include the License file at +nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this +particular file as subject to the "Classpath" exception as provided +by Oracle in the GPL Version 2 section of the License file that +accompanied this code. If applicable, add the following below the +License Header, with the fields enclosed by brackets [] replaced by +your own identifying information: +"Portions Copyrighted [year] [name of copyright owner]" + +Contributor(s): + +The Original Software is NetBeans. The Initial Developer of the Original +Software is Sun Microsystems, Inc. Portions Copyright 2009-2010 Sun +Microsystems, Inc. All Rights Reserved. + +If you wish your version of this file to be governed by only the CDDL +or only the GPL Version 2, indicate your decision by adding +"[Contributor] elects to include this software in this distribution +under the [CDDL or GPL Version 2] license." If you do not indicate a +single choice of license, a recipient has the option to distribute +your version of this file under either the CDDL, the GPL Version 2 or +to extend the choice of license to its licensees as provided above. +However, if you add GPL Version 2 code and therefore, elected the GPL +Version 2 license, then the option applies only if the new code is +made subject to such option by the copyright holder. +--> +<!-- You may freely edit this file. See harness/README in the NetBeans platform --> +<!-- for some information on what you could do (e.g. targets to override). --> +<!-- If you delete this file and reopen the project it will be recreated. --> +<project name="org.netbeans.modules.jackpot30.ide.browsing" default="netbeans" basedir="."> + <description>Builds, tests, and runs the project org.netbeans.modules.jackpot30.ide.browsing.</description> + <import file="nbproject/build-impl.xml"/> + <import file="${suite.dir}/../../findbugs-import.xml"/> +</project> http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/remoting/ide/browsing/manifest.mf ---------------------------------------------------------------------- diff --git a/remoting/ide/browsing/manifest.mf b/remoting/ide/browsing/manifest.mf new file mode 100644 index 0000000..5a53398 --- /dev/null +++ b/remoting/ide/browsing/manifest.mf @@ -0,0 +1,7 @@ +Manifest-Version: 1.0 +OpenIDE-Module: org.netbeans.modules.jackpot30.ide.browsing +OpenIDE-Module-Install: org/netbeans/modules/jackpot30/ide/browsing/Installer.class +OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/jackpot30/ide/browsing/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 +AutoUpdate-Show-In-Client: false + http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/remoting/ide/browsing/nbproject/build-impl.xml ---------------------------------------------------------------------- diff --git a/remoting/ide/browsing/nbproject/build-impl.xml b/remoting/ide/browsing/nbproject/build-impl.xml new file mode 100644 index 0000000..89b234e --- /dev/null +++ b/remoting/ide/browsing/nbproject/build-impl.xml @@ -0,0 +1,88 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2009-2017 Oracle and/or its affiliates. All rights reserved. + +Oracle and Java are registered trademarks of Oracle and/or its affiliates. +Other names may be trademarks of their respective owners. + +The contents of this file are subject to the terms of either the GNU +General Public License Version 2 only ("GPL") or the Common +Development and Distribution License("CDDL") (collectively, the +"License"). You may not use this file except in compliance with the +License. You can obtain a copy of the License at +http://www.netbeans.org/cddl-gplv2.html +or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the +specific language governing permissions and limitations under the +License. When distributing the software, include this License Header +Notice in each file and include the License file at +nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this +particular file as subject to the "Classpath" exception as provided +by Oracle in the GPL Version 2 section of the License file that +accompanied this code. If applicable, add the following below the +License Header, with the fields enclosed by brackets [] replaced by +your own identifying information: +"Portions Copyrighted [year] [name of copyright owner]" + +Contributor(s): + +The Original Software is NetBeans. The Initial Developer of the Original +Software is Sun Microsystems, Inc. Portions Copyright 2009-2010 Sun +Microsystems, Inc. All Rights Reserved. + +If you wish your version of this file to be governed by only the CDDL +or only the GPL Version 2, indicate your decision by adding +"[Contributor] elects to include this software in this distribution +under the [CDDL or GPL Version 2] license." If you do not indicate a +single choice of license, a recipient has the option to distribute +your version of this file under either the CDDL, the GPL Version 2 or +to extend the choice of license to its licensees as provided above. +However, if you add GPL Version 2 code and therefore, elected the GPL +Version 2 license, then the option applies only if the new code is +made subject to such option by the copyright holder. +--> +<!-- +*** GENERATED FROM project.xml - DO NOT EDIT *** +*** EDIT ../build.xml INSTEAD *** +--> +<project name="org.netbeans.modules.jackpot30.ide.browsing-impl" basedir=".."> + <fail message="Please build using Ant 1.7.1 or higher."> + <condition> + <not> + <antversion atleast="1.7.1"/> + </not> + </condition> + </fail> + <property file="nbproject/private/suite-private.properties"/> + <property file="nbproject/suite.properties"/> + <fail unless="suite.dir">You must set 'suite.dir' to point to your containing module suite</fail> + <property file="${suite.dir}/nbproject/private/platform-private.properties"/> + <property file="${suite.dir}/nbproject/platform.properties"/> + <macrodef name="property" uri="http://www.netbeans.org/ns/nb-module-project/2"> + <attribute name="name"/> + <attribute name="value"/> + <sequential> + <property name="@{name}" value="${@{value}}"/> + </sequential> + </macrodef> + <macrodef name="evalprops" uri="http://www.netbeans.org/ns/nb-module-project/2"> + <attribute name="property"/> + <attribute name="value"/> + <sequential> + <property name="@{property}" value="@{value}"/> + </sequential> + </macrodef> + <property file="${user.properties.file}"/> + <nbmproject2:property name="harness.dir" value="nbplatform.${nbplatform.active}.harness.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/> + <nbmproject2:property name="nbplatform.active.dir" value="nbplatform.${nbplatform.active}.netbeans.dest.dir" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/> + <nbmproject2:evalprops property="cluster.path.evaluated" value="${cluster.path}" xmlns:nbmproject2="http://www.netbeans.org/ns/nb-module-project/2"/> + <fail message="Path to 'platform' cluster missing in $${cluster.path} property or using corrupt Netbeans Platform (missing harness)."> + <condition> + <not> + <contains string="${cluster.path.evaluated}" substring="platform"/> + </not> + </condition> + </fail> + <import file="${harness.dir}/build.xml"/> +</project> http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/remoting/ide/browsing/nbproject/genfiles.properties ---------------------------------------------------------------------- diff --git a/remoting/ide/browsing/nbproject/genfiles.properties b/remoting/ide/browsing/nbproject/genfiles.properties new file mode 100644 index 0000000..e346218 --- /dev/null +++ b/remoting/ide/browsing/nbproject/genfiles.properties @@ -0,0 +1,49 @@ +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2009-2017 Oracle and/or its affiliates. All rights reserved. +# +# Oracle and Java are registered trademarks of Oracle and/or its affiliates. +# Other names may be trademarks of their respective owners. +# +# The contents of this file are subject to the terms of either the GNU +# General Public License Version 2 only ("GPL") or the Common +# Development and Distribution License("CDDL") (collectively, the +# "License"). You may not use this file except in compliance with the +# License. You can obtain a copy of the License at +# http://www.netbeans.org/cddl-gplv2.html +# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the +# specific language governing permissions and limitations under the +# License. When distributing the software, include this License Header +# Notice in each file and include the License file at +# nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this +# particular file as subject to the "Classpath" exception as provided +# by Oracle in the GPL Version 2 section of the License file that +# accompanied this code. If applicable, add the following below the +# License Header, with the fields enclosed by brackets [] replaced by +# your own identifying information: +# "Portions Copyrighted [year] [name of copyright owner]" +# +# Contributor(s): +# +# The Original Software is NetBeans. The Initial Developer of the Original +# Software is Sun Microsystems, Inc. Portions Copyright 2009-2010 Sun +# Microsystems, Inc. All Rights Reserved. +# +# If you wish your version of this file to be governed by only the CDDL +# or only the GPL Version 2, indicate your decision by adding +# "[Contributor] elects to include this software in this distribution +# under the [CDDL or GPL Version 2] license." If you do not indicate a +# single choice of license, a recipient has the option to distribute +# your version of this file under either the CDDL, the GPL Version 2 or +# to extend the choice of license to its licensees as provided above. +# However, if you add GPL Version 2 code and therefore, elected the GPL +# Version 2 license, then the option applies only if the new code is +# made subject to such option by the copyright holder. +build.xml.data.CRC32=d895a237 +build.xml.script.CRC32=461c092a [email protected] +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=7c98b9cd +nbproject/build-impl.xml.script.CRC32=3911055f +nbproject/[email protected] http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/remoting/ide/browsing/nbproject/project.properties ---------------------------------------------------------------------- diff --git a/remoting/ide/browsing/nbproject/project.properties b/remoting/ide/browsing/nbproject/project.properties new file mode 100644 index 0000000..b92aeb5 --- /dev/null +++ b/remoting/ide/browsing/nbproject/project.properties @@ -0,0 +1,43 @@ +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2009-2017 Oracle and/or its affiliates. All rights reserved. +# +# Oracle and Java are registered trademarks of Oracle and/or its affiliates. +# Other names may be trademarks of their respective owners. +# +# The contents of this file are subject to the terms of either the GNU +# General Public License Version 2 only ("GPL") or the Common +# Development and Distribution License("CDDL") (collectively, the +# "License"). You may not use this file except in compliance with the +# License. You can obtain a copy of the License at +# http://www.netbeans.org/cddl-gplv2.html +# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the +# specific language governing permissions and limitations under the +# License. When distributing the software, include this License Header +# Notice in each file and include the License file at +# nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this +# particular file as subject to the "Classpath" exception as provided +# by Oracle in the GPL Version 2 section of the License file that +# accompanied this code. If applicable, add the following below the +# License Header, with the fields enclosed by brackets [] replaced by +# your own identifying information: +# "Portions Copyrighted [year] [name of copyright owner]" +# +# Contributor(s): +# +# The Original Software is NetBeans. The Initial Developer of the Original +# Software is Sun Microsystems, Inc. Portions Copyright 2009-2010 Sun +# Microsystems, Inc. All Rights Reserved. +# +# If you wish your version of this file to be governed by only the CDDL +# or only the GPL Version 2, indicate your decision by adding +# "[Contributor] elects to include this software in this distribution +# under the [CDDL or GPL Version 2] license." If you do not indicate a +# single choice of license, a recipient has the option to distribute +# your version of this file under either the CDDL, the GPL Version 2 or +# to extend the choice of license to its licensees as provided above. +# However, if you add GPL Version 2 code and therefore, elected the GPL +# Version 2 license, then the option applies only if the new code is +# made subject to such option by the copyright holder. +javac.source=1.6 +javac.compilerargs=-Xlint -Xlint:-serial http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/remoting/ide/browsing/nbproject/project.xml ---------------------------------------------------------------------- diff --git a/remoting/ide/browsing/nbproject/project.xml b/remoting/ide/browsing/nbproject/project.xml new file mode 100644 index 0000000..64e6a55 --- /dev/null +++ b/remoting/ide/browsing/nbproject/project.xml @@ -0,0 +1,197 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + +Copyright 2009-2017 Oracle and/or its affiliates. All rights reserved. + +Oracle and Java are registered trademarks of Oracle and/or its affiliates. +Other names may be trademarks of their respective owners. + +The contents of this file are subject to the terms of either the GNU +General Public License Version 2 only ("GPL") or the Common +Development and Distribution License("CDDL") (collectively, the +"License"). You may not use this file except in compliance with the +License. You can obtain a copy of the License at +http://www.netbeans.org/cddl-gplv2.html +or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the +specific language governing permissions and limitations under the +License. When distributing the software, include this License Header +Notice in each file and include the License file at +nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this +particular file as subject to the "Classpath" exception as provided +by Oracle in the GPL Version 2 section of the License file that +accompanied this code. If applicable, add the following below the +License Header, with the fields enclosed by brackets [] replaced by +your own identifying information: +"Portions Copyrighted [year] [name of copyright owner]" + +Contributor(s): + +The Original Software is NetBeans. The Initial Developer of the Original +Software is Sun Microsystems, Inc. Portions Copyright 2009-2010 Sun +Microsystems, Inc. All Rights Reserved. + +If you wish your version of this file to be governed by only the CDDL +or only the GPL Version 2, indicate your decision by adding +"[Contributor] elects to include this software in this distribution +under the [CDDL or GPL Version 2] license." If you do not indicate a +single choice of license, a recipient has the option to distribute +your version of this file under either the CDDL, the GPL Version 2 or +to extend the choice of license to its licensees as provided above. +However, if you add GPL Version 2 code and therefore, elected the GPL +Version 2 license, then the option applies only if the new code is +made subject to such option by the copyright holder. +--> +<project xmlns="http://www.netbeans.org/ns/project/1"> + <type>org.netbeans.modules.apisupport.project</type> + <configuration> + <data xmlns="http://www.netbeans.org/ns/nb-module-project/3"> + <code-name-base>org.netbeans.modules.jackpot30.ide.browsing</code-name-base> + <suite-component/> + <module-dependencies> + <dependency> + <code-name-base>org.netbeans.modules.editor</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <release-version>3</release-version> + <specification-version>1.70.0.5.21.40</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.netbeans.modules.editor.lib</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <release-version>3</release-version> + <specification-version>3.33.0.21.40</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.netbeans.modules.editor.lib2</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <release-version>1</release-version> + <specification-version>1.71.0.40</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.netbeans.modules.editor.mimelookup</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <release-version>1</release-version> + <specification-version>1.29</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.netbeans.modules.editor.settings</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <release-version>1</release-version> + <specification-version>1.46</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.netbeans.modules.jackpot30.remoting.api</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>1.11</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.openide.awt</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>7.55</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.openide.dialogs</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>7.28</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.openide.filesystems</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>8.5</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.openide.loaders</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>7.44</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.openide.modules</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>7.39</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.openide.nodes</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>7.33</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.openide.text</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>6.54</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.openide.util</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>8.29</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.openide.util.lookup</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>8.19</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.openide.util.ui</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>9.3</specification-version> + </run-dependency> + </dependency> + <dependency> + <code-name-base>org.openide.windows</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <specification-version>6.60</specification-version> + </run-dependency> + </dependency> + </module-dependencies> + <public-packages/> + </data> + </configuration> +</project> http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/remoting/ide/browsing/nbproject/suite.properties ---------------------------------------------------------------------- diff --git a/remoting/ide/browsing/nbproject/suite.properties b/remoting/ide/browsing/nbproject/suite.properties new file mode 100644 index 0000000..942e12b --- /dev/null +++ b/remoting/ide/browsing/nbproject/suite.properties @@ -0,0 +1,42 @@ +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2009-2017 Oracle and/or its affiliates. All rights reserved. +# +# Oracle and Java are registered trademarks of Oracle and/or its affiliates. +# Other names may be trademarks of their respective owners. +# +# The contents of this file are subject to the terms of either the GNU +# General Public License Version 2 only ("GPL") or the Common +# Development and Distribution License("CDDL") (collectively, the +# "License"). You may not use this file except in compliance with the +# License. You can obtain a copy of the License at +# http://www.netbeans.org/cddl-gplv2.html +# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the +# specific language governing permissions and limitations under the +# License. When distributing the software, include this License Header +# Notice in each file and include the License file at +# nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this +# particular file as subject to the "Classpath" exception as provided +# by Oracle in the GPL Version 2 section of the License file that +# accompanied this code. If applicable, add the following below the +# License Header, with the fields enclosed by brackets [] replaced by +# your own identifying information: +# "Portions Copyrighted [year] [name of copyright owner]" +# +# Contributor(s): +# +# The Original Software is NetBeans. The Initial Developer of the Original +# Software is Sun Microsystems, Inc. Portions Copyright 2009-2010 Sun +# Microsystems, Inc. All Rights Reserved. +# +# If you wish your version of this file to be governed by only the CDDL +# or only the GPL Version 2, indicate your decision by adding +# "[Contributor] elects to include this software in this distribution +# under the [CDDL or GPL Version 2] license." If you do not indicate a +# single choice of license, a recipient has the option to distribute +# your version of this file under either the CDDL, the GPL Version 2 or +# to extend the choice of license to its licensees as provided above. +# However, if you add GPL Version 2 code and therefore, elected the GPL +# Version 2 license, then the option applies only if the new code is +# made subject to such option by the copyright holder. +suite.dir=${basedir}/.. http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/remoting/ide/browsing/src/org/netbeans/modules/jackpot30/ide/browsing/Bundle.properties ---------------------------------------------------------------------- diff --git a/remoting/ide/browsing/src/org/netbeans/modules/jackpot30/ide/browsing/Bundle.properties b/remoting/ide/browsing/src/org/netbeans/modules/jackpot30/ide/browsing/Bundle.properties new file mode 100644 index 0000000..ce8bc9f --- /dev/null +++ b/remoting/ide/browsing/src/org/netbeans/modules/jackpot30/ide/browsing/Bundle.properties @@ -0,0 +1,42 @@ +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +# +# Copyright 2009-2017 Oracle and/or its affiliates. All rights reserved. +# +# Oracle and Java are registered trademarks of Oracle and/or its affiliates. +# Other names may be trademarks of their respective owners. +# +# The contents of this file are subject to the terms of either the GNU +# General Public License Version 2 only ("GPL") or the Common +# Development and Distribution License("CDDL") (collectively, the +# "License"). You may not use this file except in compliance with the +# License. You can obtain a copy of the License at +# http://www.netbeans.org/cddl-gplv2.html +# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the +# specific language governing permissions and limitations under the +# License. When distributing the software, include this License Header +# Notice in each file and include the License file at +# nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this +# particular file as subject to the "Classpath" exception as provided +# by Oracle in the GPL Version 2 section of the License file that +# accompanied this code. If applicable, add the following below the +# License Header, with the fields enclosed by brackets [] replaced by +# your own identifying information: +# "Portions Copyrighted [year] [name of copyright owner]" +# +# Contributor(s): +# +# The Original Software is NetBeans. The Initial Developer of the Original +# Software is Sun Microsystems, Inc. Portions Copyright 2009-2010 Sun +# Microsystems, Inc. All Rights Reserved. +# +# If you wish your version of this file to be governed by only the CDDL +# or only the GPL Version 2, indicate your decision by adding +# "[Contributor] elects to include this software in this distribution +# under the [CDDL or GPL Version 2] license." If you do not indicate a +# single choice of license, a recipient has the option to distribute +# your version of this file under either the CDDL, the GPL Version 2 or +# to extend the choice of license to its licensees as provided above. +# However, if you add GPL Version 2 code and therefore, elected the GPL +# Version 2 license, then the option applies only if the new code is +# made subject to such option by the copyright holder. +OpenIDE-Module-Name=Jackpot 3.0 Remote Browsing http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/remoting/ide/browsing/src/org/netbeans/modules/jackpot30/ide/browsing/ColoringManager.java ---------------------------------------------------------------------- diff --git a/remoting/ide/browsing/src/org/netbeans/modules/jackpot30/ide/browsing/ColoringManager.java b/remoting/ide/browsing/src/org/netbeans/modules/jackpot30/ide/browsing/ColoringManager.java new file mode 100644 index 0000000..9529def --- /dev/null +++ b/remoting/ide/browsing/src/org/netbeans/modules/jackpot30/ide/browsing/ColoringManager.java @@ -0,0 +1,181 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Contributor(s): + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun + * Microsystems, Inc. All Rights Reserved. + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + */ +package org.netbeans.modules.jackpot30.ide.browsing; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.text.AttributeSet; +import org.netbeans.api.editor.mimelookup.MimeLookup; +import org.netbeans.api.editor.mimelookup.MimePath; +import org.netbeans.api.editor.settings.AttributesUtilities; +import org.netbeans.api.editor.settings.FontColorSettings; + +/**Copied from java.editor. + * + * @author Jan Lahoda + */ +public final class ColoringManager { + + public static final String KEY_MARK_OCCURRENCES = "MARK_OCCURRENCES".toLowerCase(); + private static final Map<Set<String>, String> type2Coloring; + + static { + type2Coloring = new LinkedHashMap<Set<String>, String>(); + + put("mod-type-parameter-use", "TYPE_PARAMETER_USE"); + put("mod-type-parameter-declaration", "TYPE_PARAMETER_DECLARATION"); + put("mod-enum-declaration", "ENUM", "DECLARATION"); + put("mod-annotation-type-declaration", "ANNOTATION_TYPE", "DECLARATION"); + put("mod-interface-declaration", "INTERFACE", "DECLARATION"); + put("mod-class-declaration", "CLASS", "DECLARATION"); + put("mod-constructor-declaration", "CONSTRUCTOR", "DECLARATION"); + put("mod-method-declaration", "METHOD", "DECLARATION"); + put("mod-parameter-declaration", "PARAMETER", "DECLARATION"); + put("mod-local-variable-declaration", "LOCAL_VARIABLE", "DECLARATION"); + put("mod-field-declaration", "FIELD", "DECLARATION"); + put("mod-enum", "ENUM"); + put("mod-annotation-type", "ANNOTATION_TYPE"); + put("mod-interface", "INTERFACE"); + put("mod-class", "CLASS"); + put("mod-constructor", "CONSTRUCTOR"); + put("mod-method", "METHOD"); + put("mod-parameter", "PARAMETER"); + put("mod-local-variable", "LOCAL_VARIABLE"); + put("mod-field", "FIELD"); + put("mod-public", "PUBLIC"); + put("mod-protected", "PROTECTED"); + put("mod-package-private", "PACKAGE_PRIVATE"); + put("mod-private", "PRIVATE"); + put("mod-static", "STATIC"); + put("mod-abstract", "ABSTRACT"); + put("mod-deprecated", "DEPRECATED"); + put("mod-undefined", "UNDEFINED"); + put("mod-unused", "UNUSED"); + put("javadoc-identifier", "JAVADOC_IDENTIFIER"); + put("mark-occurrences", KEY_MARK_OCCURRENCES); + } + + private static void put(String coloring, String... attributes) { + for (int i = 0; i < attributes.length; i++) { + attributes[i] = attributes[i].toLowerCase(); + } + type2Coloring.put(new HashSet<String>(Arrays.asList(attributes)), coloring); + } + + public static AttributeSet getColoringImpl(String coloringSpec) { + FontColorSettings fcs = MimeLookup.getLookup(MimePath.get("text/x-java")).lookup(FontColorSettings.class); + + if (fcs == null) { + //in tests: + return AttributesUtilities.createImmutable(); + } + + assert fcs != null; + + List<AttributeSet> attribs = new ArrayList<AttributeSet>(); + + Set<String> spec = new HashSet<String>(Arrays.asList(coloringSpec.split(" "))); + + for (Entry<Set<String>, String> attribs2Colorings : type2Coloring.entrySet()) { + if (spec.containsAll(attribs2Colorings.getKey())) { + String key = attribs2Colorings.getValue(); + + spec.removeAll(attribs2Colorings.getKey()); + + if (key != null) { + AttributeSet colors = fcs.getTokenFontColors(key); + + if (colors == null) { + Logger.getLogger(ColoringManager.class.getName()).log(Level.SEVERE, "no colors for: {0}", key); + continue; + } + + attribs.add(adjustAttributes(colors)); + } + } + } + + for (String tokenSpec : spec) { + AttributeSet colors = fcs.getTokenFontColors(tokenSpec); + + if (colors != null) { + attribs.add(adjustAttributes(colors)); + } + } + + Collections.reverse(attribs); + + AttributeSet result = AttributesUtilities.createComposite(attribs.toArray(new AttributeSet[0])); + + return result; + } + + private static AttributeSet adjustAttributes(AttributeSet as) { + Collection<Object> attrs = new LinkedList<Object>(); + + for (Enumeration<?> e = as.getAttributeNames(); e.hasMoreElements(); ) { + Object key = e.nextElement(); + Object value = as.getAttribute(key); + + if (value != Boolean.FALSE) { + attrs.add(key); + attrs.add(value); + } + } + + return AttributesUtilities.createImmutable(attrs.toArray()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/remoting/ide/browsing/src/org/netbeans/modules/jackpot30/ide/browsing/Highlighting.java ---------------------------------------------------------------------- diff --git a/remoting/ide/browsing/src/org/netbeans/modules/jackpot30/ide/browsing/Highlighting.java b/remoting/ide/browsing/src/org/netbeans/modules/jackpot30/ide/browsing/Highlighting.java new file mode 100644 index 0000000..69c9470 --- /dev/null +++ b/remoting/ide/browsing/src/org/netbeans/modules/jackpot30/ide/browsing/Highlighting.java @@ -0,0 +1,223 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.jackpot30.ide.browsing; + +import org.netbeans.modules.jackpot30.remoting.api.Utilities; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import javax.swing.event.CaretEvent; +import javax.swing.event.CaretListener; +import javax.swing.text.Document; +import javax.swing.text.JTextComponent; +import org.codeviation.pojson.Pojson; +import org.netbeans.api.editor.EditorRegistry; +import org.netbeans.api.editor.mimelookup.MimeRegistration; +import org.netbeans.modules.jackpot30.remoting.api.Utilities.RemoteSourceDescription; +import org.netbeans.modules.jackpot30.remoting.api.RemoteIndex; +import org.netbeans.modules.jackpot30.remoting.api.WebUtilities; +import org.netbeans.spi.editor.highlighting.HighlightsLayer; +import org.netbeans.spi.editor.highlighting.HighlightsLayerFactory; +import org.netbeans.spi.editor.highlighting.ZOrder; +import org.netbeans.spi.editor.highlighting.support.OffsetsBag; +import org.openide.util.Exceptions; +import org.openide.util.RequestProcessor; + +/** + * + * @author lahvac + */ +public class Highlighting { + + @MimeRegistration(mimeType = "text/x-rjava", service = HighlightsLayerFactory.class) + public static class Factory implements HighlightsLayerFactory { + @Override + public HighlightsLayer[] createLayers(Context context) { + return new HighlightsLayer[] { + HighlightsLayer.create(Highlighting.class.getName() + ".coloring", ZOrder.SYNTAX_RACK, true, getColoringBag(context.getDocument())), + HighlightsLayer.create(Highlighting.class.getName() + ".occurrences", ZOrder.CARET_RACK, true, getOccurrencesBag(context.getDocument())) + }; + } + } + + private static final RequestProcessor WORKER = new RequestProcessor(Highlighting.class.getName(), 10, false, false); + + public static void highlight(final Document doc) { + final RemoteSourceDescription rsd = Utilities.remoteSource(doc); + + if (rsd == null) return ; + + WORKER.post(new Runnable() { + @Override public void run() { + doHighlight(doc, rsd.idx, rsd.relative); + } + }); + } + + private static void doHighlight(Document doc, RemoteIndex idx, String relativePath) { + OffsetsBag target = new OffsetsBag(doc); + + try { + URI sourceURI = new URI(idx.remote.toExternalForm() + "/ui/highlightData?path=" + WebUtilities.escapeForQuery(idx.remoteSegment) + "&relative=" + WebUtilities.escapeForQuery(relativePath)); + HighlightData highlightData = Pojson.load(HighlightData.class, sourceURI.toURL().openStream()); + int o = 0; + Iterator<String> categoriesIt = highlightData.categories.iterator(); + Iterator<Long> spansIt = highlightData.spans.iterator(); + + while (categoriesIt.hasNext() && spansIt.hasNext()) { + Long span = spansIt.next(); + target.addHighlight(o, (int) (o + span), ColoringManager.getColoringImpl(categoriesIt.next())); + o += span; + } + } catch (MalformedURLException ex) { + Exceptions.printStackTrace(ex); + } catch (URISyntaxException ex) { + Exceptions.printStackTrace(ex); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + + getColoringBag(doc).setHighlights(target); + } + + private static OffsetsBag getColoringBag(Document doc) { + OffsetsBag bag = (OffsetsBag) doc.getProperty(Highlighting.class); + + if (bag == null) { + doc.putProperty(Highlighting.class, bag = new OffsetsBag(doc)); + } + + return bag; + } + + private static final Object KEY_OCCURRENCES_BAG = new Object(); + private static OffsetsBag getOccurrencesBag(Document doc) { + OffsetsBag bag = (OffsetsBag) doc.getProperty(KEY_OCCURRENCES_BAG); + + if (bag == null) { + doc.putProperty(KEY_OCCURRENCES_BAG, bag = new OffsetsBag(doc)); + } + + return bag; + } + + public static final class HighlightData { + final List<String> categories; + final List<Long> spans; + public HighlightData(List<String> cats, List<Long> spans) { + this.categories = cats; + this.spans = spans; + } + + public HighlightData() { + this(null, null); + } + + } + + public static void registerComponentListener() { + EditorRegistry.addPropertyChangeListener(L); + } + + private static final PropertyChangeListener L = new PropertyChangeListener() { + private JTextComponent old; + private CaretListener caret; + @Override public void propertyChange(PropertyChangeEvent evt) { + JTextComponent current = EditorRegistry.focusedComponent(); + + if (current == old) return ; + + if (old != null) { + old.removeCaretListener(caret); + } + + if (current != null) { + final Document doc = current.getDocument(); + final RemoteSourceDescription rsd = Utilities.remoteSource(doc); + + if (rsd != null) { + current.addCaretListener(caret = new CaretListener() { + @Override public void caretUpdate(CaretEvent e) { + final int caret = e.getDot(); + + WORKER.post(new Runnable() { + @Override public void run() { + try { + URI sourceURI = new URI(rsd.idx.remote.toExternalForm() + "/ui/target?path=" + WebUtilities.escapeForQuery(rsd.idx.remoteSegment) + "&relative=" + WebUtilities.escapeForQuery(rsd.relative) + "&position=" + caret); + Map<Object, Object> targetData = Pojson.load(HashMap.class, sourceURI.toURL().openStream()); + Object signature = targetData.get("signature"); + + if (signature instanceof String) { + URI localUsagesURI = new URI(rsd.idx.remote.toExternalForm() + "/ui/localUsages?path=" + WebUtilities.escapeForQuery(rsd.idx.remoteSegment) + "&relative=" + WebUtilities.escapeForQuery(rsd.relative) + "&signature=" + WebUtilities.escapeForQuery(String.valueOf(signature)) + "&usages=true"); + long[][] spans = Pojson.load(long[][].class, localUsagesURI.toURL().openStream()); + OffsetsBag bag = new OffsetsBag(doc); + + for (long[] span : spans) { + bag.addHighlight((int) span[0], (int) span[1], ColoringManager.getColoringImpl(ColoringManager.KEY_MARK_OCCURRENCES)); + } + + getOccurrencesBag(doc).setHighlights(bag); + } + } catch (URISyntaxException ex) { + Exceptions.printStackTrace(ex); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + }, 300);//should reuse one task... + } + }); + + } + } + + old = current; + } + }; +} http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/remoting/ide/browsing/src/org/netbeans/modules/jackpot30/ide/browsing/HyperlinkProviderImpl.java ---------------------------------------------------------------------- diff --git a/remoting/ide/browsing/src/org/netbeans/modules/jackpot30/ide/browsing/HyperlinkProviderImpl.java b/remoting/ide/browsing/src/org/netbeans/modules/jackpot30/ide/browsing/HyperlinkProviderImpl.java new file mode 100644 index 0000000..62c0c1c --- /dev/null +++ b/remoting/ide/browsing/src/org/netbeans/modules/jackpot30/ide/browsing/HyperlinkProviderImpl.java @@ -0,0 +1,236 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.jackpot30.ide.browsing; + +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.SwingUtilities; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; +import javax.swing.text.StyledDocument; +import org.codeviation.pojson.Pojson; +import org.netbeans.api.editor.mimelookup.MimeRegistration; +import org.netbeans.editor.BaseDocument; +import org.netbeans.editor.Utilities; +import org.netbeans.lib.editor.hyperlink.spi.HyperlinkProviderExt; +import org.netbeans.lib.editor.hyperlink.spi.HyperlinkType; +import org.netbeans.modules.editor.NbEditorUtilities; +import org.netbeans.modules.jackpot30.remoting.api.Utilities.RemoteSourceDescription; +import org.netbeans.modules.jackpot30.remoting.api.RemoteIndex; +import org.netbeans.modules.jackpot30.remoting.api.WebUtilities; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.cookies.EditorCookie; +import org.openide.cookies.LineCookie; +import org.openide.cookies.OpenCookie; +import org.openide.filesystems.FileObject; +import org.openide.loaders.DataObject; +import org.openide.text.Line; +import org.openide.text.Line.ShowOpenType; +import org.openide.text.Line.ShowVisibilityType; +import org.openide.text.NbDocument; +import org.openide.util.Exceptions; +import org.openide.util.NbBundle.Messages; +import org.openide.util.UserQuestionException; + +/** + * + * @author lahvac + */ +@MimeRegistration(mimeType = "text/x-rjava", service = HyperlinkProviderExt.class) +public class HyperlinkProviderImpl implements HyperlinkProviderExt { + + private static final Logger LOG = Logger.getLogger(HyperlinkProviderImpl.class.getName()); + + @Override + public Set<HyperlinkType> getSupportedHyperlinkTypes() { + return EnumSet.of(HyperlinkType.GO_TO_DECLARATION); + } + + @Override + public boolean isHyperlinkPoint(Document doc, int offset, HyperlinkType type) { + return getHyperlinkSpan(doc, offset, type) != null; + } + + @Override + public int[] getHyperlinkSpan(Document doc, int offset, HyperlinkType type) { + try { + int[] span = Utilities.getIdentifierBlock((BaseDocument) doc, offset); + + return span; + } catch (BadLocationException ex) { + return null; + } + } + + @Override + public void performClickAction(Document doc, int offset, HyperlinkType type) { + RemoteSourceDescription rsd = org.netbeans.modules.jackpot30.remoting.api.Utilities.remoteSource(doc); + FileObject file = NbEditorUtilities.getFileObject(doc); + + if (rsd != null && file != null) { + try { + URI sourceURI = new URI(rsd.idx.remote.toExternalForm() + "/ui/target?path=" + WebUtilities.escapeForQuery(rsd.idx.remoteSegment) + "&relative=" + WebUtilities.escapeForQuery(rsd.relative) + "&position=" + offset); + Map<Object, Object> targetData = Pojson.load(HashMap.class, sourceURI.toURL().openStream()); + + if (targetData.containsKey("position")) { + open(file, Integer.parseInt(String.valueOf(targetData.get("position")))); + } else if (targetData.containsKey("source")) { + RemoteIndex targetIDX = null; + for (RemoteIndex i : RemoteIndex.loadIndices()) { + if (i.remote.equals(rsd.idx.remote) && i.remoteSegment.equals(targetData.get("path"))) { + targetIDX = i; + } + } + + if (targetIDX == null) { + //TODO + } else { + String relativePath = (String) targetData.get("source"); + URI declarationSpanURI = new URI(targetIDX.remote.toExternalForm() + "/ui/declarationSpan?path=" + WebUtilities.escapeForQuery(targetIDX.remoteSegment) + "&relative=" + WebUtilities.escapeForQuery(relativePath) + "&signature=" + WebUtilities.escapeForQuery(String.valueOf(targetData.get("signature")))); + List<Long> span = Pojson.update(new ArrayList<Long>(), declarationSpanURI.toURL().openStream()); + //TODO: if the target is on disk, should use standard way to open: + open(targetIDX.getFile(relativePath), (int) (long) span.get(2)); + } + } + } catch (URISyntaxException ex) { + Exceptions.printStackTrace(ex); + } catch (IOException ex) { + Exceptions.printStackTrace(ex); + } + } + } + + @Override + public String getTooltipText(Document doc, int offset, HyperlinkType type) { + return null; + } + + public @Deprecated static boolean open(final FileObject fo, final int offset) { + return doOpen(fo, offset); + } + + @Messages("TXT_Question=Question") + private static boolean doOpen(FileObject fo, int offset) { + try { + DataObject od = DataObject.find(fo); + EditorCookie ec = od.getLookup().lookup(EditorCookie.class); + LineCookie lc = od.getLookup().lookup(LineCookie.class); + + if (ec != null && lc != null && offset != -1) { + StyledDocument doc = null; + try { + doc = ec.openDocument(); + } catch (UserQuestionException uqe) { + final Object value = DialogDisplayer.getDefault().notify( + new NotifyDescriptor.Confirmation(uqe.getLocalizedMessage(), + Bundle.TXT_Question(), + NotifyDescriptor.YES_NO_OPTION)); + if (value != NotifyDescriptor.YES_OPTION) { + return false; + } + uqe.confirmed(); + doc = ec.openDocument(); + } + if (doc != null) { + int line = NbDocument.findLineNumber(doc, offset); + int lineOffset = NbDocument.findLineOffset(doc, line); + int column = offset - lineOffset; + + if (line != -1) { + Line l = lc.getLineSet().getCurrent(line); + + if (l != null) { + doShow( l, column); + return true; + } + } + } + } + + OpenCookie oc = od.getLookup().lookup(OpenCookie.class); + + if (oc != null) { + doOpen(oc); + return true; + } + } catch (IOException e) { + if (LOG.isLoggable(Level.INFO)) + LOG.log(Level.INFO, e.getMessage(), e); + } + + return false; + } + + private static void doShow(final Line l, final int column) { + if (SwingUtilities.isEventDispatchThread()) { + l.show(ShowOpenType.OPEN, ShowVisibilityType.FOCUS, column); + } else { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + l.show(ShowOpenType.OPEN, ShowVisibilityType.FOCUS, column); + } + }); + } + } + + private static void doOpen(final OpenCookie oc) { + if (SwingUtilities.isEventDispatchThread()) { + oc.open(); + } else { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + oc.open(); + } + }); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/remoting/ide/browsing/src/org/netbeans/modules/jackpot30/ide/browsing/Installer.java ---------------------------------------------------------------------- diff --git a/remoting/ide/browsing/src/org/netbeans/modules/jackpot30/ide/browsing/Installer.java b/remoting/ide/browsing/src/org/netbeans/modules/jackpot30/ide/browsing/Installer.java new file mode 100644 index 0000000..1064501 --- /dev/null +++ b/remoting/ide/browsing/src/org/netbeans/modules/jackpot30/ide/browsing/Installer.java @@ -0,0 +1,53 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.jackpot30.ide.browsing; + +import org.openide.modules.ModuleInstall; + +public class Installer extends ModuleInstall { + + @Override + public void restored() { + Highlighting.registerComponentListener(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-netbeans-jackpot30/blob/9ed0a377/remoting/ide/browsing/src/org/netbeans/modules/jackpot30/ide/browsing/RemoteEditorKit.java ---------------------------------------------------------------------- diff --git a/remoting/ide/browsing/src/org/netbeans/modules/jackpot30/ide/browsing/RemoteEditorKit.java b/remoting/ide/browsing/src/org/netbeans/modules/jackpot30/ide/browsing/RemoteEditorKit.java new file mode 100644 index 0000000..4731be6 --- /dev/null +++ b/remoting/ide/browsing/src/org/netbeans/modules/jackpot30/ide/browsing/RemoteEditorKit.java @@ -0,0 +1,95 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ +package org.netbeans.modules.jackpot30.ide.browsing; + +import org.netbeans.modules.jackpot30.remoting.api.Utilities; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.URI; +import java.net.URISyntaxException; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; +import javax.swing.text.EditorKit; +import org.netbeans.api.editor.mimelookup.MimeRegistration; +import org.netbeans.editor.GuardedDocument; +import org.netbeans.modules.editor.NbEditorKit; +import org.netbeans.modules.jackpot30.remoting.api.Utilities.RemoteSourceDescription; +import org.netbeans.modules.jackpot30.remoting.api.WebUtilities; + +/** + * + * @author lahvac + */ +@MimeRegistration(mimeType = "text/x-rjava", service = EditorKit.class) +public class RemoteEditorKit extends NbEditorKit { + + @Override + public String getContentType() { + return "text/x-rjava"; + } + + @Override + public void read(Reader in, Document doc, int pos) throws IOException, BadLocationException { + RemoteSourceDescription rsd = Utilities.remoteSource(doc); + if (rsd != null) { + //TODO: cache the content? + try { + URI sourceURI = new URI(rsd.idx.remote.toExternalForm() + "/source/cat?path=" + WebUtilities.escapeForQuery(rsd.idx.remoteSegment) + "&relative=" + WebUtilities.escapeForQuery(rsd.relative)); + + in = new InputStreamReader(sourceURI.toURL().openStream(), "UTF-8"); + } catch (URISyntaxException ex) { + throw new IOException(ex); + } + } + + super.read(in, doc, pos); + + if (doc instanceof GuardedDocument) { + //XXX: bypassing the standard APIs + ((GuardedDocument) doc).getGuardedBlockChain().addBlock(0, doc.getLength() + 1, true); + } + + Highlighting.highlight(doc); + } + +}
