--- a/core.output2/manifest.mf
+++ a/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
--- a/core.output2/nbproject/project.xml
+++ a/core.output2/nbproject/project.xml
@@ -111,7 +111,16 @@
This document lists changes made to the Base I/O APIs. @FOOTER@
+ 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:
+
+ The Base Input/Output APIs is a small API module
+ which contains
+ 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
+ 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
+
+ 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
+
* Client usage:
+ *
* Client usage:
+ *
- * Client usage:
+ * Client usage:
+ * Introduction
+
+
+
+ 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);
+ }
+
+ BaseInputOutput
and related interfaces used in
+ driving the Output Window. The normal implementation is
+ org.netbeans.core.output2
.
+ OpenIDE-Module-Requires: org.openide.io.base.BaseIOProvider
+ BaseIOProvider.getDefault()
asks lookup for the first instance
+ of itself. This is normally provided by org.netbeans.core.output2
.
+ 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;
+ }
+}
--- a/openide.io/src/org/openide/windows/FoldHandle.java
+++ a/openide.io/src/org/openide/windows/FoldHandle.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();
--- a/openide.io/src/org/openide/windows/IOColorLines.java
+++ a/openide.io/src/org/openide/windows/IOColorLines.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.
*
* // 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:
*
- *
- * @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;
}
--- a/openide.io/src/org/openide/windows/IOColorPrint.java
+++ a/openide.io/src/org/openide/windows/IOColorPrint.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.
*
- * 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:
*
- *
- * @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;
+ }
}
--- a/openide.io/src/org/openide/windows/IOColors.java
+++ a/openide.io/src/org/openide/windows/IOColors.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.
*
- * // 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:
*
- *
- * @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);
+ }
}
--- a/openide.io/src/org/openide/windows/IOFolding.java
+++ a/openide.io/src/org/openide/windows/IOFolding.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: *
*+ * 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: + *
+ *
* 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: *
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 extends BaseIOProvider> 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 extends EventListener> 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 extends EventListener> 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) {
+ }
+ }
+ }
+ }
+ }
+}
--- a/openide.io/src/org/openide/windows/IOSelect.java
+++ a/openide.io/src/org/openide/windows/IOSelect.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* // 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: *
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;
+}
--- a/openide.io.base/src/org/openide/io/base/BaseOutputEvent.java
+++ a/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();
+ }
+}
--- a/openide.io.base/src/org/openide/io/base/BaseOutputListener.java
+++ a/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);
+}
--- a/openide.io.base/src/org/openide/io/base/BaseOutputTag.java
+++ a/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