diff --git a/core.output2/manifest.mf b/core.output2/manifest.mf --- a/core.output2/manifest.mf +++ b/core.output2/manifest.mf @@ -4,5 +4,5 @@ OpenIDE-Module-Localizing-Bundle: org/netbeans/core/output2/Bundle.properties OpenIDE-Module-Provides: org.openide.windows.IOProvider AutoUpdate-Essential-Module: true -OpenIDE-Module-Specification-Version: 1.37 +OpenIDE-Module-Specification-Version: 1.38 diff --git a/core.output2/nbproject/project.xml b/core.output2/nbproject/project.xml --- a/core.output2/nbproject/project.xml +++ b/core.output2/nbproject/project.xml @@ -111,7 +111,16 @@ - 1.40 + 1.45 + + + + org.openide.io.base + + + + 1 + 1.0 diff --git a/core.output2/src/org/netbeans/core/output2/NbIO.java b/core.output2/src/org/netbeans/core/output2/NbIO.java --- a/core.output2/src/org/netbeans/core/output2/NbIO.java +++ b/core.output2/src/org/netbeans/core/output2/NbIO.java @@ -53,18 +53,35 @@ import java.awt.*; import java.io.IOException; import java.io.Reader; +import java.util.EnumSet; import org.netbeans.core.output2.options.OutputOptions; +import org.openide.io.base.BaseColor; +import org.openide.io.base.BaseIOColorLines; +import org.openide.io.base.BaseIOColorPrint; +import org.openide.io.base.BaseIOColors; +import org.openide.io.base.BaseIOFolding; +import org.openide.io.base.BaseIOHyperlink; +import org.openide.io.base.BaseIOLinkInfo; +import org.openide.io.base.BaseIOPosition; +import org.openide.io.base.BaseIOSelect; +import org.openide.io.base.BaseIOTab; +import org.openide.io.base.BaseInputOutput; +import org.openide.io.base.BaseOutputEvent; +import org.openide.io.base.BaseOutputListener; import org.openide.util.Exceptions; import org.openide.util.Lookup; import org.openide.util.lookup.Lookups; import org.openide.windows.IOColorLines; import org.openide.windows.IOColorPrint; import org.openide.windows.IOColors; +import org.openide.windows.IOColors.OutputType; import org.openide.windows.IOContainer; import org.openide.windows.IOFolding; import org.openide.windows.IOPosition; import org.openide.windows.IOSelect; +import org.openide.windows.IOSelect.AdditionalOperation; import org.openide.windows.IOTab; +import org.openide.windows.OutputEvent; /** Implementation of InputOutput. Implements calls as a set of * "commands" which are passed up to Dispatcher to be run on the event @@ -72,7 +89,7 @@ * * @author Tim Boudreau */ -class NbIO implements InputOutput, Lookup.Provider { +class NbIO implements InputOutput, BaseInputOutput, Lookup.Provider { private Boolean focusTaken = null; private volatile boolean closed = false; @@ -248,6 +265,7 @@ return actions; } + @Override public void reset() { if (Controller.LOG) Controller.log (this + ": reset"); closed = false; @@ -312,7 +330,8 @@ ioColors = new IOColorsImpl(); lookup = Lookups.fixed(ioTab, ioColors, new IOPositionImpl(), new IOColorLinesImpl(), new IOColorPrintImpl(), - new IOSelectImpl(), new IOFoldingImpl(), options); + new IOSelectImpl(), new BaseIOSelectImpl(), + new IOFoldingImpl(), new BaseIOHyperlinkImpl(), options); } return lookup; } @@ -470,7 +489,7 @@ return ioColors != null ? ioColors.getColor(type) : AbstractLines.getDefColors()[type.ordinal()]; } - private class IOTabImpl extends IOTab { + private class IOTabImpl extends IOTab implements BaseIOTab.Provider { Icon icon; String toolTip; @@ -480,7 +499,7 @@ } @Override - protected String getToolTipText() { + public String getToolTipText() { return toolTip; } @@ -491,16 +510,17 @@ } @Override - protected void setToolTipText(String text) { + public void setToolTipText(String text) { toolTip = text; post(NbIO.this, IOEvent.CMD_SET_TOOLTIP, toolTip); } } - private class IOPositionImpl extends IOPosition { + private class IOPositionImpl extends IOPosition + implements BaseIOPosition.Provider { @Override - protected Position currentPosition() { + public PositionImpl currentPosition() { OutWriter out = out(); int size = 0; if (out != null) { @@ -510,7 +530,8 @@ } } - private class PositionImpl implements IOPosition.Position { + private class PositionImpl implements IOPosition.Position, + BaseIOPosition.Position { private int pos; public PositionImpl(int pos) { @@ -522,7 +543,7 @@ } } - private class IOColorLinesImpl extends IOColorLines { + private class IOColorLinesImpl extends IOColorLines implements BaseIOColorLines.Provider { @Override protected void println(CharSequence text, OutputListener listener, boolean important, Color color) throws IOException { @@ -531,9 +552,20 @@ out.print(text, listener, important, color, null, OutputKind.OUT, true); } } + + @Override + public void println(CharSequence text, boolean important, BaseColor color, + BaseIOLinkInfo... extendedInfo) throws IOException { + OutWriter out = out(); + if (out != null) { + OutputListener l = findAndConvertOutputListener(extendedInfo); + out.print(text, l, important, convertToColor(color), null, + OutputKind.OUT, true); + } + } } - private class IOColorPrintImpl extends IOColorPrint { + private class IOColorPrintImpl extends IOColorPrint implements BaseIOColorPrint.Provider { @Override protected void print(CharSequence text, OutputListener listener, boolean important, Color color) throws IOException { @@ -542,6 +574,17 @@ out.print(text, listener, important, color, null, OutputKind.OUT, false); } } + + @Override + public void print(CharSequence text, boolean important, BaseColor color, + BaseIOLinkInfo... extendedInfo) throws IOException { + OutWriter out = out(); + if (out != null) { + OutputListener l = findAndConvertOutputListener(extendedInfo); + out.print(text, l, important, convertToColor(color), null, + OutputKind.OUT, false); + } + } } private class IOSelectImpl extends IOSelect { @@ -553,7 +596,19 @@ } } - private class IOColorsImpl extends IOColors { + private class BaseIOSelectImpl implements BaseIOSelect.Provider { + + @Override + public void select(Set extraOps) { + if (Controller.LOG) { + Controller.log(this + ": IOSelect.select"); //NOI18N + } + NbIO.post(NbIO.this, IOEvent.CMD_FINE_SELECT, + convertIOSelectOps(extraOps)); + } + } + + private class IOColorsImpl extends IOColors implements BaseIOColors.Provider { Color[] clrs = new Color[OutputType.values().length]; @Override @@ -566,12 +621,22 @@ clrs[type.ordinal()] = color; post(NbIO.this, IOEvent.CMD_DEF_COLORS, type); } + + @Override + public BaseColor getColor(BaseIOColors.OutputType type) { + return convertToBaseColor(getColor(convertOutputType(type))); + }; + + @Override + public void setColor(BaseIOColors.OutputType type, BaseColor color) { + setColor(convertOutputType(type), convertToColor(color)); + } } - private class IOFoldingImpl extends IOFolding { + private class IOFoldingImpl extends IOFolding implements BaseIOFolding.Provider { @Override - protected FoldHandleDefinition startFold(boolean expanded) { + public NbIoFoldHandleDefinition startFold(boolean expanded) { synchronized (out()) { if (currentFold != null) { throw new IllegalStateException( @@ -582,7 +647,8 @@ } } - class NbIoFoldHandleDefinition extends IOFolding.FoldHandleDefinition { + class NbIoFoldHandleDefinition extends IOFolding.FoldHandleDefinition + implements BaseIOFolding.FoldHandleDefinition{ private final NbIoFoldHandleDefinition parent; private final int start; @@ -620,7 +686,7 @@ } @Override - public FoldHandleDefinition startFold(boolean expanded) { + public NbIoFoldHandleDefinition startFold(boolean expanded) { synchronized (out()) { if (end != -1) { throw new IllegalStateException( @@ -674,6 +740,25 @@ } } + private class BaseIOHyperlinkImpl implements BaseIOHyperlink.Provider { + + @Override + public boolean isSupported(Class cls) { + return BaseOutputListener.class.isAssignableFrom(cls); + } + + @Override + public void println(BaseIOHyperlink.Type type, String s, + boolean important, BaseIOLinkInfo... linkInfo) throws IOException { + OutputWriter writer = BaseIOHyperlink.Type.ERR.equals(type) + ? getErr() : getOut(); + if (writer != null) { + OutputListener l = findAndConvertOutputListener(linkInfo); + writer.println(s, l, important); + } + } + } + private int getLastLineNumber() { return Math.max(0, out().getLines().getLineCount() - 2); } @@ -692,4 +777,100 @@ OutputOptions getOptions() { return this.options; } + + /** + * Find the first {@link BaseOutputListener} in the list of hyperlink + * extension objects, convert it to {@link OutputListener} and return it. + */ + private OutputListener findAndConvertOutputListener(BaseIOLinkInfo... exts) { + for (Object o : exts) { + if (o instanceof BaseOutputListener) { + return convertToOutputListener((BaseOutputListener) o); + } + } + return null; + } + + private OutputListener convertToOutputListener(final BaseOutputListener l) { + return new OutputListener() { + + @Override + public void outputLineSelected(OutputEvent ev) { + } + + @Override + public void outputLineAction(OutputEvent ev) { + l.outputLineAction(convertToOutputEventBase(ev)); + } + + @Override + public void outputLineCleared(OutputEvent ev) { + } + }; + } + + private BaseOutputEvent convertToOutputEventBase(final OutputEvent e) { + InputOutput origIO = e.getInputOutput(); + BaseInputOutput src = origIO instanceof BaseInputOutput + ? (BaseInputOutput) origIO : this; + return new BaseOutputEvent(src) { + @Override + public String getLine() { + return e.getLine(); + } + }; + } + + private Set convertIOSelectOps( + Set ops) { + Set s = EnumSet.noneOf(AdditionalOperation.class); + for (BaseIOSelect.AdditionalOperation bo : ops) { + switch (bo) { + case OPEN: + s.add(AdditionalOperation.OPEN); + break; + case REQUEST_ACTIVE: + s.add(AdditionalOperation.REQUEST_ACTIVE); + break; + case REQUEST_VISIBLE: + s.add(AdditionalOperation.REQUEST_VISIBLE); + break; + } + } + return s; + } + + private OutputType convertOutputType(BaseIOColors.OutputType baseType) { + switch (baseType) { + case INPUT: + return OutputType.INPUT; + case OUTPUT: + return OutputType.OUTPUT; + case ERROR: + return OutputType.ERROR; + case HYPERLINK: + return OutputType.HYPERLINK; + case HYPERLINK_IMPORTANT: + return OutputType.HYPERLINK_IMPORTANT; + case LOG_DEBUG: + return OutputType.LOG_DEBUG; + case LOG_SUCCESS: + return OutputType.LOG_SUCCESS; + case LOG_WARNING: + return OutputType.LOG_WARNING; + case LOG_FAILURE: + return OutputType.LOG_FAILURE; + default: + throw new IllegalArgumentException( + "Unknown output type " + baseType); //NOI18N + } + } + + private Color convertToColor(BaseColor baseColor) { + return new Color(baseColor.getRGB(), true); + } + + private BaseColor convertToBaseColor(Color color) { + return new BaseColor(color.getRGB(), true); + } } diff --git a/core.output2/src/org/netbeans/core/output2/NbIOProvider.java b/core.output2/src/org/netbeans/core/output2/NbIOProvider.java --- a/core.output2/src/org/netbeans/core/output2/NbIOProvider.java +++ b/core.output2/src/org/netbeans/core/output2/NbIOProvider.java @@ -45,7 +45,6 @@ package org.netbeans.core.output2; import java.io.IOException; -import java.util.WeakHashMap; import javax.swing.Action; import org.openide.util.Exceptions; import org.openide.util.NbBundle; @@ -55,19 +54,23 @@ import org.openide.windows.OutputWriter; /** - * Supplies Output Window implementation through Lookup. + * Supplies Output Window implementation through Lookup. Provider of I/O + * instances for the org.openide.io (package org.openide.windows) API. + * * @author Jesse Glick, Tim Boudreau */ @org.openide.util.lookup.ServiceProvider(service=org.openide.windows.IOProvider.class, position=100) public final class NbIOProvider extends IOProvider { - private static final WeakHashMap containerPairMaps = - new WeakHashMap(); private static final String STDOUT = NbBundle.getMessage(NbIOProvider.class, "LBL_STDOUT"); //NOI18N - private static final String NAME = "output2"; // NOI18N - + @Override + public String getName() { + return SharedProvider.getInstance().getName(); + } + + @Override public OutputWriter getStdOut() { if (Controller.LOG) { Controller.log("NbIOProvider.getStdOut"); @@ -93,6 +96,7 @@ } + @Override public InputOutput getIO(String name, boolean newIO) { return getIO (name, newIO, new Action[0], null); } @@ -108,53 +112,15 @@ } @Override - public String getName() { - return NAME; + public InputOutput getIO(String name, boolean newIO, Action[] actions, + IOContainer ioContainer) { + + return SharedProvider.getInstance().getIO(name, newIO, actions, + ioContainer); } - @Override - public InputOutput getIO(String name, boolean newIO, - Action[] toolbarActions, IOContainer ioContainer) { - if (Controller.LOG) { - Controller.log("GETIO: " + name + " new:" + newIO); - } - IOContainer realIoContainer = ioContainer == null - ? IOContainer.getDefault() : ioContainer; - NbIO result; - synchronized (containerPairMaps) { - PairMap namesToIos = containerPairMaps.get(realIoContainer); - result = namesToIos != null ? namesToIos.get(name) : null; - } - if (result == null || newIO) { - result = new NbIO(name, toolbarActions, realIoContainer); - synchronized (containerPairMaps) { - PairMap namesToIos = containerPairMaps.get(realIoContainer); - if (namesToIos == null) { - namesToIos = new PairMap(); - containerPairMaps.put(realIoContainer, namesToIos); - } - namesToIos.add(name, result); - } - NbIO.post(new IOEvent(result, IOEvent.CMD_CREATE, newIO)); - } - return result; - } - - - static void dispose (NbIO io) { - IOContainer ioContainer = io.getIOContainer(); - if (ioContainer == null) { - ioContainer = IOContainer.getDefault(); - } - synchronized (containerPairMaps) { - PairMap namesToIos = containerPairMaps.get(ioContainer); - if (namesToIos != null) { - namesToIos.remove(io); - if (namesToIos.isEmpty()) { - containerPairMaps.remove(ioContainer); - } - } - } + static void dispose(NbIO io) { + SharedProvider.dispose(io); } } diff --git a/core.output2/src/org/netbeans/core/output2/NbIOProviderBase.java b/core.output2/src/org/netbeans/core/output2/NbIOProviderBase.java new file mode 100644 --- /dev/null +++ b/core.output2/src/org/netbeans/core/output2/NbIOProviderBase.java @@ -0,0 +1,102 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 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 2014 Sun Microsystems, Inc. + */ +package org.netbeans.core.output2; + +import java.util.EventListener; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.Action; +import org.openide.io.base.BaseIOProvider; +import org.openide.io.base.BaseInputOutput; +import org.openide.util.lookup.ServiceProvider; + +/** + * Provider of I/O instances for the org.openide.io.base API. + * + * @author jhavlin + */ +@ServiceProvider(service = BaseIOProvider.class, position = 100) +public class NbIOProviderBase extends BaseIOProvider { + + private static final Logger LOG = Logger.getLogger( + NbIOProviderBase.class.getName()); + + @Override + public String getName() { + return SharedProvider.getInstance().getName(); + } + + @Override + public BaseInputOutput getIO(String name, boolean newIO, + EventListener... actions) { + + Action[] actionArray = convertActions(actions); + return SharedProvider.getInstance().getIO(name, newIO, actionArray, + null); + } + + private Action[] convertActions(EventListener[] actions) { + Action[] actionArray = new Action[actions.length]; + for (int i = 0; i < actions.length; i++) { + if (actions[i] instanceof Action) { + actionArray[i] = (Action) actions[i]; + } else if (actions[i] == null) { + LOG.log(Level.WARNING, "Null action", //NOI18N + new IllegalArgumentException()); + return new Action[0]; + } else { + LOG.log(Level.WARNING, "Only actions of type javax." //NOI18N + + "swing.Action are supported, but object of " //NOI18N + + "type " + actions[i].getClass() + " found", //NOI18N + new IllegalArgumentException()); + return new Action[0]; + } + } + return actionArray; + } + + @Override + public boolean isActionTypeSupported( + Class cls) { + return Action.class.isAssignableFrom(cls); + } +} diff --git a/core.output2/src/org/netbeans/core/output2/SharedProvider.java b/core.output2/src/org/netbeans/core/output2/SharedProvider.java new file mode 100644 --- /dev/null +++ b/core.output2/src/org/netbeans/core/output2/SharedProvider.java @@ -0,0 +1,119 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 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 2014 Sun Microsystems, Inc. + */ +package org.netbeans.core.output2; + +import java.util.WeakHashMap; +import javax.swing.Action; +import org.openide.windows.IOContainer; + +/** + * Shared provider for both the original (org.openide.io/org.openide.windows) + * and the base (org.openide.io.base) APIs. + * + * @author jhavlin + */ +public class SharedProvider { + + private static final WeakHashMap containerPairMaps + = new WeakHashMap(); + private static final String NAME = "output2"; // NOI18N + + private static class SingletonHolder { + + static SharedProvider INSTANCE = new SharedProvider(); + } + + public static SharedProvider getInstance() { + return SingletonHolder.INSTANCE; + } + + private SharedProvider() { + System.out.println("x"); + } + + public String getName() { + return NAME; + } + + NbIO getIO(String name, boolean newIO, + Action[] toolbarActions, IOContainer ioContainer) { + if (Controller.LOG) { + Controller.log("GETIO: " + name + " new:" + newIO); + } + IOContainer realIoContainer = ioContainer == null + ? IOContainer.getDefault() : ioContainer; + NbIO result; + synchronized (containerPairMaps) { + PairMap namesToIos = containerPairMaps.get(realIoContainer); + result = namesToIos != null ? namesToIos.get(name) : null; + } + if (result == null || newIO) { + result = new NbIO(name, toolbarActions, realIoContainer); + synchronized (containerPairMaps) { + PairMap namesToIos = containerPairMaps.get(realIoContainer); + if (namesToIos == null) { + namesToIos = new PairMap(); + containerPairMaps.put(realIoContainer, namesToIos); + } + namesToIos.add(name, result); + } + NbIO.post(new IOEvent(result, IOEvent.CMD_CREATE, newIO)); + } + return result; + } + + static void dispose(NbIO io) { + IOContainer ioContainer = io.getIOContainer(); + if (ioContainer == null) { + ioContainer = IOContainer.getDefault(); + } + synchronized (containerPairMaps) { + PairMap namesToIos = containerPairMaps.get(ioContainer); + if (namesToIos != null) { + namesToIos.remove(io); + if (namesToIos.isEmpty()) { + containerPairMaps.remove(ioContainer); + } + } + } + } +} diff --git a/nbbuild/build.properties b/nbbuild/build.properties --- a/nbbuild/build.properties +++ b/nbbuild/build.properties @@ -176,6 +176,7 @@ core.netigso,\ o.n.swing.outline,\ o.n.swing.tabcontrol,\ + openide.io.base,\ editor.indent,\ editor.bracesmatching,\ j2ee.metadata,\ diff --git a/nbbuild/cluster.properties b/nbbuild/cluster.properties --- a/nbbuild/cluster.properties +++ b/nbbuild/cluster.properties @@ -250,6 +250,7 @@ openide.filesystems.compat8,\ openide.filesystems.nb,\ openide.io,\ + openide.io.base,\ openide.loaders,\ openide.nodes,\ openide.options,\ diff --git a/nbbuild/javadoctools/links.xml b/nbbuild/javadoctools/links.xml --- a/nbbuild/javadoctools/links.xml +++ b/nbbuild/javadoctools/links.xml @@ -233,3 +233,4 @@ + diff --git a/nbbuild/javadoctools/properties.xml b/nbbuild/javadoctools/properties.xml --- a/nbbuild/javadoctools/properties.xml +++ b/nbbuild/javadoctools/properties.xml @@ -231,3 +231,4 @@ + diff --git a/nbbuild/javadoctools/replaces.xml b/nbbuild/javadoctools/replaces.xml --- a/nbbuild/javadoctools/replaces.xml +++ b/nbbuild/javadoctools/replaces.xml @@ -231,3 +231,4 @@ + diff --git a/openide.io.base/apichanges.xml b/openide.io.base/apichanges.xml new file mode 100644 --- /dev/null +++ b/openide.io.base/apichanges.xml @@ -0,0 +1,139 @@ + + + + + + + + + + + + + Base I/O APIs + + + + + + + + + + + + + + + + + Change History for the Base I/O APIs + + + + + + +

Introduction

+ +

This document lists changes made to the Base I/O APIs.

+ + +
+ + +

@FOOTER@

+ + +
+ +
+ diff --git a/openide.io.base/arch.xml b/openide.io.base/arch.xml new file mode 100644 --- /dev/null +++ b/openide.io.base/arch.xml @@ -0,0 +1,1106 @@ + + +]> + + + + &api-questions; + + + + + +

+ Just a base API/SPI for defining the output window. +

+
+
+ + + + + +

+ Too little code to test. +

+
+ + + + + +

+ Done. +

+
+ + + + + +

There is an SPI but additional implementations are not expected. The API is most important.

+

+ Simple usage example: +

+
+  BaseInputOutput io = BaseIOProvider.getDefault().getIO("My Window", true);
+  PrintWriter w = io.getOut();
+  w.println("Line of plain text.");
+  BaseOutputListener listener = new BaseOutputListener() {
+      public void outputLineAction(BaseOutputEvent ev) {
+          StatusDisplayer.getDefault().setStatusText("Hyperlink clicked!");
+      }
+  };
+  if (BaseIOHyperlink.isSupported(io, BaseOutputListener.class)) {
+    BaseIOHyperlink.println(io, Type.OUT, "Line of hyperlinked text.", true, listener);
+  }
+  
+
+ + + + + +

+ The Base Input/Output APIs is a small API module + which contains BaseInputOutput and related interfaces used in + driving the Output Window. The normal implementation is + org.netbeans.core.output2. +

+

+ The API was extracted from module openide.io, which depends on some + GUI-related classes. This module has no such dependencies. +

+
+ + + + + + + + + + + + +

+ This module is an alternative for org.openide.io, it has similar goals, but + less dependencies. +

+
+ + + + + +

+ Yes. +

+
+ + + + + +

+ The module defines an API. +

+
+ + + + + +

+ N/A +

+
+ + + + + +

+ 1.7 +

+
+ + + + + +

+ JRE +

+
+ + + + + + + + + + + + +

+ None. +

+
+ + + + + +

+ Any +

+
+ + + + + +

+ You will very likely also want to declare +

+
OpenIDE-Module-Requires: org.openide.io.base.BaseIOProvider
+

to ensure that an Output Window implementation is in fact enabled.

+
+ + + + + +

+ Just the module JAR. +

+
+ + + + + +

+ Yes +

+
+ + + + + +

+ No; only API classes are public. +

+
+ + + + + +

+ Anywhere +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ Should be thread safe. +

+
+ + + + + +

+ Plain Unicode text only. +

+
+ + + + + +

+ N/A +

+
+ + + + + +

+ None +

+
+ + + + + + BaseIOProvider.getDefault() asks lookup for the first instance + of itself. This is normally provided by org.netbeans.core.output2. + + + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ N/A +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ Scalability in GUI speed and memory consumption is probably limited only + by the Output Window implementation. +

+
+ + + + + +

+ No special behavior. +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

No, but the implementation may.

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ + + + + +

+ No +

+
+ +
diff --git a/openide.io.base/build.xml b/openide.io.base/build.xml new file mode 100644 --- /dev/null +++ b/openide.io.base/build.xml @@ -0,0 +1,5 @@ + + + Builds, tests, and runs the project org.openide.io.base + + diff --git a/openide.io.base/manifest.mf b/openide.io.base/manifest.mf new file mode 100644 --- /dev/null +++ b/openide.io.base/manifest.mf @@ -0,0 +1,5 @@ +Manifest-Version: 1.0 +OpenIDE-Module: org.openide.io.base/1 +OpenIDE-Module-Localizing-Bundle: org/openide/io/base/Bundle.properties +OpenIDE-Module-Specification-Version: 1.0 + diff --git a/openide.io.base/nbproject/project.properties b/openide.io.base/nbproject/project.properties new file mode 100644 --- /dev/null +++ b/openide.io.base/nbproject/project.properties @@ -0,0 +1,4 @@ +is.autoload=true +javac.source=1.6 +javac.compilerargs=-Xlint -Xlint:-serial +javadoc.arch=${basedir}/arch.xml diff --git a/openide.io.base/nbproject/project.xml b/openide.io.base/nbproject/project.xml new file mode 100644 --- /dev/null +++ b/openide.io.base/nbproject/project.xml @@ -0,0 +1,39 @@ + + + org.netbeans.modules.apisupport.project + + + org.openide.io.base + + + org.netbeans.api.annotations.common + + + + 1 + 1.24 + + + + org.openide.util.base + + + + 9.1 + + + + org.openide.util.lookup + + + + 8.25 + + + + + org.openide.io.base + + + + diff --git a/openide.io.base/src/org/openide/io/base/BaseColor.java b/openide.io.base/src/org/openide/io/base/BaseColor.java new file mode 100644 --- /dev/null +++ b/openide.io.base/src/org/openide/io/base/BaseColor.java @@ -0,0 +1,193 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 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 2014 Sun Microsystems, Inc. + */ +package org.openide.io.base; + +/** + * Color for use in base I/O APIs. Extrected from java.awt.Color. + * + * @author jhavlin + */ +public final class BaseColor { + + private int value; + + /** + * Creates an opaque sRGB color with the specified combined RGB value + * consisting of the red component in bits 16-23, the green component in + * bits 8-15, and the blue component in bits 0-7. The actual color used in + * rendering depends on finding the best match given the color space + * available for a particular output device. Alpha is defaulted to 255. + * + * @param rgb the combined RGB components + * @see #getRed + * @see #getGreen + * @see #getBlue + * @see #getRGB + */ + public BaseColor(int rgb) { + value = 0xff000000 | rgb; + } + + /** + * Creates an sRGB color with the specified combined RGBA value consisting + * of the alpha component in bits 24-31, the red component in bits 16-23, + * the green component in bits 8-15, and the blue component in bits 0-7. If + * the hasalpha argument is false, alpha is + * defaulted to 255. + * + * @param rgba the combined RGBA components + * @param hasalpha true if the alpha bits are valid; + * false otherwise + * @see java.awt.image.ColorModel#getRGBdefault + * @see #getRed + * @see #getGreen + * @see #getBlue + * @see #getAlpha + * @see #getRGB + */ + public BaseColor(int rgba, boolean hasalpha) { + if (hasalpha) { + value = rgba; + } else { + value = 0xff000000 | rgba; + } + } + + /** + * Creates an opaque sRGB color with the specified red, green, and blue + * values in the range (0 - 255). The actual color used in rendering depends + * on finding the best match given the color space available for a given + * output device. Alpha is defaulted to 255. + * + * @throws IllegalArgumentException if r, g or + * b are outside of the range 0 to 255, inclusive + * @param r the red component + * @param g the green component + * @param b the blue component + * @see #getRed + * @see #getGreen + * @see #getBlue + * @see #getRGB + */ + public BaseColor(int r, int g, int b) { + this(r, g, b, 255); + } + + /** + * Creates an sRGB color with the specified red, green, blue, and alpha + * values in the range (0 - 255). + * + * @throws IllegalArgumentException if r, g, + * b or a are outside of the range 0 to 255, + * inclusive + * @param r the red component + * @param g the green component + * @param b the blue component + * @param a the alpha component + * @see #getRed + * @see #getGreen + * @see #getBlue + * @see #getAlpha + * @see #getRGB + */ + public BaseColor(int r, int g, int b, int a) { + value = ((a & 0xFF) << 24) + | ((r & 0xFF) << 16) + | ((g & 0xFF) << 8) + | ((b & 0xFF)); + } + + /** + * Returns the RGB value representing the color in the default sRGB + * color model. (Bits 24-31 are alpha, 16-23 are red, 8-15 are green, + * 0-7 are blue). + * + * @return the RGB value of the color in the default sRGB + * ColorModel. + * @see #getRed + * @see #getGreen + * @see #getBlue + */ + public int getRGB() { + return value; + } + + /** + * Returns the red component in the range 0-255 in the default sRGB space. + * + * @return the red component. + * @see #getRGB + */ + public int getRed() { + return (getRGB() >> 16) & 0xFF; + } + + /** + * Returns the green component in the range 0-255 in the default sRGB space. + * + * @return the green component. + * @see #getRGB + */ + public int getGreen() { + return (getRGB() >> 8) & 0xFF; + } + + /** + * Returns the blue component in the range 0-255 in the default sRGB space. + * + * @return the blue component. + * @see #getRGB + */ + public int getBlue() { + return (getRGB()) & 0xFF; + } + + /** + * Returns the alpha component in the range 0-255. + * + * @return the alpha component. + * @see #getRGB + */ + public int getAlpha() { + return (getRGB() >> 24) & 0xff; + } +} diff --git a/openide.io/src/org/openide/windows/FoldHandle.java b/openide.io.base/src/org/openide/io/base/BaseFoldHandle.java copy from openide.io/src/org/openide/windows/FoldHandle.java copy to openide.io.base/src/org/openide/io/base/BaseFoldHandle.java --- a/openide.io/src/org/openide/windows/FoldHandle.java +++ b/openide.io.base/src/org/openide/io/base/BaseFoldHandle.java @@ -40,28 +40,27 @@ * Portions Copyrighted 2013 Sun Microsystems, Inc. */ -package org.openide.windows; +package org.openide.io.base; import java.util.logging.Level; import java.util.logging.Logger; import org.netbeans.api.annotations.common.CheckForNull; -import org.openide.windows.IOFolding.FoldHandleDefinition; +import org.openide.io.base.BaseIOFolding.FoldHandleDefinition; /** * An object that refers to a fold in output window. It can be used to finish * the fold, or to create nested folds. * * @author jhavlin - * @since openide.io/1.38 */ -public final class FoldHandle { +public final class BaseFoldHandle { private final FoldHandleDefinition definition; - private static final Logger LOG = Logger.getLogger(FoldHandle.class.getName()); - private FoldHandle currentChild; + private static final Logger LOG = Logger.getLogger(BaseFoldHandle.class.getName()); + private BaseFoldHandle currentChild; private boolean finished = false; - FoldHandle(FoldHandleDefinition definition) { + BaseFoldHandle(FoldHandleDefinition definition) { this.definition = definition; } @@ -85,8 +84,8 @@ * @throws IllegalStateException if the fold has been already finished, or * if an unfinished nested fold exists. */ - public FoldHandle startFold(boolean expanded) { - currentChild = new FoldHandle(definition.startFold(expanded)); + public BaseFoldHandle startFold(boolean expanded) { + currentChild = new BaseFoldHandle(definition.startFold(expanded)); return currentChild; } @@ -106,8 +105,6 @@ * * @return True if {@link #finish()} or {@link #silentFinish()} has been * already called on this fold handle, false otherwise. - * - * @since openide.io/1.42 */ public boolean isFinished() { return finished; @@ -119,10 +116,8 @@ * unfinished. * * @return The last started nested fold. Can be null. - * - * @since openide.io/1.42 */ - public @CheckForNull FoldHandle getLastNestedFold() { + public @CheckForNull BaseFoldHandle getLastNestedFold() { return currentChild; } @@ -131,10 +126,8 @@ * returns null if the last nested fold has been already finished. * * @return The last unfinished nested fold or null. - * - * @since openide.io/1.42 */ - public @CheckForNull FoldHandle getCurrentNestedFold() { + public @CheckForNull BaseFoldHandle getCurrentNestedFold() { return (currentChild != null && !currentChild.isFinished()) ? currentChild : null; @@ -145,8 +138,6 @@ * handle has been already finished. If an unfinished child fold exists, it * will be finished too. Any exception that could happen will be caught and * logged. - * - * @since openide.io/1.42 */ public void silentFinish() { if (!finished) { @@ -166,10 +157,8 @@ * @param expanded True to expand the new fold, false to collapse it, parent * folds will not be collapsed/expanded. * @return The new fold handle, or null if it cannot be created. - * - * @since openide.io/1.42 */ - public @CheckForNull FoldHandle silentStartFold(boolean expanded) { + public @CheckForNull BaseFoldHandle silentStartFold(boolean expanded) { if (!finished) { if (currentChild != null && !currentChild.finished) { currentChild.silentFinish(); diff --git a/openide.io/src/org/openide/windows/IOColorLines.java b/openide.io.base/src/org/openide/io/base/BaseIOColorLines.java copy from openide.io/src/org/openide/windows/IOColorLines.java copy to openide.io.base/src/org/openide/io/base/BaseIOColorLines.java --- a/openide.io/src/org/openide/windows/IOColorLines.java +++ b/openide.io.base/src/org/openide/io/base/BaseIOColorLines.java @@ -40,90 +40,118 @@ * Portions Copyrighted 2008 Sun Microsystems, Inc. */ -package org.openide.windows; +package org.openide.io.base; -import java.awt.Color; import java.io.IOException; +import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.api.annotations.common.NullAllowed; import org.openide.util.Lookup; /** * Line printing with custom color. *

* Client usage: + *

*
  *  // print green line
- *  InputOutput io = ...;
- *  IOColorLines.println(io, "Green line", Color.GREEN);
+ *  {@link BaseInputOutput} io = ...;
+ *  if (BaseIOColorLines.isSupported(io)) {
+ *      BaseIOColorLines.println(io, "Green line", Color.GREEN);
+ *  }
  * 
- * How to support {@link IOColorLines} in own {@link IOProvider} implementation: + * How to support {@link BaseIOColorLines} in own {@link BaseIOProvider} implementation: *
    - *
  • {@link InputOutput} provided by {@link IOProvider} has to implement {@link org.openide.util.Lookup.Provider} - *
  • Extend {@link IOColorLines} and implement its abstract methods - *
  • Place instance of {@link IOColorLines} to {@link Lookup} provided by {@link InputOutput} + *
  • Implement some {@link Provider} of BaseIOColorLines.
  • + *
  • Place instance of {@link Provider} to {@link Lookup} provided by {@link BaseInputOutput}.
  • *
- * @see IOColors - * @see IOColorPrint - * @since 1.16 - * @author Tomas Holy + * @see BaseIOColors + * @see BaseIOColorPrint + * @author Tomas Holy, Jaroslav Havlin */ -public abstract class IOColorLines { +public final class BaseIOColorLines { - private static IOColorLines find(InputOutput io) { - if (io instanceof Lookup.Provider) { - Lookup.Provider p = (Lookup.Provider) io; - return p.getLookup().lookup(IOColorLines.class); - } - return null; + private BaseIOColorLines() {} + + /** + * Prints line with selected color. + * + * @param io IO to print to. + * @param text A string to print to the tab. + * @param color A color for the line of text (null allowed). If null is + * passed default color (see {@link BaseIOColors}) is used. + * @throws java.io.IOException if printing to the output fails. + * @throws IllegalArgumentException if the I/O does not support this + * feature. + */ + public static void println( + @NonNull BaseInputOutput io, + @NonNull CharSequence text, + @NullAllowed BaseColor color) throws IOException { + println(io, text, false, color); } /** * Prints line with selected color - * @param io IO to print to - * @param text a string to print to the tab - * @param color a color for the line of text (null allowed). If null is passed default color (see {@link IOColors}) is used. + * + * @param io IO to print to. + * @param text A string to print to the tab. + * @param important Mark the line as important. Makes the UI respond + * appropriately, eg. stop the automatic scrolling or highlight the + * hyperlink. + * @param color A color for the line of text (null allowed). If null is + * passed default color (see {@link BaseIOColors}) is used. + * @param extendedInfo Output listener, output tag, or similar objects. See + * {@link BaseIOHyperlink}. + * @throws java.io.IOException if printing to the output fails. + * @throws IllegalArgumentException if the I/O does not support this + * feature. */ - public static void println(InputOutput io, CharSequence text, Color color) throws IOException { - IOColorLines iocl = find(io); - if (iocl != null) { - iocl.println(text, null, false, color); - } + public static void println( + @NonNull BaseInputOutput io, + @NonNull CharSequence text, + boolean important, + @NullAllowed BaseColor color, + @NonNull BaseIOLinkInfo... extendedInfo) + throws IOException { + + ExtrasHelper.getExtras(io, BaseIOColorLines.Provider.class).println( + text, important, color, extendedInfo); + } + + + /** + * Checks whether this feature is supported for provided IO. + * @param io IO to check on. + * @return True if supported. + */ + public static boolean isSupported(@NonNull BaseInputOutput io) { + return ExtrasHelper.isSupported(io, BaseIOColorLines.Provider.class); } /** - * Prints line with selected color - * @param io IO to print to - * @param text a string to print to the tab - * @param listener a listener that will receive events about this line - * @param important important mark the line as important. - * Makes the UI respond appropriately, eg. stop the automatic scrolling - * or highlight the hyperlink. - * @param color a color for the line of text (null allowed). If null is passed default color (see {@link IOColors}) is used. + * SPI for implementing support for color printing. + * @see BaseIOColorLines */ - public static void println(InputOutput io, CharSequence text, OutputListener listener, boolean important, Color color) throws IOException { - IOColorLines iocl = find(io); - if (iocl != null) { - iocl.println(text, listener, important, color); - } + public interface Provider { + + /** + * Prints line with selected color + * + * @param text A string to print to the tab. or other extension type, + * see {@link BaseIOHyperlink}. (null allowed) + * @param important Mark the line as important. Makes the UI respond + * appropriately, eg. stop the automatic scrolling or highlight the + * hyperlink. + * @param color A color for the line of text (null allowed). If null is + * passed default color (see {@link BaseIOColors}) is used. + * @param extendedInfo Output listener, output tag, or similar objects. + * See {@link BaseIOHyperlink}. + * @throws java.io.IOException if printing to the output fails. + */ + void println( + @NonNull CharSequence text, + boolean important, + @NullAllowed BaseColor color, + @NonNull BaseIOLinkInfo... extendedInfo) throws IOException; } - - - /** - * Checks whether this feature is supported for provided IO - * @param io IO to check on - * @return true if supported - */ - public static boolean isSupported(InputOutput io) { - return find(io) != null; - } - - /** - * Prints line with selected color - * @param text a string to print to the tab - * @param listener a listener that will receive events about this line (null allowed) - * @param important important mark the line as important. - * Makes the UI respond appropriately, eg. stop the automatic scrolling - * or highlight the hyperlink. - * @param color a color for the line of text (null allowed). If null is passed default color (see {@link IOColors}) is used. - */ - abstract protected void println(CharSequence text, OutputListener listener, boolean important, Color color) throws IOException; } diff --git a/openide.io/src/org/openide/windows/IOColorPrint.java b/openide.io.base/src/org/openide/io/base/BaseIOColorPrint.java copy from openide.io/src/org/openide/windows/IOColorPrint.java copy to openide.io.base/src/org/openide/io/base/BaseIOColorPrint.java --- a/openide.io/src/org/openide/windows/IOColorPrint.java +++ b/openide.io.base/src/org/openide/io/base/BaseIOColorPrint.java @@ -40,73 +40,83 @@ * Portions Copyrighted 2009 Sun Microsystems, Inc. */ -package org.openide.windows; +package org.openide.io.base; -import java.awt.Color; import java.io.IOException; +import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.api.annotations.common.NullAllowed; import org.openide.util.Lookup; /** * Text printing with custom color. *

* Client usage: + *

*
- *  InputOutput io = ...;
- *  OutputListener l = ...;
- *  OutputListener l2 = ...;
- *  IOColorPrint.print(io, "Green text", Color.GREEN);
- *  IOColorPrint.print(io, " orange hyperlink ", l, false, Color.ORANGE);
- *  IOColorPrint.print(io, " green hyperlink\n", l2, false, Color.GREEN);
- * 
- * How to support {@link IOColorPrint} in own {@link IOProvider} implementation: + BaseInputOutput io = ...; + BaseOutputListener l = ...; + BaseOutputListener l2 = ...; + if (BaseIOColorPrint.isSupported(io)) { + BaseIOColorPrint.print(io, "Green text", Color.GREEN); + BaseIOColorPrint.print(io, " orange hyperlink ", false, Color.ORANGE, l); + BaseIOColorPrint.print(io, " green hyperlink\n", false, Color.GREEN, l2); + } + + * How to support {@link BaseIOColorPrint} in own {@link BaseIOProvider} implementation: *
    - *
  • {@link InputOutput} provided by {@link IOProvider} has to implement {@link org.openide.util.Lookup.Provider} - *
  • Extend {@link IOColorPrint} and implement its abstract methods - *
  • Place instance of {@link IOColorPrint} to {@link Lookup} provided by {@link InputOutput} + *
  • Implement some {@link Provider} of BaseIOColorPrint.
  • + *
  • Place instance of {@link Provider} to {@link Lookup} provided by {@link BaseInputOutput}.
  • *
- * @see IOColors - * @see IOColorLines - * @since 1.18 - * @author Tomas Holy + * @see BaseIOColors + * @see BaseIOColorLines + * @author Tomas Holy, Jaroslav Havlin */ -public abstract class IOColorPrint { +public final class BaseIOColorPrint { - private static IOColorPrint find(InputOutput io) { - if (io instanceof Lookup.Provider) { - Lookup.Provider p = (Lookup.Provider) io; - return p.getLookup().lookup(IOColorPrint.class); - } - return null; - } + private BaseIOColorPrint() {} /** * Prints text with selected color - * @param io IO to print to - * @param text a string to print to the tab - * @param color a color for the text (null allowed). If null is passed default color (see {@link IOColors}) is used. + * @param io IO to print to. + * @param text A string to print to the tab. + * @param color A color for the text (null allowed). If null is passed + * default color (see {@link BaseIOColors}) is used. + * @throws java.io.IOException if printint to the output fails. + * @throws IllegalArgumentException if the I/O does not support this + * feature. */ - public static void print(InputOutput io, CharSequence text, Color color) throws IOException { - IOColorPrint iocl = find(io); - if (iocl != null) { - iocl.print(text, null, false, color); - } + public static void print( + @NonNull BaseInputOutput io, + @NonNull CharSequence text, + @NullAllowed BaseColor color) throws IOException { + print(io, text, false, color); } /** * Prints text with selected color and add listener for it - * @param io IO to print to - * @param text a string to print to the tab - * @param listener a listener that will receive events about this text (null allowed) - * @param important important mark the line as important. + * @param io IO to print to. + * @param text A string to print to the tab. + * @param important Mark the line as important. * Makes the UI respond appropriately, eg. stop the automatic scrolling * or highlight the hyperlink. - * @param color a color for the text (null allowed). If null is passed default color (see {@link IOColors}) is used. + * @param color A color for the text (null allowed). If null is passed + * default color (see {@link BaseIOColors}) is used. + * @param extendedInfo Output listeners, output tags or similar objects, see + * {@link BaseIOHyperlink}. + * @throws java.io.IOException if writing to the output fails. + * @throws IllegalArgumentException if the I/O does not support this + * feature. */ - public static void print(InputOutput io, CharSequence text, OutputListener listener, boolean important, Color color) throws IOException { - IOColorPrint iocl = find(io); - if (iocl != null) { - iocl.print(text, listener, important, color); - } + public static void print( + @NonNull BaseInputOutput io, + @NonNull CharSequence text, + boolean important, + @NullAllowed BaseColor color, + @NonNull BaseIOLinkInfo... extendedInfo) + throws IOException { + + ExtrasHelper.getExtras(io, BaseIOColorPrint.Provider.class).print( + text, important, color, extendedInfo); } @@ -115,18 +125,29 @@ * @param io IO to check on * @return true if supported */ - public static boolean isSupported(InputOutput io) { - return find(io) != null; + public static boolean isSupported(@NonNull BaseInputOutput io) { + return ExtrasHelper.isSupported(io, BaseIOColorPrint.Provider.class); } - /** - * Prints text with selected color and optionaly add listener for it - * @param text a string to print to the tab - * @param listener a listener that will receive events about this text (null allowed) - * @param important important mark the line as important. - * Makes the UI respond appropriately, eg. stop the automatic scrolling - * or highlight the hyperlink. - * @param color a color for the text (null allowed). If null is passed default color (see {@link IOColors}) is used. - */ - abstract protected void print(CharSequence text, OutputListener listener, boolean important, Color color) throws IOException; + public interface Provider { + + /** + * Prints text with selected color and optionaly add listener for it + * + * @param text A string to print to the tab. + * @param important Mark the line as important. Makes the UI + * respond appropriately, eg. stop the automatic scrolling or highlight + * the hyperlink. + * @param color A color for the text (null allowed). If null is passed + * default color (see {@link BaseIOColors}) is used. + * @param extendedInfo Output listener, output tag or similar objects, + * see {@link BaseIOHyperlink}. + * @throws java.io.IOException if writing to the output fails. + */ + void print( + @NonNull CharSequence text, + boolean important, + @NullAllowed BaseColor color, + @NonNull BaseIOLinkInfo... extendedInfo) throws IOException; + } } diff --git a/openide.io/src/org/openide/windows/IOColors.java b/openide.io.base/src/org/openide/io/base/BaseIOColors.java copy from openide.io/src/org/openide/windows/IOColors.java copy to openide.io.base/src/org/openide/io/base/BaseIOColors.java --- a/openide.io/src/org/openide/windows/IOColors.java +++ b/openide.io.base/src/org/openide/io/base/BaseIOColors.java @@ -40,41 +40,37 @@ * Portions Copyrighted 2008 Sun Microsystems, Inc. */ -package org.openide.windows; +package org.openide.io.base; -import java.awt.Color; +import org.netbeans.api.annotations.common.CheckForNull; +import org.netbeans.api.annotations.common.NonNull; import org.openide.util.Lookup; /** * Settings of colors for normal, error, hyperlink, important hyperlink lines. * Change is global for text past and future. *

- * Client usage: + * Client usage: + *

*
- *  // set important hyperlink color to red
- *  InputOutput io = ...;
- *  IOColors.setColor(io, IOColors.OutputType.HYPERLINK_IMPORTANT, Color.RED);
- * 
- * How to support {@link IOColors} in own {@link IOProvider} implementation: + // set important hyperlink color to red + BaseInputOutput io = ...; + if (BaseIOColors.isSupported(io)) { + BaseIOColors.setColor(io, BaseIOColors.OutputType.HYPERLINK_IMPORTANT, Color.RED); + } + + * How to support {@link BaseIOColors} in own {@link BaseIOProvider} implementation: *
    - *
  • {@link InputOutput} provided by {@link IOProvider} has to implement {@link org.openide.util.Lookup.Provider} - *
  • Extend {@link IOColors} and implement its abstract methods - *
  • Place instance of {@link IOColors} to {@link Lookup} provided by {@link InputOutput} + *
  • Implement some {@link Provider} of BaseIOColors. + *
  • Place instance of {@link BaseIOColors} to {@link Lookup} provided by {@link BaseInputOutput}. *
- * @see IOColorLines - * @see IOColorPrint - * @since 1.16 - * @author Tomas Holy + * @see BaseIOColorLines + * @see BaseIOColorPrint + * @author Tomas Holy, Jaroslav Havlin */ -public abstract class IOColors { +public final class BaseIOColors { - private static IOColors find(InputOutput io) { - if (io instanceof Lookup.Provider) { - Lookup.Provider p = (Lookup.Provider) io; - return p.getLookup().lookup(IOColors.class); - } - return null; - } + private BaseIOColors() {} /** * output types @@ -110,49 +106,67 @@ } /** - * Gets current color for output - * @param io InputOutput to operate on - * @param type output type to get color for - * @return current color for specified output type or null if not supported + * Gets current color for output. + * @param io {@link BaseInputOutput} to operate on. + * @param type Output type to get color for. + * @return Current color for specified output type or null if not supported. */ - public static Color getColor(InputOutput io, OutputType type) { - IOColors ioc = find(io); + public static @CheckForNull BaseColor getColor( + @NonNull BaseInputOutput io, + @NonNull OutputType type) { + + Provider ioc = ExtrasHelper.find(io, BaseIOColors.Provider.class); return ioc != null ? ioc.getColor(type) : null; } /** - * Sets specified color for output - * @param io InputOutput to operate on - * @param type output type to set color for - * @param color new color for specified output type + * Sets specified color for output. + * + * @param io {@link BaseInputOutput} to operate on. + * @param type Output type to set color for. + * @param color New color for specified output type. */ - public static void setColor(InputOutput io, OutputType type, Color color) { - IOColors ioc = find(io); + public static void setColor( + @NonNull BaseInputOutput io, + @NonNull OutputType type, + @NonNull BaseColor color) { + Provider ioc = ExtrasHelper.find(io, BaseIOColors.Provider.class); if (ioc != null) { ioc.setColor(type, color); } } /** - * Checks whether this feature is supported for provided IO - * @param io IO to check on - * @return true if supported + * Checks whether this feature is supported for provided IO. + * + * @param io IO to check on. + * @return True if supported. */ - public static boolean isSupported(InputOutput io) { - return find(io) != null; + public static boolean isSupported(@NonNull BaseInputOutput io) { + return ExtrasHelper.isSupported(io, BaseIOColors.Provider.class); } /** - * Gets current color for output - * @param type output type to get color for - * @return current color for specified output + * SPI for implementing support for output coloring. + * + * @see BaseIOColors */ - abstract protected Color getColor(OutputType type); + public interface Provider { - /** - * Sets specified color for output - * @param type output type to set color for - * @param color new color for specified output type - */ - abstract protected void setColor(OutputType type, Color color); + /** + * Gets current color for output. + * + * @param type Output type to get color for. + * @return Current color for specified output. + */ + @NonNull BaseColor getColor(@NonNull OutputType type); + + /** + * Sets specified color for output + * + * @param type Output type to set color for. + * @param color New color for specified output type. + */ + void setColor(@NonNull OutputType type, @NonNull BaseColor color); + } } diff --git a/openide.io/src/org/openide/windows/IOFolding.java b/openide.io.base/src/org/openide/io/base/BaseIOFolding.java copy from openide.io/src/org/openide/windows/IOFolding.java copy to openide.io.base/src/org/openide/io/base/BaseIOFolding.java --- a/openide.io/src/org/openide/windows/IOFolding.java +++ b/openide.io.base/src/org/openide/io/base/BaseIOFolding.java @@ -39,12 +39,11 @@ * * Portions Copyrighted 2013 Sun Microsystems, Inc. */ -package org.openide.windows; +package org.openide.io.base; import org.netbeans.api.annotations.common.CheckReturnValue; import org.netbeans.api.annotations.common.NonNull; import org.openide.util.Lookup; -import org.openide.util.Lookup.Provider; import org.openide.util.Parameters; /** @@ -53,15 +52,15 @@ * Client usage: *

*
- *  InputOutput io = ...;
- *  if (!IOFolding.isSupported(io)) {
+ *  BaseInputOutput io = ...;
+ *  if (!BaseIOFolding.isSupported(io)) {
  *    throw new Exception("Folding is not supported");
  *  }
  *  io.getOut().println("First Line - start of fold");
- *  FoldHandle fold = IOFolding.startFold(io, true);
+ *  BaseFoldHandle fold = BaseIOFolding.startFold(io, true);
  *  io.getOut().println("  Fold Content 1");
  *  io.getOut().println("  The first line of nested fold");
- *  FoldHandle nestedFold = fold.startFold(true);
+ *  BaseFoldHandle nestedFold = fold.startFold(true);
  *  io.getOut().println("     Nested fold content 1");
  *  nestedFold.finish();
  *  io.getOut().println("  Fold Content 2");
@@ -69,88 +68,77 @@
  *  io.getOut().println("Text outside of the fold.");
  * 
*

- * How to support {@link IOFolding} in own {@link IOProvider} implementation: + * How to support {@link BaseIOFolding} in own {@link BaseIOProvider} implementation: *

*
    - *
  • {@link InputOutput} provided by {@link IOProvider} has to implement - * {@link Provider}
  • - *
  • Extend {@link IOFolding} and implement its abstract methods
  • + *
  • Implement some {@link Provider} of BaseIOFolding
  • *
  • Extend {@link FoldHandleDefinition}
  • - *
  • Place instance of {@link IOFolding} to {@link Lookup} provided by - * {@link InputOutput}
  • + *
  • Place instance of {@link Provider} to {@link Lookup} provided by + * {@link BaseInputOutput}
  • *
* * @author jhavlin * @since openide.io/1.38 */ -public abstract class IOFolding { +public final class BaseIOFolding { + + private BaseIOFolding() {} /** - * Check whether an {@link InputOutput} supports folding. + * Check whether an {@link BaseInputOutput} supports folding. * - * @param io The InputOutput to check. - * @return True if {@link #startFold(InputOutput, boolean)} can be used with - * {@code io}, false otherwise. + * @param io The {@link BaseInputOutput} to check. + * @return True if {@link #startFold(BaseInputOutput, boolean)} can be used + * with {@code io}, false otherwise. */ - public static boolean isSupported(@NonNull InputOutput io) { + public static boolean isSupported(@NonNull BaseInputOutput io) { Parameters.notNull("parent", io); //NOI18N - return findIOFolding(io) != null; + return ExtrasHelper.isSupported(io, BaseIOFolding.Provider.class); } - /** - * Find folding support in an {@link InputOutput} object. - * - * @return IOFolding object if folding is supported by the {@code parent} - * object, null otherwise. - */ - private static IOFolding findIOFolding(InputOutput parent) { - return (parent instanceof Lookup.Provider) - ? ((Lookup.Provider) parent).getLookup().lookup(IOFolding.class) - : null; + public interface Provider { + + /** + * Create a fold handle definition for the current last line in the + * output window. + * + * @param expanded Initial state of the fold. + * @return FoldHandleDefinition for the fold handle. Never null. + * + * @throws IllegalStateException if the last fold hasn't been finished + * yet. + */ + @NonNull + FoldHandleDefinition startFold(boolean expanded); } /** - * Create a fold handle definition for the current last line in the output - * window. - * - * @param expanded Initial state of the fold. - * @return FoldHandleDefinition for the fold handle. Never null. - * - * @throws IllegalStateException if the last fold hasn't been finished yet. - */ - @NonNull - protected abstract FoldHandleDefinition startFold(boolean expanded); - - /** * Create a fold handle for the current last line in the output window. * - * @param io InputOutput to create the fold in. + * @param io {@link BaseInputOutput} to create the fold in. * @param expanded Initial state of the fold. * @return The fold handle that can be used to finish the fold or to create * nested folds. * @throws IllegalStateException if the last fold hasn't been finished yet. * @throws UnsupportedOperationException if folding is not supported by the - * InputOutput object. + * {@link BaseInputOutput} object. */ @CheckReturnValue @NonNull - public static FoldHandle startFold( - @NonNull InputOutput io, boolean expanded) { + public static BaseFoldHandle startFold( + @NonNull BaseInputOutput io, boolean expanded) { Parameters.notNull("io", io); //NOI18N - IOFolding folding = findIOFolding(io); - if (folding == null) { - throw new UnsupportedOperationException( - "The InputOutput doesn't support folding"); //NOI18N - } else { - return new FoldHandle(folding.startFold(expanded)); - } + BaseIOFolding.Provider folding = ExtrasHelper.getExtras(io, + BaseIOFolding.Provider.class); + + return new BaseFoldHandle(folding.startFold(expanded)); } /** * An SPI for creating custom FoldHandle implementations. */ - protected static abstract class FoldHandleDefinition { + public interface FoldHandleDefinition { /** * Finish the fold at the current last line. Ensure that nested folds @@ -159,7 +147,7 @@ * @throws IllegalStateException if parent fold has been already * finished, or if there is an unfinished nested fold. */ - public abstract void finish(); + public void finish(); /** * Start a new fold at the current last line. Ensure that the parent @@ -171,7 +159,7 @@ * @throws IllegalStateException if the fold has been already finished, * or if the last nested fold hasn't been finished yet. */ - public abstract FoldHandleDefinition startFold(boolean expanded); + public FoldHandleDefinition startFold(boolean expanded); /** * Set state of the fold. @@ -180,6 +168,6 @@ * * @param expanded True to expand the fold, false to collapse it. */ - public abstract void setExpanded(boolean expanded); + public void setExpanded(boolean expanded); } } diff --git a/openide.io.base/src/org/openide/io/base/BaseIOHyperlink.java b/openide.io.base/src/org/openide/io/base/BaseIOHyperlink.java new file mode 100644 --- /dev/null +++ b/openide.io.base/src/org/openide/io/base/BaseIOHyperlink.java @@ -0,0 +1,201 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 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 2014 Sun Microsystems, Inc. + */ +package org.openide.io.base; + +import java.io.IOException; +import org.netbeans.api.annotations.common.NonNull; +import org.openide.util.Lookup; + +/** + * Text printing with listeners, tags, or custom extension types. + * + *

+ * Client usage: + *

+ *
+  BaseInputOutput io = ...;
+  BaseOutputListener l = ...;
+  BaseOutputTag t = ...;
+
+  // check only one extension type
+  if (BaseIOHyperlink.isSupported(io, BaseOutputListener.class) {
+    BaseIOHyperlink.println(io, "Link", false, l);
+  }
+
+  // to print a single line with several extensions
+  if (BaseIOHyperlink.isSupported(io)) { //check extensions supported at all
+    List<Object> exts = new LinkedList<Object>();
+    if (BaseIOHyperlink.isSupported(io, BaseOutputListener.class)) {
+      exts.add(new MyOutputListener());
+    }
+    if (BaseIOHyperlink.isSupported(io, BaseOutputTag.class)) {
+      exts.add(new MyOutputTag());
+    }
+    BaseIOHyperlink.println(io, "Link 2", false, exts.toArray(new Object[exts.size()]));
+  }
+
+ 
+ * How to support {@link BaseIOHyperlink} in own {@link BaseIOProvider} implementation: + *
    + *
  • Implement some {@link Provider} of BaseIOHyperlink.
  • + *
  • Place instance of {@link Provider} to {@link Lookup} provided by {@link BaseInputOutput}.
  • + *
+ * + * @author Jaroslav Havlin + */ +public final class BaseIOHyperlink { + + private BaseIOHyperlink() {} + + public enum Type { + + OUT, ERR; + } + + /** + * Check whether BaseIOHyperlink extension is supported by the I/O. + * + * @param io The I/O to check for support of BaseIOHyperlink. + * @return True if BaseIOHyperlink is supported by the I/O, false otherwise. + */ + public static boolean isSupported(@NonNull BaseInputOutput io) { + return ExtrasHelper.isSupported(io, BaseIOHyperlink.Provider.class); + } + + /** + * Print a line which will be displayed as a hyperlink, calling the action + * specified in the array object if it is clicked. + * + * @param io I/O to print into. + * @param type Type of output, standard or error. + * @param str a string to print to the tab + * @param important mark the line as important. Makes the UI respond + * appropriately, eg. stop the automatic scrolling or highlight the + * hyperlink. + * @param linkInfo array containing extending info for the text, e.g. + * an output listener and/or an output tag. + * @throws IOException if the string could not be printed + * @throws IllegalArgumentException if the I/O does not support this feature. + */ + public static void println( + @NonNull BaseInputOutput io, + @NonNull Type type, + @NonNull String str, + boolean important, + @NonNull BaseIOLinkInfo... linkInfo) throws IOException { + ExtrasHelper.getExtras(io, BaseIOHyperlink.Provider.class).println( + type, str, important, linkInfo); + } + + /** + * Print a line which will be displayed as a hyperlink, calling the action + * specifided in the {@link Lookup} object if it is clicked, if the caret + * enters it, or if the enter key is pressed over it. + * + * @param io I/O to print into. + * @param type Type of output, standard or error. + * @param str a string to print to the tab + * @param linkInfo array containing extending info for the text, e.g. + * an output listener and/or an output tag. + * @throws IOException if the string could not be printed + * @throws IllegalArgumentException if the I/O does not support this feature. + */ + public static void println( + @NonNull BaseInputOutput io, + @NonNull Type type, + @NonNull String str, + @NonNull BaseIOLinkInfo... linkInfo) throws IOException { + println(io, type, str, false, linkInfo); + } + + /** + * Check whether BaseIOHyperlink is supported by the I/O and that its lines + * can be extended with link info of class {@code cls}. + * + * @param io I/O object to get extending types from. + * @param cls The link info class that we want to check the support for. + * @return True if the I/O supports {@link BaseIOHyperlink} and if it can be + * extended with instances of class {@code cls}. + */ + public static boolean isSupported( + @NonNull BaseInputOutput io, + @NonNull Class cls) { + Provider p = ExtrasHelper.find(io, Provider.class); + return p == null + ? false + : p.isSupported(cls); + } + + /** + * SPI for implementing support for {@link BaseIOHyperlink}. + */ + public interface Provider { + + /** + * Check whether passed class or interface is supported by this + * implementation of BaseOutputWriter and can be put to the array passed + * to + * {@link #println(BaseIOHyperlink.Type, String, boolean, BaseIOLinkInfo...)}. + * + * @param cls Class or interface to check + * @return True if class or interface {@code cls} is supported. + */ + boolean isSupported(@NonNull Class cls); + + /** + * Print a line which will be displayed as a hyperlink, calling the + * action specifided in the array object if it is clicked. + * + * @param type Type of the output, {@link Type#OUT} for standard output, + * {@link Type#ERR} for error output. + * @param s a string to print to the tab + * @param linkInfo array containing extending info for the text, + * e.g. an output listener and/or an output tag. + * @param important mark the line as important. Makes the UI respond + * appropriately, eg. stop the automatic scrolling or highlight the + * hyperlink. + * @throws IOException if the string could not be printed. + */ + void println(@NonNull Type type, @NonNull String s, boolean important, + @NonNull BaseIOLinkInfo... linkInfo) throws IOException; + } +} diff --git a/openide.io.base/src/org/openide/io/base/BaseIOLinkInfo.java b/openide.io.base/src/org/openide/io/base/BaseIOLinkInfo.java new file mode 100644 --- /dev/null +++ b/openide.io.base/src/org/openide/io/base/BaseIOLinkInfo.java @@ -0,0 +1,51 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 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 2014 Sun Microsystems, Inc. + */ +package org.openide.io.base; + +/** + * Marker interface for classes that can be used as extending link info for + * {@link BaseIOHyperlink}. + * + * @author jhavlin + */ +public interface BaseIOLinkInfo { +} diff --git a/openide.io/src/org/openide/windows/IOPosition.java b/openide.io.base/src/org/openide/io/base/BaseIOPosition.java copy from openide.io/src/org/openide/windows/IOPosition.java copy to openide.io.base/src/org/openide/io/base/BaseIOPosition.java --- a/openide.io/src/org/openide/windows/IOPosition.java +++ b/openide.io.base/src/org/openide/io/base/BaseIOPosition.java @@ -40,40 +40,37 @@ * Portions Copyrighted 2008 Sun Microsystems, Inc. */ -package org.openide.windows; +package org.openide.io.base; +import org.netbeans.api.annotations.common.CheckForNull; +import org.netbeans.api.annotations.common.NonNull; import org.openide.util.Lookup; /** * Navigation (scrolling) in IO component. - *

+ *

* Client usage: + *

*
- *  InputOutput io = ...;
- *  // store current position of IO
- *  IOPosition.Position pos = IOPosition.currentPosition(io);
- *  ...
- *  // scroll to stored position
- *  pos.scrollTo();
- * 
- * How to support {@link IOPosition} in own {@link IOProvider} implementation: + BaseInputOutput io = ...; + // store current position of IO + Position pos = BaseIOPosition.currentPosition(io); + ... + // scroll to stored position + pos.scrollTo(); + How to support {@link BaseIOPosition} in own {@link BaseIOProvider} + * implementation: *
    - *
  • {@link InputOutput} provided by {@link IOProvider} has to implement {@link org.openide.util.Lookup.Provider} - *
  • Extend {@link IOPosition} and implement its abstract methods - *
  • Place instance of {@link IOPosition} to {@link Lookup} provided by {@link InputOutput} + *
  • Implement {@link Provider} and implement its methods. + *
  • Place instance of {@link Provider} to {@link Lookup} provided by + * {@link BaseInputOutput} *
- * @since 1.16 - * @author Tomas Holy + * + * @author Tomas Holy, Jaroslav Havlin */ -public abstract class IOPosition { +public final class BaseIOPosition { - private static IOPosition find(InputOutput io) { - if (io instanceof Lookup.Provider) { - Lookup.Provider p = (Lookup.Provider) io; - return p.getLookup().lookup(IOPosition.class); - } - return null; - } + private BaseIOPosition() {} public interface Position { void scrollTo(); @@ -81,11 +78,13 @@ /** * Gets current position (in number of chars) in IO - * @param io IO to operate on - * @return current position or null if not supported + * @param io IO to operate on. + * @return Current position or null if not supported. */ - public static Position currentPosition(InputOutput io) { - IOPosition iop = find(io); + public static @CheckForNull Position currentPosition( + @NonNull BaseInputOutput io) { + + Provider iop = ExtrasHelper.find(io, Provider.class); return iop != null ? iop.currentPosition() : null; } @@ -94,13 +93,17 @@ * @param io IO to check on * @return true if supported */ - public static boolean isSupported(InputOutput io) { - return find(io) != null; + public static boolean isSupported(BaseInputOutput io) { + return ExtrasHelper.isSupported(io, Provider.class); } - /** - * Gets current position in IO - * @return current position - */ - abstract protected Position currentPosition(); + public interface Provider { + + /** + * Gets current position in IO + * + * @return current position + */ + Position currentPosition(); + } } diff --git a/openide.io.base/src/org/openide/io/base/BaseIOProvider.java b/openide.io.base/src/org/openide/io/base/BaseIOProvider.java new file mode 100644 --- /dev/null +++ b/openide.io.base/src/org/openide/io/base/BaseIOProvider.java @@ -0,0 +1,329 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 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 2014 Sun Microsystems, Inc. + */ +package org.openide.io.base; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintStream; +import java.io.PrintWriter; +import java.io.Reader; +import java.io.StringWriter; +import java.util.Collection; +import java.util.EventListener; +import org.netbeans.api.annotations.common.NonNull; +import org.openide.util.Lookup; + +/** + * A factory for IO tabs. To create a new tab to write to, call e.g. + * BaseIOProvider.getDefault().getIO("MyTab", false) (pass true if + * there may be an existing tab with the same name and you want to write to a + * new tab). + * + * @author jhavlin + */ +public abstract class BaseIOProvider { + + public static @NonNull BaseIOProvider getDefault() { + BaseIOProvider iopb = Lookup.getDefault().lookup(BaseIOProvider.class); + if (iopb == null) { + iopb = new Trivial(); + } + return iopb; + } + + /** + * Gets BaseIOProvider of selected name or delegates to getDefault() if none + * was found. + * + * @param name ID of provider. + * @return The instance corresponding to provided name or default instance + * if not found. + */ + public static @NonNull BaseIOProvider get(@NonNull String name) { + Collection res = Lookup.getDefault().lookupAll( + BaseIOProvider.class); + for (BaseIOProvider iop : res) { + if (iop.getName().equals(name)) { + return iop; + } + } + return getDefault(); + } + + /** + * Gets name (ID) of provider + * + * @return name of provider + */ + public abstract @NonNull String getName(); + + /** + * Get a named instance of {@link BaseInputOutput}, which represents an + * output tab in the output window. Streams for reading/writing can be + * accessed via getters on the returned instance. + * + * @param name A localised display name for the tab. + * @param newIO If true, a new {@link BaseInputOutput} is returned, + * else an existing {@link BaseInputOutput} of the same name may be + * returned. + * @param actions Objects that specify actions available in the I/O tab, + * usually {@link javax.swing.Action} instances, possibly + * {@link BaseOutputTag} instances, depending on what the BaseIOProvider + * supports. + * @return An {@link BaseInputOutput} instance for accessing the new tab. + * @see BaseInputOutput + */ + public abstract @NonNull + BaseInputOutput getIO( + @NonNull String name, boolean newIO, EventListener... actions); + + /** + * Check whether this implementation supports action type {@code cls}. + * + * @param cls Action type to check the support for. + * + * @return True if the passed type can be used for specifying actions for + * the output tab, false if the passed type is not supported. + * + * @see #getIO(java.lang.String, boolean, java.util.EventListener...) + */ + public abstract boolean isActionTypeSupported( + @NonNull Class cls); + + /** + * Fallback implementation. + */ + private static final class Trivial extends BaseIOProvider { + + private static final Reader in = new BufferedReader( + new InputStreamReader(System.in)); + private static final PrintStream out = System.out; + private static final PrintStream err = System.err; + + public Trivial() { + } + + @Override + public String getName() { + return "Trivial"; //NOI18N + } + + @Override + public BaseInputOutput getIO(String name, boolean newIO, + EventListener... actions) { + return new TrivialIO(name); + } + + @Override + public boolean isActionTypeSupported( + Class cls) { + return false; + } + + @SuppressWarnings("deprecation") + private final class TrivialIO implements BaseInputOutput { + + private final String name; + + public TrivialIO(String name) { + this.name = name; + } + + @Override + public Reader getIn() { + return in; + } + + @Override + public PrintWriter getOut() { + return new TrivialOW(out, name); + } + + @Override + public PrintWriter getErr() { + return new TrivialOW(err, name); + } + + public Reader flushReader() { + return getIn(); + } + + @Override + public boolean isClosed() { + return false; + } + + @Override + public void closeInputOutput() { + } + + @Override + public void reset() { + } + + @Override + public Lookup getLookup() { + return Lookup.EMPTY; + } + } + + private static final class TrivialOW extends PrintWriter { + + private static int count = 0; + private final String name; + private final PrintStream stream; + + @SuppressWarnings("ValueOfIncrementOrDecrementUsed") + public TrivialOW(PrintStream stream, String name) { + // XXX using super(new PrintWriter(stream)) does not seem to work for some reason! + super(new StringWriter()); + this.stream = stream; + if (name != null) { + this.name = name; + } else { + this.name = "anon-" + ++count; // NOI18N + } + } + + private void prefix(boolean hyperlink) { + if (hyperlink) { + stream.print("[" + name + "]* "); // NOI18N + } else { + stream.print("[" + name + "] "); // NOI18N + } + } + + @Override + public void println(float x) { + prefix(false); + stream.println(x); + } + + @Override + public void println(double x) { + prefix(false); + stream.println(x); + } + + @Override + public void println() { + prefix(false); + stream.println(); + } + + @Override + public void println(Object x) { + prefix(false); + stream.println(x); + } + + @Override + public void println(int x) { + prefix(false); + stream.println(x); + } + + @Override + public void println(char x) { + prefix(false); + stream.println(x); + } + + @Override + public void println(long x) { + prefix(false); + stream.println(x); + } + + @Override + @SuppressWarnings("ImplicitArrayToString") + public void println(char[] x) { + prefix(false); + stream.println(x); + } + + @Override + public void println(boolean x) { + prefix(false); + stream.println(x); + } + + @Override + public void println(String x) { + prefix(false); + stream.println(x); + } + + @Override + public void write(int c) { + stream.write(c); + } + + @Override + public void write(char[] buf, int off, int len) { + String s = new String(buf, off, len); + if (s.endsWith("\n")) { + println(s.substring(0, s.length() - 1)); + } else { + try { + stream.write(s.getBytes()); + } catch (IOException x) { + } + } + } + + @Override + public void write(String s, int off, int len) { + String sub = s.substring(off, off + len); + if (sub.endsWith("\n")) { + println(sub.substring(0, sub.length() - 1)); + } else { + try { + stream.write(sub.getBytes()); + } catch (IOException x) { + } + } + } + } + } +} diff --git a/openide.io/src/org/openide/windows/IOSelect.java b/openide.io.base/src/org/openide/io/base/BaseIOSelect.java copy from openide.io/src/org/openide/windows/IOSelect.java copy to openide.io.base/src/org/openide/io/base/BaseIOSelect.java --- a/openide.io/src/org/openide/windows/IOSelect.java +++ b/openide.io.base/src/org/openide/io/base/BaseIOSelect.java @@ -40,74 +40,70 @@ * Portions Copyrighted 2010 Sun Microsystems, Inc. */ -package org.openide.windows; +package org.openide.io.base; import java.util.Set; -import org.openide.util.Lookup; +import org.netbeans.api.annotations.common.NonNull; import org.openide.util.Parameters; /** - * Capability of an InputOutput of finer grained selection of a component. - *

- * InputOutput.select() does too much. - * @author ivan - * @since 1.23 + * Capability of an {@link BaseInputOutput} of fine grained selection of a + * component. + * + * @author ivan, Jaroslav Havlin */ -public abstract class IOSelect { +public final class BaseIOSelect { + + private BaseIOSelect() {} /** - * Additional operations to perform when issuing {@link IOSelect#select}. + * Additional operations to perform when selecting the output tab. * @author ivan */ public static enum AdditionalOperation { - /** - * Additionally issue open() on the TopComponent containing the InputOutput. - */ + /** + * Additionally issue open() on the TopComponent containing the + * {@link BaseInputOutput}. + */ OPEN, /** - * Additionally issue requestVisible() on the TopComponent containing the InputOutput. + * Additionally issue requestVisible() on the TopComponent containing + * the {@link BaseInputOutput}. */ REQUEST_VISIBLE, /** - * Additionally issue requestActive() on the TopComponent containing the InputOutput. + * Additionally issue requestActive() on the TopComponent containing + * the {@link BaseInputOutput}. */ REQUEST_ACTIVE } - private static IOSelect find(InputOutput io) { - if (io instanceof Lookup.Provider) { - Lookup.Provider p = (Lookup.Provider) io; - return p.getLookup().lookup(IOSelect.class); - } - return null; - } - /** * With an empty 'extraOps' simply selects this io * without involving it's containing TopComponent. *

* For example: + *

*
-     * if (IOSelect.isSupported(io) {
-     *     IOSelect.select(io, EnumSet.noneOf(IOSelect.AdditionalOperation.class));
+     * if (BaseIOSelect.isSupported(io) {
+     *     BaseIOSelect.select(io, EnumSet.noneOf(IOSelect.AdditionalOperation.class));
      * }
      * 
*

- * If this capability is not supported then regular InputOutput.select() - * will be called. - * @param io InputOutput to operate on. + * If this capability is not supported then no operation will be performed. + *

+ * @param io {@link BaseInputOutput} to operate on. * @param extraOps Additional operations to apply to the containing * TopComponent. */ - public static void select(InputOutput io, Set extraOps) { + public static void select(BaseInputOutput io, Set extraOps) { Parameters.notNull("extraOps", extraOps); // NOI18N - IOSelect ios = find(io); - if (ios != null) - ios.select(extraOps); - else - io.select(); // fallback + Provider ios = ExtrasHelper.find(io, Provider.class); + if (ios != null) { + ios.select(extraOps); + } } /** @@ -115,15 +111,19 @@ * @param io IO to check on * @return true if supported */ - public static boolean isSupported(InputOutput io) { - return find(io) != null; + public static boolean isSupported(BaseInputOutput io) { + return ExtrasHelper.isSupported(io, Provider.class); } - /** - * With an empty 'extraOps' simply selects this io - * without involving it's containing TopComponent. - * @param extraOps Additional operations to apply to the containing - * TopComponent. - */ - abstract protected void select(Set extraOps); + public interface Provider { + + /** + * With an empty 'extraOps' simply selects this io without involving + * it's containing TopComponent. + * + * @param extraOps Additional operations to apply to the containing + * TopComponent. + */ + void select(@NonNull Set extraOps); + } } diff --git a/openide.io/src/org/openide/windows/IOTab.java b/openide.io.base/src/org/openide/io/base/BaseIOTab.java copy from openide.io/src/org/openide/windows/IOTab.java copy to openide.io.base/src/org/openide/io/base/BaseIOTab.java --- a/openide.io/src/org/openide/windows/IOTab.java +++ b/openide.io.base/src/org/openide/io/base/BaseIOTab.java @@ -40,9 +40,11 @@ * Portions Copyrighted 2008 Sun Microsystems, Inc. */ -package org.openide.windows; +package org.openide.io.base; -import javax.swing.Icon; +import org.netbeans.api.annotations.common.CheckForNull; +import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.api.annotations.common.NullAllowed; import org.openide.util.Lookup; /** @@ -51,68 +53,41 @@ * Client usage: *
  *  // settings of IO tab icon, tooltip
- *  InputOutput io = ...;
- *  Icon icon = ...;
- *  IOTab.setIcon(io, icon);
- *  IOTab.setToolTipText(io, "text");
+ *  BaseInputOutput io = ...;
+ *  BaseIOTab.setToolTipText(io, "text");
  * 
- * How to support {@link IOTab} in own {@link IOProvider} implementation: + * How to support {@link BaseIOTab} in own {@link BaseIOProvider} implementation: *
    - *
  • {@link InputOutput} provided by {@link IOProvider} has to implement {@link org.openide.util.Lookup.Provider} - *
  • Extend {@link IOTab} and implement its abstract methods - *
  • Place instance of {@link IOTab} to {@link Lookup} provided by {@link InputOutput} + *
  • Implement {@link Provider}.
  • + *
  • Place instance of {@link Provider} to {@link Lookup} provided by {@link BaseInputOutput}.
  • *
- * @since 1.15 - * @author Tomas Holy + * @author Tomas Holy, Jaroslav Havlin */ -public abstract class IOTab { - private static IOTab find(InputOutput io) { - if (io instanceof Lookup.Provider) { - Lookup.Provider p = (Lookup.Provider) io; - return p.getLookup().lookup(IOTab.class); - } - return null; - } +public final class BaseIOTab { - /** - * Gets current tab icon for specified IO - * @param io IO to operate on - * @return current tab icon or null if not supported - */ - public static Icon getIcon(InputOutput io) { - IOTab iot = find(io); - return iot != null ? iot.getIcon() : null; - } - - /** - * Sets icon to tab corresponding to specified IO - * @param io IO to operate on - * @param icon tab icon - */ - public static void setIcon(InputOutput io, Icon icon) { - IOTab iot = find(io); - if (iot != null) { - iot.setIcon(icon); - } - } + private BaseIOTab() {} /** * Gets current tool tip text for specified IO - * @param io IO to operate on - * @return current tool tip text or null if not supported + * @param io IO to operate on. + * @return Current tool tip text or null if not supported. */ - public static String getToolTipText(InputOutput io) { - IOTab iot = find(io); + public static @CheckForNull String getToolTipText( + @NonNull BaseInputOutput io) { + + Provider iot = ExtrasHelper.find(io, Provider.class); return iot != null ? iot.getToolTipText() : null; } /** * Sets tool tip text to tab corresponding to specified IO - * @param io IO to operate on - * @param text new tool tip text + * @param io IO to operate on. + * @param text New tool tip text. */ - public static void setToolTipText(InputOutput io, String text) { - IOTab iot = find(io); + public static void setToolTipText( + @NonNull BaseInputOutput io, + @NullAllowed String text) { + Provider iot = ExtrasHelper.find(io, Provider.class); if (iot != null) { iot.setToolTipText(text); } @@ -120,35 +95,30 @@ /** * Checks whether this feature is supported for provided IO - * @param io IO to check on - * @return true if supported + * @param io IO to check on. + * @return True if supported. */ - public static boolean isSupported(InputOutput io) { - return find(io) != null; + public static boolean isSupported(BaseInputOutput io) { + return ExtrasHelper.isSupported(io, Provider.class); } /** - * Gets current tab icon - * @return current tab icon + * SPI for implementation of {@link BaseIOTab} support. */ - abstract protected Icon getIcon(); + public interface Provider { + /** + * Gets current tool tip text. + * + * @return Current tool tip text. + */ + @CheckForNull String getToolTipText(); - /** - * Sets icon to tab - * @param icon tab icon - */ - abstract protected void setIcon(Icon icon); - - /** - * Gets current tool tip text - * @return current tool tip text - */ - abstract protected String getToolTipText(); - - /** - * Sets tool tip text to tab - * @param text new tool tip text - */ - abstract protected void setToolTipText(String text); + /** + * Sets tool tip text to tab. + * + * @param text New tool tip text. + */ + void setToolTipText(@NullAllowed String text); + } } diff --git a/openide.io.base/src/org/openide/io/base/BaseInputOutput.java b/openide.io.base/src/org/openide/io/base/BaseInputOutput.java new file mode 100644 --- /dev/null +++ b/openide.io.base/src/org/openide/io/base/BaseInputOutput.java @@ -0,0 +1,112 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 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 2014 Sun Microsystems, Inc. + */ +package org.openide.io.base; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.Reader; +import org.openide.util.Lookup; + +/** + * An I/O connection to one tab on the Output Window. To acquire an instance to + * write to, call, e.g., + * BaseIOProvider.getDefault().getIO("someName", false). To get + * actual streams to write to, call getOut() or + * getErr() on the returned instance. + *

+ * Generally it is preferable not to hold a reference to an instance of + * {@link org.openide.io.base.BaseInputOutput}, but rather to fetch it by name + * from {@link org.openide.io.base.BaseIOProvider} as needed. + *

+ * + * @author Ian Formanek, Jaroslav Tulach, Petr Hamernik, Ales Novak, Jan + * Jancura, Jaroslav Havlin + */ +public interface BaseInputOutput extends Lookup.Provider { + + /** + * Acquire an output writer to write to the tab. This is the usual use of a + * tab--it writes to the main output pane. + * + * @return the writer + */ + public PrintWriter getOut(); + + /** + * Get a reader to read from the tab. If a reader is ever requested, an + * input line is added to the tab and used to read one line at a time. + * + * @return the reader + */ + public Reader getIn(); + + /** + * Get an output writer to write to the tab in error mode. This might show + * up in a different color than the regular output, e.g., or appear in a + * separate pane. + * + * @return the writer + */ + public PrintWriter getErr(); + + /** + * Closes this tab. The effect of calling any method on an instance of + * {@link BaseInputOutput} after calling {@link #closeInputOutput()} on it + * is undefined. + */ + public void closeInputOutput(); + + /** + * Test whether this tab has been closed, either by a call to + * closeInputOutput() or by the user closing the tab in the UI. + * + * @see #closeInputOutput + * @return true if it is closed + */ + public boolean isClosed(); + + /** + * Clean the output area. + * @throws java.io.IOException + */ + void reset() throws IOException; +} diff --git a/openide.io.base/src/org/openide/io/base/BaseOutputEvent.java b/openide.io.base/src/org/openide/io/base/BaseOutputEvent.java new file mode 100644 --- /dev/null +++ b/openide.io.base/src/org/openide/io/base/BaseOutputEvent.java @@ -0,0 +1,70 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 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 2014 Sun Microsystems, Inc. + */ +package org.openide.io.base; + +/** + * Event fired when something happens to a line in the Output Window. + * + * @author Jaroslav Tulach, Petr Hamernik, Jaroslav Havlin + */ +public abstract class BaseOutputEvent extends java.util.EventObject { + /** generated Serialized Version UID */ + static final long serialVersionUID = 4809584286971828815L; + /** Create an event. + * @param src the tab in question + */ + public BaseOutputEvent (BaseInputOutput src) { + super (src); + } + + /** Get the text on the line. + * @return the text + */ + public abstract String getLine (); + + /** Get the Output Window tab in question. + * @return the tab + */ + public BaseInputOutput getInputOutput() { + return (BaseInputOutput) getSource(); + } +} diff --git a/openide.io.base/src/org/openide/io/base/BaseOutputListener.java b/openide.io.base/src/org/openide/io/base/BaseOutputListener.java new file mode 100644 --- /dev/null +++ b/openide.io.base/src/org/openide/io/base/BaseOutputListener.java @@ -0,0 +1,59 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 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 2014 Sun Microsystems, Inc. + */ +package org.openide.io.base; + +/** + * Listener to actions taken on a line in the Output Window. + * + * @author Jaroslav Tulach + * @version 0.11 Dec 01, 1997 + */ +public interface BaseOutputListener extends java.util.EventListener, + BaseIOLinkInfo { + + /** + * Called when some sort of action is performed on a line. + * + * @param ev the event describing the line + */ + void outputLineAction(BaseOutputEvent ev); +} diff --git a/openide.io.base/src/org/openide/io/base/BaseOutputTag.java b/openide.io.base/src/org/openide/io/base/BaseOutputTag.java new file mode 100644 --- /dev/null +++ b/openide.io.base/src/org/openide/io/base/BaseOutputTag.java @@ -0,0 +1,77 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 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 2014 Sun Microsystems, Inc. + */ +package org.openide.io.base; + +import java.util.EventListener; +import java.util.Set; + +/** + * Base class for adding tagging information to output text. + * + * @author jhavlin + */ +public interface BaseOutputTag extends BaseIOLinkInfo, EventListener { + + /** + * Get type of this tag. + * + * @return Type of the tag. + */ + String getType(); + + /** + * Get value of an attribute specified by name. + * + * @param attributeName Name of the attribute. + * @return Value of the attribute, or null if it is not available. + * @throws IllegalArgumentException If tag of this type should not be + * queried for attribute of name {@code attributeName}. + */ + Object getAttribute(String attributeName); + + /** + * Get set of names of available attributes. + * + * @return Set of attribute names. + */ + Set getAttributeNames(); +} diff --git a/openide.io.base/src/org/openide/io/base/Bundle.properties b/openide.io.base/src/org/openide/io/base/Bundle.properties new file mode 100644 --- /dev/null +++ b/openide.io.base/src/org/openide/io/base/Bundle.properties @@ -0,0 +1,1 @@ +OpenIDE-Module-Name=Base I/O APIs diff --git a/openide.io.base/src/org/openide/io/base/ExtrasHelper.java b/openide.io.base/src/org/openide/io/base/ExtrasHelper.java new file mode 100644 --- /dev/null +++ b/openide.io.base/src/org/openide/io/base/ExtrasHelper.java @@ -0,0 +1,100 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2014 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 2014 Sun Microsystems, Inc. + */ +package org.openide.io.base; + +/** + * Helper class for finding extensions in I/O's lookup. + * + * @author jhavlin + */ +class ExtrasHelper { + + private ExtrasHelper() {} + + /** + * Check whether class {@code extras} is present in the I/O's lookup. + * + * @param io I/O to check + * @param extras Extension class that should be supported. + * + * @return True if the I/O supports the extension class, false otherwise. + */ + static boolean isSupported(BaseInputOutput io, Class extras) { + Object o = io.getLookup().lookup(extras); + return o != null; + } + + /** + * Get extension of given type, or throw an exception if it is not present. + * + * @param Type of the extension. + * @param io I/O to get the extension for. + * @param cls Extension class. + * + * @return The extension object of given type. + * @throws IllegalArgumentException If the I/O does not support this + * extension type. + */ + static T getExtras(BaseInputOutput io, Class cls) { + T extras = io.getLookup().lookup(cls); + if (extras == null) { + throw new IllegalArgumentException("BaseInputOutput " + io + + " does not support " + cls); + } else { + return extras; + } + } + + /** + * Get extension of given type, or return null if it is not present. + * + * @param Type of the extension. + * @param io I/O to get the extension for. + * @param cls Extension class. + * + * @return The extension object of given type, or null if it is not + * supported. + */ + static T find(BaseInputOutput io, Class cls) { + return io.getLookup().lookup(cls); + } +}