This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 245014
Collapse All | Expand All

(-)a/core.output2/nbproject/project.xml (-1 / +10 lines)
Lines 111-117 Link Here
111
                    <build-prerequisite/>
111
                    <build-prerequisite/>
112
                    <compile-dependency/>
112
                    <compile-dependency/>
113
                    <run-dependency>
113
                    <run-dependency>
114
                        <specification-version>1.40</specification-version>
114
                        <specification-version>1.45</specification-version>
115
                    </run-dependency>
116
                </dependency>
117
                <dependency>
118
                    <code-name-base>org.openide.io.base</code-name-base>
119
                    <build-prerequisite/>
120
                    <compile-dependency/>
121
                    <run-dependency>
122
                        <release-version>1</release-version>
123
                        <specification-version>1.0</specification-version>
115
                    </run-dependency>
124
                    </run-dependency>
116
                </dependency>
125
                </dependency>
117
                <dependency>
126
                <dependency>
(-)a/core.output2/src/org/netbeans/core/output2/NbIO.java (-15 / +196 lines)
Lines 53-70 Link Here
53
import java.awt.*;
53
import java.awt.*;
54
import java.io.IOException;
54
import java.io.IOException;
55
import java.io.Reader;
55
import java.io.Reader;
56
import java.util.EnumSet;
56
import org.netbeans.core.output2.options.OutputOptions;
57
import org.netbeans.core.output2.options.OutputOptions;
58
import org.openide.io.base.BaseColor;
59
import org.openide.io.base.BaseIOColorLines;
60
import org.openide.io.base.BaseIOColorPrint;
61
import org.openide.io.base.BaseIOColors;
62
import org.openide.io.base.BaseIOFolding;
63
import org.openide.io.base.BaseIOHyperlink;
64
import org.openide.io.base.BaseIOLinkInfo;
65
import org.openide.io.base.BaseIOPosition;
66
import org.openide.io.base.BaseIOSelect;
67
import org.openide.io.base.BaseIOTab;
68
import org.openide.io.base.BaseInputOutput;
69
import org.openide.io.base.BaseOutputEvent;
70
import org.openide.io.base.BaseOutputListener;
57
import org.openide.util.Exceptions;
71
import org.openide.util.Exceptions;
58
import org.openide.util.Lookup;
72
import org.openide.util.Lookup;
59
import org.openide.util.lookup.Lookups;
73
import org.openide.util.lookup.Lookups;
60
import org.openide.windows.IOColorLines;
74
import org.openide.windows.IOColorLines;
61
import org.openide.windows.IOColorPrint;
75
import org.openide.windows.IOColorPrint;
62
import org.openide.windows.IOColors;
76
import org.openide.windows.IOColors;
77
import org.openide.windows.IOColors.OutputType;
63
import org.openide.windows.IOContainer;
78
import org.openide.windows.IOContainer;
64
import org.openide.windows.IOFolding;
79
import org.openide.windows.IOFolding;
65
import org.openide.windows.IOPosition;
80
import org.openide.windows.IOPosition;
66
import org.openide.windows.IOSelect;
81
import org.openide.windows.IOSelect;
82
import org.openide.windows.IOSelect.AdditionalOperation;
67
import org.openide.windows.IOTab;
83
import org.openide.windows.IOTab;
84
import org.openide.windows.OutputEvent;
68
85
69
/** Implementation of InputOutput.  Implements calls as a set of
86
/** Implementation of InputOutput.  Implements calls as a set of
70
 * "commands" which are passed up to Dispatcher to be run on the event
87
 * "commands" which are passed up to Dispatcher to be run on the event
Lines 72-78 Link Here
72
 *
89
 *
73
 * @author  Tim Boudreau
90
 * @author  Tim Boudreau
74
 */
91
 */
75
class NbIO implements InputOutput, Lookup.Provider {
92
class NbIO implements InputOutput, BaseInputOutput, Lookup.Provider {
76
93
77
    private Boolean focusTaken = null;
94
    private Boolean focusTaken = null;
78
    private volatile boolean closed = false;
95
    private volatile boolean closed = false;
Lines 263-268 Link Here
263
        return actions;
280
        return actions;
264
    }
281
    }
265
    
282
    
283
    @Override
266
    public void reset() {
284
    public void reset() {
267
        if (Controller.LOG) Controller.log (this + ": reset");
285
        if (Controller.LOG) Controller.log (this + ": reset");
268
        closed = false;
286
        closed = false;
Lines 327-333 Link Here
327
            ioColors = new IOColorsImpl();
345
            ioColors = new IOColorsImpl();
328
            lookup = Lookups.fixed(ioTab, ioColors, new IOPositionImpl(),
346
            lookup = Lookups.fixed(ioTab, ioColors, new IOPositionImpl(),
329
                    new IOColorLinesImpl(), new IOColorPrintImpl(),
347
                    new IOColorLinesImpl(), new IOColorPrintImpl(),
330
                    new IOSelectImpl(), new IOFoldingImpl(), options);
348
                    new IOSelectImpl(), new BaseIOSelectImpl(),
349
                    new IOFoldingImpl(), new BaseIOHyperlinkImpl(), options);
331
        }
350
        }
332
        return lookup;
351
        return lookup;
333
    }
352
    }
Lines 485-491 Link Here
485
        return ioColors != null ? ioColors.getColor(type) : AbstractLines.getDefColors()[type.ordinal()];
504
        return ioColors != null ? ioColors.getColor(type) : AbstractLines.getDefColors()[type.ordinal()];
486
    }
505
    }
487
506
488
    private class IOTabImpl extends IOTab {
507
    private class IOTabImpl extends IOTab implements BaseIOTab.Provider {
489
        Icon icon;
508
        Icon icon;
490
        String toolTip;
509
        String toolTip;
491
510
Lines 495-501 Link Here
495
        }
514
        }
496
515
497
        @Override
516
        @Override
498
        protected String getToolTipText() {
517
        public String getToolTipText() {
499
            return toolTip;
518
            return toolTip;
500
        }
519
        }
501
520
Lines 506-521 Link Here
506
        }
525
        }
507
526
508
        @Override
527
        @Override
509
        protected void setToolTipText(String text) {
528
        public void setToolTipText(String text) {
510
            toolTip = text;
529
            toolTip = text;
511
            post(NbIO.this, IOEvent.CMD_SET_TOOLTIP, toolTip);
530
            post(NbIO.this, IOEvent.CMD_SET_TOOLTIP, toolTip);
512
        }
531
        }
513
    }
532
    }
514
533
515
    private class IOPositionImpl extends IOPosition {
534
    private class IOPositionImpl extends IOPosition
535
            implements BaseIOPosition.Provider {
516
536
517
        @Override
537
        @Override
518
        protected Position currentPosition() {
538
        public PositionImpl currentPosition() {
519
            OutWriter out = out();
539
            OutWriter out = out();
520
            int size = 0;
540
            int size = 0;
521
            if (out != null) {
541
            if (out != null) {
Lines 525-531 Link Here
525
        }
545
        }
526
    }
546
    }
527
547
528
    private class PositionImpl implements IOPosition.Position {
548
    private class PositionImpl implements IOPosition.Position,
549
            BaseIOPosition.Position {
529
        private int pos;
550
        private int pos;
530
551
531
        public PositionImpl(int pos) {
552
        public PositionImpl(int pos) {
Lines 537-543 Link Here
537
        }
558
        }
538
    }
559
    }
539
560
540
    private class IOColorLinesImpl extends IOColorLines {
561
    private class IOColorLinesImpl extends IOColorLines implements BaseIOColorLines.Provider {
541
562
542
        @Override
563
        @Override
543
        protected void println(CharSequence text, OutputListener listener, boolean important, Color color) throws IOException {
564
        protected void println(CharSequence text, OutputListener listener, boolean important, Color color) throws IOException {
Lines 546-554 Link Here
546
                out.print(text, listener, important, color, null, OutputKind.OUT, true);
567
                out.print(text, listener, important, color, null, OutputKind.OUT, true);
547
            }
568
            }
548
        }
569
        }
570
571
        @Override
572
        public void println(CharSequence text, boolean important, BaseColor color,
573
                BaseIOLinkInfo... extendedInfo) throws IOException {
574
            OutWriter out = out();
575
            if (out != null) {
576
                OutputListener l = findAndConvertOutputListener(extendedInfo);
577
                out.print(text, l, important, convertToColor(color), null,
578
                        OutputKind.OUT, true);
579
            }
580
        }
549
    }
581
    }
550
582
551
    private class IOColorPrintImpl extends IOColorPrint {
583
    private class IOColorPrintImpl extends IOColorPrint implements BaseIOColorPrint.Provider {
552
584
553
        @Override
585
        @Override
554
        protected void print(CharSequence text, OutputListener listener, boolean important, Color color) throws IOException {
586
        protected void print(CharSequence text, OutputListener listener, boolean important, Color color) throws IOException {
Lines 557-562 Link Here
557
                out.print(text, listener, important, color, null, OutputKind.OUT, false);
589
                out.print(text, listener, important, color, null, OutputKind.OUT, false);
558
            }
590
            }
559
        }
591
        }
592
593
        @Override
594
        public void print(CharSequence text, boolean important, BaseColor color,
595
                BaseIOLinkInfo... extendedInfo) throws IOException {
596
            OutWriter out = out();
597
            if (out != null) {
598
                OutputListener l = findAndConvertOutputListener(extendedInfo);
599
                out.print(text, l, important, convertToColor(color), null,
600
                        OutputKind.OUT, false);
601
            }
602
        }
560
    }
603
    }
561
604
562
    private class IOSelectImpl extends IOSelect {
605
    private class IOSelectImpl extends IOSelect {
Lines 568-574 Link Here
568
	}
611
	}
569
    }
612
    }
570
613
571
    private class IOColorsImpl extends IOColors {
614
    private class BaseIOSelectImpl implements BaseIOSelect.Provider {
615
616
        @Override
617
        public void select(Set<BaseIOSelect.AdditionalOperation> extraOps) {
618
            if (Controller.LOG) {
619
                Controller.log(this + ": IOSelect.select");             //NOI18N
620
            }
621
            NbIO.post(NbIO.this, IOEvent.CMD_FINE_SELECT,
622
                    convertIOSelectOps(extraOps));
623
        }
624
    }
625
626
    private class IOColorsImpl extends IOColors implements BaseIOColors.Provider {
572
        Color[] clrs = new Color[OutputType.values().length];
627
        Color[] clrs = new Color[OutputType.values().length];
573
628
574
        @Override
629
        @Override
Lines 581-592 Link Here
581
            clrs[type.ordinal()] = color;
636
            clrs[type.ordinal()] = color;
582
            post(NbIO.this, IOEvent.CMD_DEF_COLORS, type);
637
            post(NbIO.this, IOEvent.CMD_DEF_COLORS, type);
583
        }
638
        }
639
640
        @Override
641
        public BaseColor getColor(BaseIOColors.OutputType type) {
642
            return convertToBaseColor(getColor(convertOutputType(type)));
643
        };
644
645
        @Override
646
        public void setColor(BaseIOColors.OutputType type, BaseColor color) {
647
            setColor(convertOutputType(type), convertToColor(color));
648
        }
584
    }
649
    }
585
650
586
    private class IOFoldingImpl extends IOFolding {
651
    private class IOFoldingImpl extends IOFolding implements BaseIOFolding.Provider {
587
652
588
        @Override
653
        @Override
589
        protected FoldHandleDefinition startFold(boolean expanded) {
654
        public NbIoFoldHandleDefinition startFold(boolean expanded) {
590
            synchronized (outOrException()) {
655
            synchronized (outOrException()) {
591
                if (currentFold != null) {
656
                if (currentFold != null) {
592
                    throw new IllegalStateException(
657
                    throw new IllegalStateException(
Lines 597-603 Link Here
597
            }
662
            }
598
        }
663
        }
599
664
600
        class NbIoFoldHandleDefinition extends IOFolding.FoldHandleDefinition {
665
        class NbIoFoldHandleDefinition extends IOFolding.FoldHandleDefinition
666
            implements BaseIOFolding.FoldHandleDefinition{
601
667
602
            private final NbIoFoldHandleDefinition parent;
668
            private final NbIoFoldHandleDefinition parent;
603
            private final int start;
669
            private final int start;
Lines 635-641 Link Here
635
            }
701
            }
636
702
637
            @Override
703
            @Override
638
            public FoldHandleDefinition startFold(boolean expanded) {
704
            public NbIoFoldHandleDefinition startFold(boolean expanded) {
639
                synchronized (outOrException()) {
705
                synchronized (outOrException()) {
640
                    if (end != -1) {
706
                    if (end != -1) {
641
                        throw new IllegalStateException(
707
                        throw new IllegalStateException(
Lines 689-694 Link Here
689
        }
755
        }
690
    }
756
    }
691
757
758
    private class BaseIOHyperlinkImpl implements BaseIOHyperlink.Provider {
759
760
        @Override
761
        public boolean isSupported(Class<? extends BaseIOLinkInfo> cls) {
762
            return BaseOutputListener.class.isAssignableFrom(cls);
763
        }
764
765
        @Override
766
        public void println(BaseIOHyperlink.Type type, String s,
767
                boolean important, BaseIOLinkInfo... linkInfo) throws IOException {
768
            OutputWriter writer = BaseIOHyperlink.Type.ERR.equals(type)
769
                    ? getErr() : getOut();
770
            if (writer != null) {
771
                OutputListener l = findAndConvertOutputListener(linkInfo);
772
                writer.println(s, l, important);
773
            }
774
        }
775
    }
776
692
    private int getLastLineNumber() {
777
    private int getLastLineNumber() {
693
        return Math.max(0, out().getLines().getLineCount() - 2);
778
        return Math.max(0, out().getLines().getLineCount() - 2);
694
    }
779
    }
Lines 707-710 Link Here
707
    OutputOptions getOptions() {
792
    OutputOptions getOptions() {
708
        return this.options;
793
        return this.options;
709
    }
794
    }
795
796
    /**
797
     * Find the first {@link BaseOutputListener} in the list of hyperlink
798
     * extension objects, convert it to {@link OutputListener} and return it.
799
     */
800
    private OutputListener findAndConvertOutputListener(BaseIOLinkInfo... exts) {
801
        for (Object o : exts) {
802
            if (o instanceof BaseOutputListener) {
803
                return convertToOutputListener((BaseOutputListener) o);
804
            }
805
        }
806
        return null;
807
    }
808
809
    private OutputListener convertToOutputListener(final BaseOutputListener l) {
810
        return new OutputListener() {
811
812
            @Override
813
            public void outputLineSelected(OutputEvent ev) {
814
            }
815
816
            @Override
817
            public void outputLineAction(OutputEvent ev) {
818
                l.outputLineAction(convertToOutputEventBase(ev));
819
            }
820
821
            @Override
822
            public void outputLineCleared(OutputEvent ev) {
823
            }
824
        };
825
    }
826
827
    private BaseOutputEvent convertToOutputEventBase(final OutputEvent e) {
828
        InputOutput origIO = e.getInputOutput();
829
        BaseInputOutput src = origIO instanceof BaseInputOutput
830
                ? (BaseInputOutput) origIO : this;
831
        return new BaseOutputEvent(src) {
832
            @Override
833
            public String getLine() {
834
                return e.getLine();
835
            }
836
        };
837
    }
838
839
    private Set<AdditionalOperation> convertIOSelectOps(
840
            Set<BaseIOSelect.AdditionalOperation> ops) {
841
        Set<AdditionalOperation> s = EnumSet.noneOf(AdditionalOperation.class);
842
        for (BaseIOSelect.AdditionalOperation bo : ops) {
843
            switch (bo) {
844
                case OPEN:
845
                    s.add(AdditionalOperation.OPEN);
846
                    break;
847
                case REQUEST_ACTIVE:
848
                    s.add(AdditionalOperation.REQUEST_ACTIVE);
849
                    break;
850
                case REQUEST_VISIBLE:
851
                    s.add(AdditionalOperation.REQUEST_VISIBLE);
852
                    break;
853
            }
854
        }
855
        return s;
856
    }
857
858
    private OutputType convertOutputType(BaseIOColors.OutputType baseType) {
859
        switch (baseType) {
860
            case INPUT:
861
                return OutputType.INPUT;
862
            case OUTPUT:
863
                return OutputType.OUTPUT;
864
            case ERROR:
865
                return OutputType.ERROR;
866
            case HYPERLINK:
867
                return OutputType.HYPERLINK;
868
            case HYPERLINK_IMPORTANT:
869
                return OutputType.HYPERLINK_IMPORTANT;
870
            case LOG_DEBUG:
871
                return OutputType.LOG_DEBUG;
872
            case LOG_SUCCESS:
873
                return OutputType.LOG_SUCCESS;
874
            case LOG_WARNING:
875
                return OutputType.LOG_WARNING;
876
            case LOG_FAILURE:
877
                return OutputType.LOG_FAILURE;
878
            default:
879
                throw new IllegalArgumentException(
880
                        "Unknown output type " + baseType);             //NOI18N
881
        }
882
    }
883
884
    private Color convertToColor(BaseColor baseColor) {
885
        return new Color(baseColor.getRGB(), true);
886
    }
887
888
    private BaseColor convertToBaseColor(Color color) {
889
        return new BaseColor(color.getRGB(), true);
890
    }
710
}
891
}
(-)a/core.output2/src/org/netbeans/core/output2/NbIOProvider.java (-51 / +17 lines)
Lines 45-51 Link Here
45
package org.netbeans.core.output2;
45
package org.netbeans.core.output2;
46
46
47
import java.io.IOException;
47
import java.io.IOException;
48
import java.util.WeakHashMap;
49
import javax.swing.Action;
48
import javax.swing.Action;
50
import org.openide.util.Exceptions;
49
import org.openide.util.Exceptions;
51
import org.openide.util.NbBundle;
50
import org.openide.util.NbBundle;
Lines 55-73 Link Here
55
import org.openide.windows.OutputWriter;
54
import org.openide.windows.OutputWriter;
56
55
57
/**
56
/**
58
 * Supplies Output Window implementation through Lookup.
57
 * Supplies Output Window implementation through Lookup. Provider of I/O
58
 * instances for the org.openide.io (package org.openide.windows) API.
59
 *
59
 * @author Jesse Glick, Tim Boudreau
60
 * @author Jesse Glick, Tim Boudreau
60
 */
61
 */
61
@org.openide.util.lookup.ServiceProvider(service=org.openide.windows.IOProvider.class, position=100)
62
@org.openide.util.lookup.ServiceProvider(service=org.openide.windows.IOProvider.class, position=100)
62
public final class NbIOProvider extends IOProvider {
63
public final class NbIOProvider extends IOProvider {
63
    private static final WeakHashMap<IOContainer, PairMap> containerPairMaps =
64
            new WeakHashMap<IOContainer, PairMap>();
65
64
66
    private static final String STDOUT = NbBundle.getMessage(NbIOProvider.class,
65
    private static final String STDOUT = NbBundle.getMessage(NbIOProvider.class,
67
        "LBL_STDOUT"); //NOI18N
66
        "LBL_STDOUT"); //NOI18N
68
67
69
    private static final String NAME = "output2"; // NOI18N
68
    @Override
70
    
69
    public String getName() {
70
        return SharedProvider.getInstance().getName();
71
    }
72
73
    @Override
71
    public OutputWriter getStdOut() {
74
    public OutputWriter getStdOut() {
72
        if (Controller.LOG) {
75
        if (Controller.LOG) {
73
            Controller.log("NbIOProvider.getStdOut");
76
            Controller.log("NbIOProvider.getStdOut");
Lines 93-98 Link Here
93
    }
96
    }
94
    
97
    
95
    
98
    
99
    @Override
96
    public InputOutput getIO(String name, boolean newIO) {
100
    public InputOutput getIO(String name, boolean newIO) {
97
        return getIO (name, newIO, new Action[0], null);
101
        return getIO (name, newIO, new Action[0], null);
98
    }
102
    }
Lines 108-160 Link Here
108
    }
112
    }
109
113
110
    @Override
114
    @Override
111
    public String getName() {
115
    public InputOutput getIO(String name, boolean newIO, Action[] actions,
112
        return NAME;
116
            IOContainer ioContainer) {
117
118
        return SharedProvider.getInstance().getIO(name, newIO, actions,
119
                ioContainer);
113
    }
120
    }
114
121
115
    @Override
122
    static void dispose(NbIO io) {
116
    public InputOutput getIO(String name, boolean newIO,
123
        SharedProvider.dispose(io);
117
            Action[] toolbarActions, IOContainer ioContainer) {
118
        if (Controller.LOG) {
119
            Controller.log("GETIO: " + name + " new:" + newIO);
120
        }
121
        IOContainer realIoContainer = ioContainer == null
122
                ? IOContainer.getDefault() : ioContainer;
123
        NbIO result;
124
        synchronized (containerPairMaps) {
125
            PairMap namesToIos = containerPairMaps.get(realIoContainer);
126
            result = namesToIos != null ? namesToIos.get(name) : null;
127
        }
128
        if (result == null || newIO) {
129
            result = new NbIO(name, toolbarActions, realIoContainer);
130
            synchronized (containerPairMaps) {
131
                PairMap namesToIos = containerPairMaps.get(realIoContainer);
132
                if (namesToIos == null) {
133
                    namesToIos = new PairMap();
134
                    containerPairMaps.put(realIoContainer, namesToIos);
135
                }
136
                namesToIos.add(name, result);
137
            }
138
            NbIO.post(new IOEvent(result, IOEvent.CMD_CREATE, newIO));
139
        }
140
        return result;
141
    }
142
    
143
    
144
    static void dispose (NbIO io) {
145
        IOContainer ioContainer = io.getIOContainer();
146
        if (ioContainer == null) {
147
            ioContainer = IOContainer.getDefault();
148
        }
149
        synchronized (containerPairMaps) {
150
            PairMap namesToIos = containerPairMaps.get(ioContainer);
151
            if (namesToIos != null) {
152
                namesToIos.remove(io);
153
                if (namesToIos.isEmpty()) {
154
                    containerPairMaps.remove(ioContainer);
155
                }
156
            }
157
        }
158
    }
124
    }
159
}
125
}
160
126
(-)a/core.output2/src/org/netbeans/core/output2/NbIOProviderBase.java (+103 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.core.output2;
43
44
import java.util.EventListener;
45
import java.util.logging.Level;
46
import java.util.logging.Logger;
47
import javax.swing.Action;
48
import org.openide.io.base.BaseIOProvider;
49
import org.openide.io.base.BaseInputOutput;
50
import org.openide.util.Lookup;
51
import org.openide.util.lookup.ServiceProvider;
52
53
/**
54
 * Provider of I/O instances for the org.openide.io.base API.
55
 *
56
 * @author jhavlin
57
 */
58
@ServiceProvider(service = BaseIOProvider.class, position = 100)
59
public class NbIOProviderBase extends BaseIOProvider {
60
61
    private static final Logger LOG = Logger.getLogger(
62
            NbIOProviderBase.class.getName());
63
64
    @Override
65
    public String getName() {
66
        return SharedProvider.getInstance().getName();
67
    }
68
69
    @Override
70
    public BaseInputOutput getIO(String name, boolean newIO,
71
            Lookup context, EventListener... actions) {
72
73
        Action[] actionArray = convertActions(actions);
74
        return SharedProvider.getInstance().getIO(name, newIO, actionArray,
75
                null);
76
    }
77
78
    private Action[] convertActions(EventListener[] actions) {
79
        Action[] actionArray = new Action[actions.length];
80
        for (int i = 0; i < actions.length; i++) {
81
            if (actions[i] instanceof Action) {
82
                actionArray[i] = (Action) actions[i];
83
            } else if (actions[i] == null) {
84
                LOG.log(Level.WARNING, "Null action",                   //NOI18N
85
                        new IllegalArgumentException());
86
                return new Action[0];
87
            } else {
88
                LOG.log(Level.WARNING, "Only actions of type javax."    //NOI18N
89
                        + "swing.Action are supported, but object of "  //NOI18N
90
                        + "type " + actions[i].getClass() + " found",   //NOI18N
91
                        new IllegalArgumentException());
92
                return new Action[0];
93
            }
94
        }
95
        return actionArray;
96
    }
97
98
    @Override
99
    public boolean isActionTypeSupported(
100
            Class<? extends EventListener> cls) {
101
        return Action.class.isAssignableFrom(cls);
102
    }
103
}
(-)a/core.output2/src/org/netbeans/core/output2/SharedProvider.java (+119 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.core.output2;
43
44
import java.util.WeakHashMap;
45
import javax.swing.Action;
46
import org.openide.windows.IOContainer;
47
48
/**
49
 * Shared provider for both the original (org.openide.io/org.openide.windows)
50
 * and the base (org.openide.io.base) APIs.
51
 *
52
 * @author jhavlin
53
 */
54
public class SharedProvider {
55
56
    private static final WeakHashMap<IOContainer, PairMap> containerPairMaps
57
            = new WeakHashMap<IOContainer, PairMap>();
58
    private static final String NAME = "output2"; // NOI18N
59
60
    private static class SingletonHolder {
61
62
        static SharedProvider INSTANCE = new SharedProvider();
63
    }
64
65
    public static SharedProvider getInstance() {
66
        return SingletonHolder.INSTANCE;
67
    }
68
69
    private SharedProvider() {
70
        System.out.println("x");
71
    }
72
73
    public String getName() {
74
        return NAME;
75
    }
76
77
    NbIO getIO(String name, boolean newIO,
78
            Action[] toolbarActions, IOContainer ioContainer) {
79
        if (Controller.LOG) {
80
            Controller.log("GETIO: " + name + " new:" + newIO);
81
        }
82
        IOContainer realIoContainer = ioContainer == null
83
                ? IOContainer.getDefault() : ioContainer;
84
        NbIO result;
85
        synchronized (containerPairMaps) {
86
            PairMap namesToIos = containerPairMaps.get(realIoContainer);
87
            result = namesToIos != null ? namesToIos.get(name) : null;
88
        }
89
        if (result == null || newIO) {
90
            result = new NbIO(name, toolbarActions, realIoContainer);
91
            synchronized (containerPairMaps) {
92
                PairMap namesToIos = containerPairMaps.get(realIoContainer);
93
                if (namesToIos == null) {
94
                    namesToIos = new PairMap();
95
                    containerPairMaps.put(realIoContainer, namesToIos);
96
                }
97
                namesToIos.add(name, result);
98
            }
99
            NbIO.post(new IOEvent(result, IOEvent.CMD_CREATE, newIO));
100
        }
101
        return result;
102
    }
103
104
    static void dispose(NbIO io) {
105
        IOContainer ioContainer = io.getIOContainer();
106
        if (ioContainer == null) {
107
            ioContainer = IOContainer.getDefault();
108
        }
109
        synchronized (containerPairMaps) {
110
            PairMap namesToIos = containerPairMaps.get(ioContainer);
111
            if (namesToIos != null) {
112
                namesToIos.remove(io);
113
                if (namesToIos.isEmpty()) {
114
                    containerPairMaps.remove(ioContainer);
115
                }
116
            }
117
        }
118
    }
119
}
(-)a/nbbuild/build.properties (+1 lines)
Lines 177-182 Link Here
177
    core.netigso,\
177
    core.netigso,\
178
    o.n.swing.outline,\
178
    o.n.swing.outline,\
179
    o.n.swing.tabcontrol,\
179
    o.n.swing.tabcontrol,\
180
    openide.io.base,\
180
    editor.indent,\
181
    editor.indent,\
181
    editor.bracesmatching,\
182
    editor.bracesmatching,\
182
    j2ee.metadata,\
183
    j2ee.metadata,\
(-)a/nbbuild/cluster.properties (+1 lines)
Lines 251-256 Link Here
251
        openide.filesystems.compat8,\
251
        openide.filesystems.compat8,\
252
        openide.filesystems.nb,\
252
        openide.filesystems.nb,\
253
        openide.io,\
253
        openide.io,\
254
	openide.io.base,\
254
        openide.loaders,\
255
        openide.loaders,\
255
        openide.nodes,\
256
        openide.nodes,\
256
        openide.options,\
257
        openide.options,\
(-)a/openide.io.base/apichanges.xml (+139 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!--
3
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
5
Copyright 2014 Oracle and/or its affiliates. All rights reserved.
6
7
Oracle and Java are registered trademarks of Oracle and/or its affiliates.
8
Other names may be trademarks of their respective owners.
9
10
The contents of this file are subject to the terms of either the GNU
11
General Public License Version 2 only ("GPL") or the Common
12
Development and Distribution License("CDDL") (collectively, the
13
"License"). You may not use this file except in compliance with the
14
License. You can obtain a copy of the License at
15
http://www.netbeans.org/cddl-gplv2.html
16
or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
17
specific language governing permissions and limitations under the
18
License.  When distributing the software, include this License Header
19
Notice in each file and include the License file at
20
nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
21
particular file as subject to the "Classpath" exception as provided
22
by Oracle in the GPL Version 2 section of the License file that
23
accompanied this code. If applicable, add the following below the
24
License Header, with the fields enclosed by brackets [] replaced by
25
your own identifying information:
26
"Portions Copyrighted [year] [name of copyright owner]"
27
28
If you wish your version of this file to be governed by only the CDDL
29
or only the GPL Version 2, indicate your decision by adding
30
"[Contributor] elects to include this software in this distribution
31
under the [CDDL or GPL Version 2] license." If you do not indicate a
32
single choice of license, a recipient has the option to distribute
33
your version of this file under either the CDDL, the GPL Version 2 or
34
to extend the choice of license to its licensees as provided above.
35
However, if you add GPL Version 2 code and therefore, elected the GPL
36
Version 2 license, then the option applies only if the new code is
37
made subject to such option by the copyright holder.
38
39
Contributor(s):
40
41
Portions Copyrighted 2014 Sun Microsystems, Inc.
42
-->
43
44
<?xml-stylesheet type="text/xml" href="../nbbuild/javadoctools/apichanges.xsl"?>
45
<!DOCTYPE apichanges PUBLIC "-//NetBeans//DTD API changes list 1.0//EN" "../nbbuild/javadoctools/apichanges.dtd">
46
47
<!--
48
49
INFO FOR PEOPLE ADDING CHANGES:
50
51
Check the DTD (apichanges.dtd) for details on the syntax. You do not
52
need to regenerate the HTML, as this is part of Javadoc generation; just
53
change the XML. Rough syntax of a change (several parts optional):
54
55
<change>
56
    <api name="compiler"/>
57
    <summary>Some brief description here, can use <b>XHTML</b></summary>
58
    <version major="1" minor="99"/>
59
    <date day="13" month="6" year="2001"/>
60
    <author login="jrhacker"/>
61
    <compatibility addition="yes"/>
62
    <description>
63
        The main description of the change here.
64
        Again can use full <b>XHTML</b> as needed.
65
    </description>
66
    <class package="org.openide.compiler" name="DoWhatIWantCompiler"/>
67
    <issue number="14309"/>
68
</change>
69
70
Also permitted elements: <package>, <branch>. <version> is API spec
71
version, recommended for all new changes. <compatibility> should say
72
if things were added/modified/deprecated/etc. and give all information
73
related to upgrading old code. List affected top-level classes and
74
link to issue numbers if applicable. See the DTD for more details.
75
76
Changes need not be in any particular order, they are sorted in various
77
ways by the stylesheet anyway.
78
79
Dates are assumed to mean "on the trunk". If you *also* make the same
80
change on a stabilization branch, use the <branch> tag to indicate this
81
and explain why the change was made on a branch in the <description>.
82
83
Please only change this file on the trunk! Rather: you can change it
84
on branches if you want, but these changes will be ignored; only the
85
trunk version of this file is important.
86
87
Deprecations do not count as incompatible, assuming that code using the
88
deprecated calls continues to see their documented behavior. But do
89
specify deprecation="yes" in <compatibility>.
90
91
This file is not a replacement for Javadoc: it is intended to list changes,
92
not describe the complete current behavior, for which ordinary documentation
93
is the proper place.
94
95
-->
96
97
<apichanges>
98
99
    <!-- First, a list of API names you may use: -->
100
    <apidefs>
101
        <apidef name="io.base">Base I/O APIs</apidef>
102
        <!-- etc. -->
103
    </apidefs>
104
105
    <!-- ACTUAL CHANGES BEGIN HERE: -->
106
107
    <changes>
108
109
        <!-- Start here... -->
110
111
    </changes>
112
113
    <!-- Now the surrounding HTML text and document structure: -->
114
115
    <htmlcontents>
116
<!-- Generated from apichanges.xml -->
117
    <head>
118
      <title>Change History for the Base I/O APIs</title>
119
      <link rel="stylesheet" href="prose.css" type="text/css"/>
120
    </head>
121
    <body>
122
123
<p class="overviewlink"><a href="@TOP@/overview-summary.html">Overview</a></p>
124
125
<h1>Introduction</h1>
126
127
<p>This document lists changes made to the <a href="@TOP@/overview-summary.html">Base I/O APIs</a>.</p>
128
129
<!-- The actual lists of changes, as summaries and details: -->
130
      <hr/>
131
      <standard-changelists module-code-name="org.openide.io.base/1"/>
132
133
      <hr/><p>@FOOTER@</p>
134
135
    </body>
136
  </htmlcontents>
137
138
</apichanges>
139
(-)a/openide.io.base/arch.xml (+1106 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!DOCTYPE api-answers PUBLIC "-//NetBeans//DTD Arch Answers//EN" "../nbbuild/antsrc/org/netbeans/nbbuild/Arch.dtd" [
3
  <!ENTITY api-questions SYSTEM "../nbbuild/antsrc/org/netbeans/nbbuild/Arch-api-questions.xml">
4
]>
5
6
<api-answers
7
  question-version="1.29"
8
  author="yourname@netbeans.org"
9
>
10
11
  &api-questions;
12
13
14
<!--
15
        <question id="arch-overall" when="init">
16
            Describe the overall architecture.
17
            <hint>
18
            What will be API for
19
            <a href="http://wiki.netbeans.org/API_Design#Separate_API_for_clients_from_support_API">
20
                clients and what support API</a>?
21
            What parts will be pluggable?
22
            How will plug-ins be registered? Please use <code>&lt;api type="export"/&gt;</code>
23
            to describe your general APIs and specify their
24
            <a href="http://wiki.netbeans.org/API_Stability#Private">
25
            stability categories</a>.
26
            If possible please provide simple diagrams.
27
            </hint>
28
        </question>
29
-->
30
 <answer id="arch-overall">
31
      <api
32
        name="BaseInputOutputAPI"
33
        group="java"
34
        type="export"
35
        category="devel"
36
        url="@org-openide-io-base@/org/openide/io/base/package-summary.html"
37
    >
38
        <p>
39
            Just a base API/SPI for defining the output window.
40
        </p>
41
    </api>
42
 </answer>
43
44
45
46
<!--
47
        <question id="arch-quality" when="init">
48
            How will the <a href="http://www.netbeans.org/community/guidelines/q-evangelism.html">quality</a>
49
            of your code be tested and
50
            how are future regressions going to be prevented?
51
            <hint>
52
            What kind of testing do
53
            you want to use? How much functionality, in which areas,
54
            should be covered by the tests? How you find out that your
55
            project was successful?
56
            </hint>
57
        </question>
58
-->
59
 <answer id="arch-quality">
60
  <p>
61
   Too little code to test.
62
  </p>
63
 </answer>
64
65
66
67
<!--
68
        <question id="arch-time" when="init">
69
            What are the time estimates of the work?
70
            <hint>
71
            Please express your estimates of how long the design, implementation,
72
            stabilization are likely to last. How many people will be needed to
73
            implement this and what is the expected milestone by which the work should be
74
            ready?
75
            </hint>
76
        </question>
77
-->
78
 <answer id="arch-time">
79
  <p>
80
   Done.
81
  </p>
82
 </answer>
83
84
85
86
<!--
87
        <question id="arch-usecases" when="init">
88
            <hint>
89
                Content of this answer will be displayed as part of page at
90
                http://www.netbeans.org/download/dev/javadoc/usecases.html
91
                You can use tags &lt;usecase name="name&gt; regular html description &lt;/usecase&gt;
92
                and if you want to use an URL you can prefix if with @TOP@ to begin
93
                at the root of your javadoc
94
            </hint>
95
96
            Describe the main <a href="http://wiki.netbeans.org/API_Design#The_Importance_of_Being_Use_Case_Oriented">
97
            use cases</a> of the new API. Who will use it under
98
            what circumstances? What kind of code would typically need to be written
99
            to use the module?
100
        </question>
101
-->
102
 <answer id="arch-usecases">
103
    <p>There is an SPI but additional implementations are not expected. The API is most important.</p>
104
    <p>
105
     Simple usage example:
106
    </p>
107
  <pre>
108
  <span class="type">BaseInputOutput</span> <span class="variable-name">io</span> = BaseIOProvider.getDefault().getIO(<span class="string">"My Window"</span>, true);
109
  <span class="type">PrintWriter</span> <span class="variable-name">w</span> = io.getOut();
110
  w.println(<span class="string">"Line of plain text."</span>);
111
  <span class="type">BaseOutputListener</span> <span class="variable-name">listener</span> = <span class="keyword">new</span> <span class="type">BaseOutputListener</span>() {
112
      <span class="keyword">public</span> <span class="type">void</span> <span class="function-name">outputLineAction</span>(<span class="type">BaseOutputEvent</span> <span class="variable-name">ev</span>) {
113
          StatusDisplayer.getDefault().setStatusText(<span class="string">"Hyperlink clicked!"</span>);
114
      }
115
  };
116
  if (BaseIOHyperlink.isSupported(io, <span class="type">BaseOutputListener</span>.class)) {
117
    BaseIOHyperlink.println(io, Type.OUT, <span class="string">"Line of hyperlinked text."</span>, true, listener);
118
  }
119
  </pre>
120
 </answer>
121
122
123
124
<!--
125
        <question id="arch-what" when="init">
126
            What is this project good for?
127
            <hint>
128
            Please provide here a few lines describing the project,
129
            what problem it should solve, provide links to documentation,
130
            specifications, etc.
131
            </hint>
132
        </question>
133
-->
134
 <answer id="arch-what">
135
  <p>
136
   The Base Input/Output APIs is a small API module
137
   which contains <code>BaseInputOutput</code> and related interfaces used in
138
   driving the Output Window. The normal implementation is
139
   <code>org.netbeans.core.output2</code>.
140
  </p>
141
  <p>
142
   The API was extracted from module openide.io, which depends on some
143
   GUI-related classes. This module has no such dependencies.
144
  </p>
145
 </answer>
146
147
148
149
<!--
150
        <question id="arch-where" when="impl">
151
            Where one can find sources for your module?
152
            <hint>
153
                Please provide link to the Hg web client at
154
                http://hg.netbeans.org/
155
                or just use tag defaultanswer generate='here'
156
            </hint>
157
        </question>
158
-->
159
 <answer id="arch-where">
160
  <defaultanswer generate='here' />
161
 </answer>
162
163
164
165
<!--
166
        <question id="compat-deprecation" when="init">
167
            How the introduction of your project influences functionality
168
            provided by previous version of the product?
169
            <hint>
170
            If you are planning to deprecate/remove/change any existing APIs,
171
            list them here accompanied with the reason explaining why you
172
            are doing so.
173
            </hint>
174
        </question>
175
-->
176
 <answer id="compat-deprecation">
177
  <p>
178
   This module is an alternative for org.openide.io, it has similar goals, but
179
   less dependencies.
180
  </p>
181
 </answer>
182
183
184
185
<!--
186
        <question id="compat-i18n" when="impl">
187
            Is your module correctly internationalized?
188
            <hint>
189
            Correct internationalization means that it obeys instructions
190
            at <a href="http://www.netbeans.org/download/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/i18n-branding.html">
191
            NetBeans I18N pages</a>.
192
            </hint>
193
        </question>
194
-->
195
 <answer id="compat-i18n">
196
  <p>
197
   Yes.
198
  </p>
199
 </answer>
200
201
202
203
<!--
204
        <question id="compat-standards" when="init">
205
            Does the module implement or define any standards? Is the
206
            implementation exact or does it deviate somehow?
207
        </question>
208
-->
209
 <answer id="compat-standards">
210
  <p>
211
   The module defines an API.
212
  </p>
213
 </answer>
214
215
216
217
<!--
218
        <question id="compat-version" when="impl">
219
            Can your module coexist with earlier and future
220
            versions of itself? Can you correctly read all old settings? Will future
221
            versions be able to read your current settings? Can you read
222
            or politely ignore settings stored by a future version?
223
224
            <hint>
225
            Very helpful for reading settings is to store version number
226
            there, so future versions can decide whether how to read/convert
227
            the settings and older versions can ignore the new ones.
228
            </hint>
229
        </question>
230
-->
231
 <answer id="compat-version">
232
  <p>
233
   N/A
234
  </p>
235
 </answer>
236
237
238
239
<!--
240
        <question id="dep-jre" when="final">
241
            Which version of JRE do you need (1.2, 1.3, 1.4, etc.)?
242
            <hint>
243
            It is expected that if your module runs on 1.x that it will run
244
            on 1.x+1 if no, state that please. Also describe here cases where
245
            you run different code on different versions of JRE and why.
246
            </hint>
247
        </question>
248
-->
249
 <answer id="dep-jre">
250
  <p>
251
   1.7
252
  </p>
253
 </answer>
254
255
256
257
<!--
258
        <question id="dep-jrejdk" when="final">
259
            Do you require the JDK or is the JRE enough?
260
        </question>
261
-->
262
 <answer id="dep-jrejdk">
263
  <p>
264
   JRE
265
  </p>
266
 </answer>
267
268
269
270
<!--
271
        <question id="dep-nb" when="init">
272
            What other NetBeans projects and modules does this one depend on?
273
            <hint>
274
            Depending on other NetBeans projects influnces the ability of
275
            users of your work to customize their own branded version of
276
            NetBeans by enabling and disabling some modules. Too
277
            much dependencies restrict this kind of customization. If that
278
            is your case, then you may want to split your functionality into
279
            pieces of autoload, eager and regular modules which can be
280
            enabled independently. Usually the answer to this question
281
            is generated from your <code>project.xml</code> file, but
282
            if it is not guessed correctly, you can suppress it by
283
            specifying &lt;defaultanswer generate="none"/&gt; and
284
            write here your own. Please describe such projects as imported APIs using
285
            the <code>&lt;api name="identification" type="import or export" category="stable" url="where is the description" /&gt;</code>.
286
            By doing this information gets listed in the summary page of your
287
            javadoc.
288
            </hint>
289
        </question>
290
-->
291
 <answer id="dep-nb">
292
  <defaultanswer generate='here' />
293
 </answer>
294
295
296
297
<!--
298
        <question id="dep-non-nb" when="init">
299
            What other projects outside NetBeans does this one depend on?
300
301
            <hint>
302
            Depending on 3rd party libraries is always problematic,
303
            especially if they are not open source, as that complicates
304
            the licensing scheme of NetBeans. Please enumerate your
305
            external dependencies here, so it is correctly understood since
306
            the begining what are the legal implications of your project.
307
            Also please note that
308
            some non-NetBeans projects are packaged as NetBeans modules
309
            (see <a href="http://libs.netbeans.org/">libraries</a>) and
310
            it is preferred to use this approach when more modules may
311
            depend and share such third-party libraries.
312
            </hint>
313
        </question>
314
-->
315
 <answer id="dep-non-nb">
316
  <p>
317
   None.
318
  </p>
319
 </answer>
320
321
322
323
<!--
324
        <question id="dep-platform" when="init">
325
            On which platforms does your module run? Does it run in the same
326
            way on each?
327
            <hint>
328
            If you plan any dependency on OS or any usage of native code,
329
            please describe why you are doing so and describe how you envision
330
            to enforce the portability of your code.
331
            Please note that there is a support for <a href="http://www.netbeans.org/download/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/api.html#how-os-specific">OS conditionally
332
            enabled modules</a> which together with autoload/eager modules
333
            can allow you to enable to provide the best OS aware support
334
            on certain OSes while providing compatibility bridge on the not
335
            supported ones.
336
            Also please list the supported
337
            OSes/HW platforms and mentioned the lovest version of JDK required
338
            for your project to run on. Also state whether JRE is enough or
339
            you really need JDK.
340
            </hint>
341
        </question>
342
-->
343
 <answer id="dep-platform">
344
  <p>
345
   Any
346
  </p>
347
 </answer>
348
349
350
351
<!--
352
        <question id="deploy-dependencies" when="final">
353
            What do other modules need to do to declare a dependency on this one,
354
            in addition to or instead of the normal module dependency declaration
355
            (e.g. tokens to require)?
356
            <hint>
357
                Provide a sample of the actual lines you would add to a module manifest
358
                to declare a dependency, for example OpenIDE-Module-Requires: some.token.
359
                If other modules should not depend on this module, or should just use a
360
                simple regular module dependency, you can just answer "nothing". If you
361
                intentionally expose a semistable API to clients using implementation
362
                dependencies, you should mention that here (but there is no need to give
363
                an example of usage).
364
            </hint>
365
        </question>
366
-->
367
 <answer id="deploy-dependencies">
368
  <p>
369
   You will very likely also want to declare
370
  </p>
371
  <pre>OpenIDE-Module-Requires: org.openide.io.base.BaseIOProvider</pre>
372
  <p>to ensure that an Output Window implementation is in fact enabled.</p>
373
 </answer>
374
375
376
377
<!--
378
        <question id="deploy-jar" when="impl">
379
            Do you deploy just module JAR file(s) or other files as well?
380
            <hint>
381
            Usually a module consist of one JAR file (perhaps with Class-Path
382
            extensions) and also a configuration file that enables it. If you
383
            have any other files, use
384
            &lt;api group="java.io.File" name="yourname" type="export" category="friend"&gt;...&lt;/api&gt;
385
            to define the location, name and stability of your files (of course
386
            changing "yourname" and "friend" to suit your needs).
387
388
            If it uses more than one JAR, describe where they are located, how
389
            they refer to each other.
390
            If it consist of module JAR(s) and other files, please describe
391
            what is their purpose, why other files are necessary. Please
392
            make sure that installation/uninstallation leaves the system
393
            in state as it was before installation.
394
            </hint>
395
        </question>
396
-->
397
 <answer id="deploy-jar">
398
  <p>
399
   Just the module JAR.
400
  </p>
401
 </answer>
402
403
404
405
<!--
406
        <question id="deploy-nbm" when="impl">
407
            Can you deploy an NBM via the Update Center?
408
            <hint>
409
            If not why?
410
            </hint>
411
        </question>
412
-->
413
 <answer id="deploy-nbm">
414
  <p>
415
   Yes
416
  </p>
417
 </answer>
418
419
420
421
<!--
422
        <question id="deploy-packages" when="init">
423
            Are packages of your module made inaccessible by not declaring them
424
            public?
425
426
            <hint>
427
            By default NetBeans build harness treats all packages are private.
428
            If you export some of them - either as public or friend packages,
429
            you should have a reason. If the reason is described elsewhere
430
            in this document, you can ignore this question.
431
            </hint>
432
        </question>
433
-->
434
 <answer id="deploy-packages">
435
  <p>
436
   No; only API classes are public.
437
  </p>
438
 </answer>
439
440
441
442
<!--
443
        <question id="deploy-shared" when="final">
444
            Do you need to be installed in the shared location only, or in the user directory only,
445
            or can your module be installed anywhere?
446
            <hint>
447
            Installation location shall not matter, if it does explain why.
448
            Consider also whether <code>InstalledFileLocator</code> can help.
449
            </hint>
450
        </question>
451
-->
452
 <answer id="deploy-shared">
453
  <p>
454
   Anywhere
455
  </p>
456
 </answer>
457
458
459
460
<!--
461
        <question id="exec-ant-tasks" when="impl">
462
            Do you define or register any ant tasks that other can use?
463
464
            <hint>
465
            If you provide an ant task that users can use, you need to be very
466
            careful about its syntax and behaviour, as it most likely forms an
467
	          API for end users and as there is a lot of end users, their reaction
468
            when such API gets broken can be pretty strong.
469
            </hint>
470
        </question>
471
-->
472
 <answer id="exec-ant-tasks">
473
  <p>
474
   No
475
  </p>
476
 </answer>
477
478
479
480
<!--
481
        <question id="exec-classloader" when="impl">
482
            Does your code create its own class loader(s)?
483
            <hint>
484
            A bit unusual. Please explain why and what for.
485
            </hint>
486
        </question>
487
-->
488
 <answer id="exec-classloader">
489
  <p>
490
   No
491
  </p>
492
 </answer>
493
494
495
496
<!--
497
        <question id="exec-component" when="impl">
498
            Is execution of your code influenced by any (string) property
499
            of any of your components?
500
501
            <hint>
502
            Often <code>JComponent.getClientProperty</code>, <code>Action.getValue</code>
503
            or <code>PropertyDescriptor.getValue</code>, etc. are used to influence
504
            a behavior of some code. This of course forms an interface that should
505
            be documented. Also if one depends on some interface that an object
506
            implements (<code>component instanceof Runnable</code>) that forms an
507
            API as well.
508
            </hint>
509
        </question>
510
-->
511
 <answer id="exec-component">
512
  <p>
513
   No
514
  </p>
515
 </answer>
516
517
518
519
<!--
520
        <question id="exec-introspection" when="impl">
521
            Does your module use any kind of runtime type information (<code>instanceof</code>,
522
            work with <code>java.lang.Class</code>, etc.)?
523
            <hint>
524
            Check for cases when you have an object of type A and you also
525
            expect it to (possibly) be of type B and do some special action. That
526
            should be documented. The same applies on operations in meta-level
527
            (Class.isInstance(...), Class.isAssignableFrom(...), etc.).
528
            </hint>
529
        </question>
530
-->
531
 <answer id="exec-introspection">
532
  <p>
533
   No
534
  </p>
535
 </answer>
536
537
538
539
<!--
540
        <question id="exec-privateaccess" when="final">
541
            Are you aware of any other parts of the system calling some of
542
            your methods by reflection?
543
            <hint>
544
            If so, describe the "contract" as an API. Likely private or friend one, but
545
            still API and consider rewrite of it.
546
            </hint>
547
        </question>
548
-->
549
 <answer id="exec-privateaccess">
550
  <p>
551
   No
552
  </p>
553
 </answer>
554
555
556
557
<!--
558
        <question id="exec-process" when="impl">
559
            Do you execute an external process from your module? How do you ensure
560
            that the result is the same on different platforms? Do you parse output?
561
            Do you depend on result code?
562
            <hint>
563
            If you feed an input, parse the output please declare that as an API.
564
            </hint>
565
        </question>
566
-->
567
 <answer id="exec-process">
568
  <p>
569
   No
570
  </p>
571
 </answer>
572
573
574
575
<!--
576
        <question id="exec-property" when="impl">
577
            Is execution of your code influenced by any environment or
578
            Java system (<code>System.getProperty</code>) property?
579
            On a similar note, is there something interesting that you
580
            pass to <code>java.util.logging.Logger</code>? Or do you observe
581
            what others log?
582
            <hint>
583
            If there is a property that can change the behavior of your
584
            code, somebody will likely use it. You should describe what it does
585
            and the <a href="http://wiki.netbeans.org/API_Stability">stability category</a>
586
            of this API. You may use
587
            <pre>
588
                &lt;api type="export" group="property" name="id" category="private" url="http://..."&gt;
589
                    description of the property, where it is used, what it influence, etc.
590
                &lt;/api&gt;
591
            </pre>
592
            </hint>
593
        </question>
594
-->
595
 <answer id="exec-property">
596
  <p>
597
   No
598
  </p>
599
 </answer>
600
601
602
603
<!--
604
        <question id="exec-reflection" when="impl">
605
            Does your code use Java Reflection to execute other code?
606
            <hint>
607
            This usually indicates a missing or insufficient API in the other
608
            part of the system. If the other side is not aware of your dependency
609
            this contract can be easily broken.
610
            </hint>
611
        </question>
612
-->
613
 <answer id="exec-reflection">
614
  <p>
615
   No
616
  </p>
617
 </answer>
618
619
620
621
<!--
622
        <question id="exec-threading" when="init">
623
            What threading models, if any, does your module adhere to? How the
624
            project behaves with respect to threading?
625
            <hint>
626
                Is your API threadsafe? Can it be accessed from any threads or
627
                just from some dedicated ones? Any special relation to AWT and
628
                its Event Dispatch thread? Also
629
                if your module calls foreign APIs which have a specific threading model,
630
                indicate how you comply with the requirements for multithreaded access
631
                (synchronization, mutexes, etc.) applicable to those APIs.
632
                If your module defines any APIs, or has complex internal structures
633
                that might be used from multiple threads, declare how you protect
634
                data against concurrent access, race conditions, deadlocks, etc.,
635
                and whether such rules are enforced by runtime warnings, errors, assertions, etc.
636
                Examples: a class might be non-thread-safe (like Java Collections); might
637
                be fully thread-safe (internal locking); might require access through a mutex
638
                (and may or may not automatically acquire that mutex on behalf of a client method);
639
                might be able to run only in the event queue; etc.
640
                Also describe when any events are fired: synchronously, asynchronously, etc.
641
                Ideas: <a href="http://core.netbeans.org/proposals/threading/index.html#recommendations">Threading Recommendations</a> (in progress)
642
            </hint>
643
        </question>
644
-->
645
 <answer id="exec-threading">
646
  <p>
647
   Should be thread safe.
648
  </p>
649
 </answer>
650
651
652
653
<!--
654
        <question id="format-clipboard" when="impl">
655
            Which data flavors (if any) does your code read from or insert to
656
            the clipboard (by access to clipboard on means calling methods on <code>java.awt.datatransfer.Transferable</code>?
657
658
            <hint>
659
            Often Node's deal with clipboard by usage of <code>Node.clipboardCopy, Node.clipboardCut and Node.pasteTypes</code>.
660
            Check your code for overriding these methods.
661
            </hint>
662
        </question>
663
-->
664
 <answer id="format-clipboard">
665
  <p>
666
   Plain Unicode text only.
667
  </p>
668
 </answer>
669
670
671
672
<!--
673
        <question id="format-dnd" when="impl">
674
            Which protocols (if any) does your code understand during Drag &amp; Drop?
675
            <hint>
676
            Often Node's deal with clipboard by usage of <code>Node.drag, Node.getDropType</code>.
677
            Check your code for overriding these methods. Btw. if they are not overridden, they
678
            by default delegate to <code>Node.clipboardCopy, Node.clipboardCut and Node.pasteTypes</code>.
679
            </hint>
680
        </question>
681
-->
682
 <answer id="format-dnd">
683
  <p>
684
   N/A
685
  </p>
686
 </answer>
687
688
689
690
<!--
691
        <question id="format-types" when="impl">
692
            Which protocols and file formats (if any) does your module read or write on disk,
693
            or transmit or receive over the network? Do you generate an ant build script?
694
            Can it be edited and modified?
695
696
            <hint>
697
            <p>
698
            Files can be read and written by other programs, modules and users. If they influence
699
            your behaviour, make sure you either document the format or claim that it is a private
700
            api (using the &lt;api&gt; tag).
701
            </p>
702
703
            <p>
704
            If you generate an ant build file, this is very likely going to be seen by end users and
705
            they will be attempted to edit it. You should be ready for that and provide here a link
706
            to documentation that you have for such purposes and also describe how you are going to
707
            understand such files during next release, when you (very likely) slightly change the
708
            format.
709
            </p>
710
            </hint>
711
        </question>
712
-->
713
 <answer id="format-types">
714
  <p>
715
   None
716
  </p>
717
 </answer>
718
719
720
721
<!--
722
        <question id="lookup-lookup" when="init">
723
            Does your module use <code>org.openide.util.Lookup</code>
724
            or any similar technology to find any components to communicate with? Which ones?
725
726
            <hint>
727
            NetBeans is build around a generic registry of services called
728
            lookup. It is preferable to use it for registration and discovery
729
            if possible. See
730
            <a href="http://www.netbeans.org/download/dev/javadoc/org-openide-util/org/openide/util/lookup/doc-files/index.html">
731
            The Solution to Comunication Between Components
732
            </a>. If you do not plan to use lookup and insist usage
733
            of other solution, then please describe why it is not working for
734
            you.
735
            <br/>
736
            When filling the final version of your arch document, please
737
            describe the interfaces you are searching for, where
738
            are defined, whether you are searching for just one or more of them,
739
            if the order is important, etc. Also classify the stability of such
740
            API contract. Use &lt;api group=&amp;lookup&amp; /&gt; tag, so
741
            your information gets listed in the summary page of your javadoc.
742
            </hint>
743
        </question>
744
-->
745
 <answer id="lookup-lookup">
746
  <code>BaseIOProvider.getDefault()</code> asks lookup for the first instance
747
  of itself. This is normally provided by <code>org.netbeans.core.output2</code>.
748
 </answer>
749
750
751
752
<!--
753
        <question id="lookup-register" when="final">
754
            Do you register anything into lookup for other code to find?
755
            <hint>
756
            Do you register using layer file or using a declarative annotation such as <code>@ServiceProvider</code>?
757
            Who is supposed to find your component?
758
            </hint>
759
        </question>
760
-->
761
 <answer id="lookup-register">
762
  <p>
763
   No
764
  </p>
765
 </answer>
766
767
768
769
<!--
770
        <question id="lookup-remove" when="final">
771
            Do you remove entries of other modules from lookup?
772
            <hint>
773
            Why? Of course, that is possible, but it can be dangerous. Is the module
774
            your are masking resource from aware of what you are doing?
775
            </hint>
776
        </question>
777
-->
778
 <answer id="lookup-remove">
779
  <p>
780
   No
781
  </p>
782
 </answer>
783
784
785
786
<!--
787
        <question id="perf-exit" when="final">
788
            Does your module run any code on exit?
789
        </question>
790
-->
791
 <answer id="perf-exit">
792
  <p>
793
   No
794
  </p>
795
 </answer>
796
797
798
799
<!--
800
        <question id="perf-huge_dialogs" when="final">
801
            Does your module contain any dialogs or wizards with a large number of
802
            GUI controls such as combo boxes, lists, trees, or text areas?
803
        </question>
804
-->
805
 <answer id="perf-huge_dialogs">
806
  <p>
807
   No
808
  </p>
809
 </answer>
810
811
812
813
<!--
814
        <question id="perf-limit" when="init">
815
            Are there any hard-coded or practical limits in the number or size of
816
            elements your code can handle?
817
            <hint>
818
                Most of algorithms have increasing memory and speed complexity
819
                with respect to size of data they operate on. What is the critical
820
                part of your project that can be seen as a bottleneck with
821
                respect to speed or required memory? What are the practical
822
                sizes of data you tested your project with? What is your estimate
823
                of potential size of data that would cause visible performance
824
                problems? Is there some kind of check to detect such situation
825
                and prevent "hard" crashes - for example the CloneableEditorSupport
826
                checks for size of a file to be opened in editor
827
                and if it is larger than 1Mb it shows a dialog giving the
828
                user the right to decide - e.g. to cancel or commit suicide.
829
            </hint>
830
        </question>
831
-->
832
 <answer id="perf-limit">
833
  <p>
834
   No
835
  </p>
836
 </answer>
837
838
839
840
<!--
841
        <question id="perf-mem" when="final">
842
            How much memory does your component consume? Estimate
843
            with a relation to the number of windows, etc.
844
        </question>
845
-->
846
 <answer id="perf-mem">
847
  <p>
848
   N/A
849
  </p>
850
 </answer>
851
852
853
854
<!--
855
        <question id="perf-menus" when="final">
856
            Does your module use dynamically updated context menus, or
857
            context-sensitive actions with complicated and slow enablement logic?
858
            <hint>
859
                If you do a lot of tricks when adding actions to regular or context menus, you can significantly
860
                slow down display of the menu, even when the user is not using your action. Pay attention to
861
                actions you add to the main menu bar, and to context menus of foreign nodes or components. If
862
                the action is conditionally enabled, or changes its display dynamically, you need to check the
863
                impact on performance. In some cases it may be more appropriate to make a simple action that is
864
                always enabled but does more detailed checks in a dialog if it is actually run.
865
            </hint>
866
        </question>
867
-->
868
 <answer id="perf-menus">
869
  <p>
870
   No
871
  </p>
872
 </answer>
873
874
875
876
<!--
877
        <question id="perf-progress" when="final">
878
            Does your module execute any long-running tasks?
879
880
            <hint>Long running tasks should never block
881
            AWT thread as it badly hurts the UI
882
            <a href="http://performance.netbeans.org/responsiveness/issues.html">
883
            responsiveness</a>.
884
            Tasks like connecting over
885
            network, computing huge amount of data, compilation
886
            be done asynchronously (for example
887
            using <code>RequestProcessor</code>), definitively it should
888
            not block AWT thread.
889
            </hint>
890
        </question>
891
-->
892
 <answer id="perf-progress">
893
  <p>
894
   No
895
  </p>
896
 </answer>
897
898
899
900
<!--
901
        <question id="perf-scale" when="init">
902
            Which external criteria influence the performance of your
903
            program (size of file in editor, number of files in menu,
904
            in source directory, etc.) and how well your code scales?
905
            <hint>
906
            Please include some estimates, there are other more detailed
907
            questions to answer in later phases of implementation.
908
            </hint>
909
        </question>
910
-->
911
 <answer id="perf-scale">
912
  <p>
913
    Scalability in GUI speed and memory consumption is probably limited only
914
    by the Output Window implementation.
915
  </p>
916
 </answer>
917
918
919
920
<!--
921
        <question id="perf-spi" when="init">
922
            How the performance of the plugged in code will be enforced?
923
            <hint>
924
            If you allow foreign code to be plugged into your own module, how
925
            do you enforce that it will behave correctly and quickly and will not
926
            negatively influence the performance of your own module?
927
            </hint>
928
        </question>
929
-->
930
 <answer id="perf-spi">
931
  <p>
932
   No special behavior.
933
  </p>
934
 </answer>
935
936
937
938
<!--
939
        <question id="perf-startup" when="final">
940
            Does your module run any code on startup?
941
        </question>
942
-->
943
 <answer id="perf-startup">
944
  <p>
945
   No
946
  </p>
947
 </answer>
948
949
950
951
<!--
952
        <question id="perf-wakeup" when="final">
953
            Does any piece of your code wake up periodically and do something
954
            even when the system is otherwise idle (no user interaction)?
955
        </question>
956
-->
957
 <answer id="perf-wakeup">
958
  <p>
959
   No
960
  </p>
961
 </answer>
962
963
964
965
<!--
966
        <question id="resources-file" when="final">
967
            Does your module use <code>java.io.File</code> directly?
968
969
            <hint>
970
            NetBeans provide a logical wrapper over plain files called
971
            <code>org.openide.filesystems.FileObject</code> that
972
            provides uniform access to such resources and is the preferred
973
            way that should be used. But of course there can be situations when
974
            this is not suitable.
975
            </hint>
976
        </question>
977
-->
978
 <answer id="resources-file">
979
   <p>No, but the implementation may.</p>
980
 </answer>
981
982
983
984
<!--
985
        <question id="resources-layer" when="final">
986
            Does your module provide own layer? Does it create any files or
987
            folders in it? What it is trying to communicate by that and with which
988
            components?
989
990
            <hint>
991
            NetBeans allows automatic and declarative installation of resources
992
            by module layers. Module register files into appropriate places
993
            and other components use that information to perform their task
994
            (build menu, toolbar, window layout, list of templates, set of
995
            options, etc.).
996
            </hint>
997
        </question>
998
-->
999
 <answer id="resources-layer">
1000
  <p>
1001
   No
1002
  </p>
1003
 </answer>
1004
1005
1006
1007
<!--
1008
        <question id="resources-mask" when="final">
1009
            Does your module mask/hide/override any resources provided by other modules in
1010
            their layers?
1011
1012
            <hint>
1013
            If you mask a file provided by another module, you probably depend
1014
            on that and do not want the other module to (for example) change
1015
            the file's name. That module shall thus make that file available as an API
1016
            of some stability category.
1017
            </hint>
1018
        </question>
1019
-->
1020
 <answer id="resources-mask">
1021
  <p>
1022
   No
1023
  </p>
1024
 </answer>
1025
1026
1027
1028
<!--
1029
        <question id="resources-preferences" when="final">
1030
            Does your module uses preferences via Preferences API? Does your module use NbPreferences or
1031
            or regular JDK Preferences ? Does it read, write or both ?
1032
            Does it share preferences with other modules ? If so, then why ?
1033
            <hint>
1034
                You may use
1035
                    &lt;api type="export" group="preferences"
1036
                    name="preference node name" category="private"&gt;
1037
                    description of individual keys, where it is used, what it
1038
                    influences, whether the module reads/write it, etc.
1039
                    &lt;/api&gt;
1040
                Due to XML ID restrictions, rather than /org/netbeans/modules/foo give the "name" as org.netbeans.modules.foo.
1041
                Note that if you use NbPreferences this name will then be the same as the code name base of the module.
1042
            </hint>
1043
        </question>
1044
-->
1045
 <answer id="resources-preferences">
1046
  <p>
1047
   No
1048
  </p>
1049
 </answer>
1050
1051
1052
1053
<!--
1054
        <question id="resources-read" when="final">
1055
            Does your module read any resources from layers? For what purpose?
1056
1057
            <hint>
1058
            As this is some kind of intermodule dependency, it is a kind of API.
1059
            Please describe it and classify according to
1060
            <a href="http://wiki.netbeans.org/API_Design#What_is_an_API.3F">
1061
            common stability categories</a>.
1062
            </hint>
1063
        </question>
1064
-->
1065
 <answer id="resources-read">
1066
  <p>
1067
   No
1068
  </p>
1069
 </answer>
1070
1071
1072
1073
<!--
1074
        <question id="security-grant" when="final">
1075
            Does your code grant additional rights to some other code?
1076
            <hint>Avoid using a class loader that adds extra
1077
            permissions to loaded code unless really necessary.
1078
            Also note that your API implementation
1079
            can also expose unneeded permissions to enemy code by
1080
            calling AccessController.doPrivileged().</hint>
1081
        </question>
1082
-->
1083
 <answer id="security-grant">
1084
  <p>
1085
   No
1086
  </p>
1087
 </answer>
1088
1089
1090
1091
<!--
1092
        <question id="security-policy" when="final">
1093
            Does your functionality require modifications to the standard policy file?
1094
            <hint>Your code might pass control to third-party code not
1095
            coming from trusted domains. This could be code downloaded over the
1096
            network or code coming from libraries that are not bundled
1097
            with NetBeans. Which permissions need to be granted to which domains?</hint>
1098
        </question>
1099
-->
1100
 <answer id="security-policy">
1101
  <p>
1102
   No
1103
  </p>
1104
 </answer>
1105
1106
</api-answers>
(-)a/openide.io.base/build.xml (+5 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project basedir="." default="netbeans" name="openide.io.base">
3
    <description>Builds, tests, and runs the project org.openide.io.base</description>
4
    <import file="../nbbuild/templates/projectized.xml"/>
5
</project>
(-)a/openide.io.base/manifest.mf (+5 lines)
Line 0 Link Here
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.io.base/1
3
OpenIDE-Module-Localizing-Bundle: org/openide/io/base/Bundle.properties
4
OpenIDE-Module-Specification-Version: 1.0
5
(-)a/openide.io.base/nbproject/project.properties (+4 lines)
Line 0 Link Here
1
is.autoload=true
2
javac.source=1.6
3
javac.compilerargs=-Xlint -Xlint:-serial
4
javadoc.arch=${basedir}/arch.xml
(-)a/openide.io.base/nbproject/project.xml (+39 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://www.netbeans.org/ns/project/1">
3
    <type>org.netbeans.modules.apisupport.project</type>
4
    <configuration>
5
        <data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
6
            <code-name-base>org.openide.io.base</code-name-base>
7
            <module-dependencies>
8
                <dependency>
9
                    <code-name-base>org.netbeans.api.annotations.common</code-name-base>
10
                    <build-prerequisite/>
11
                    <compile-dependency/>
12
                    <run-dependency>
13
                        <release-version>1</release-version>
14
                        <specification-version>1.24</specification-version>
15
                    </run-dependency>
16
                </dependency>
17
                <dependency>
18
                    <code-name-base>org.openide.util.base</code-name-base>
19
                    <build-prerequisite/>
20
                    <compile-dependency/>
21
                    <run-dependency>
22
                        <specification-version>9.1</specification-version>
23
                    </run-dependency>
24
                </dependency>
25
                <dependency>
26
                    <code-name-base>org.openide.util.lookup</code-name-base>
27
                    <build-prerequisite/>
28
                    <compile-dependency/>
29
                    <run-dependency>
30
                        <specification-version>8.25</specification-version>
31
                    </run-dependency>
32
                </dependency>
33
            </module-dependencies>
34
            <public-packages>
35
                <package>org.openide.io.base</package>
36
            </public-packages>
37
        </data>
38
    </configuration>
39
</project>
(-)a/openide.io.base/src/org/openide/io/base/BaseColor.java (+193 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2014 Sun Microsystems, Inc.
41
 */
42
package org.openide.io.base;
43
44
/**
45
 * Color for use in base I/O APIs. Extrected from java.awt.Color.
46
 *
47
 * @author jhavlin
48
 */
49
public final class BaseColor {
50
51
    private int value;
52
53
    /**
54
     * Creates an opaque sRGB color with the specified combined RGB value
55
     * consisting of the red component in bits 16-23, the green component in
56
     * bits 8-15, and the blue component in bits 0-7. The actual color used in
57
     * rendering depends on finding the best match given the color space
58
     * available for a particular output device. Alpha is defaulted to 255.
59
     *
60
     * @param rgb the combined RGB components
61
     * @see #getRed
62
     * @see #getGreen
63
     * @see #getBlue
64
     * @see #getRGB
65
     */
66
    public BaseColor(int rgb) {
67
        value = 0xff000000 | rgb;
68
    }
69
70
    /**
71
     * Creates an sRGB color with the specified combined RGBA value consisting
72
     * of the alpha component in bits 24-31, the red component in bits 16-23,
73
     * the green component in bits 8-15, and the blue component in bits 0-7. If
74
     * the <code>hasalpha</code> argument is <code>false</code>, alpha is
75
     * defaulted to 255.
76
     *
77
     * @param rgba the combined RGBA components
78
     * @param hasalpha <code>true</code> if the alpha bits are valid;
79
     * <code>false</code> otherwise
80
     * @see java.awt.image.ColorModel#getRGBdefault
81
     * @see #getRed
82
     * @see #getGreen
83
     * @see #getBlue
84
     * @see #getAlpha
85
     * @see #getRGB
86
     */
87
    public BaseColor(int rgba, boolean hasalpha) {
88
        if (hasalpha) {
89
            value = rgba;
90
        } else {
91
            value = 0xff000000 | rgba;
92
        }
93
    }
94
95
    /**
96
     * Creates an opaque sRGB color with the specified red, green, and blue
97
     * values in the range (0 - 255). The actual color used in rendering depends
98
     * on finding the best match given the color space available for a given
99
     * output device. Alpha is defaulted to 255.
100
     *
101
     * @throws IllegalArgumentException if <code>r</code>, <code>g</code> or
102
     * <code>b</code> are outside of the range 0 to 255, inclusive
103
     * @param r the red component
104
     * @param g the green component
105
     * @param b the blue component
106
     * @see #getRed
107
     * @see #getGreen
108
     * @see #getBlue
109
     * @see #getRGB
110
     */
111
    public BaseColor(int r, int g, int b) {
112
        this(r, g, b, 255);
113
    }
114
115
    /**
116
     * Creates an sRGB color with the specified red, green, blue, and alpha
117
     * values in the range (0 - 255).
118
     *
119
     * @throws IllegalArgumentException if <code>r</code>, <code>g</code>,
120
     * <code>b</code> or <code>a</code> are outside of the range 0 to 255,
121
     * inclusive
122
     * @param r the red component
123
     * @param g the green component
124
     * @param b the blue component
125
     * @param a the alpha component
126
     * @see #getRed
127
     * @see #getGreen
128
     * @see #getBlue
129
     * @see #getAlpha
130
     * @see #getRGB
131
     */
132
    public BaseColor(int r, int g, int b, int a) {
133
        value = ((a & 0xFF) << 24)
134
                | ((r & 0xFF) << 16)
135
                | ((g & 0xFF) << 8)
136
                | ((b & 0xFF));
137
    }
138
139
    /**
140
     * Returns the RGB value representing the color in the default sRGB
141
     * color model. (Bits 24-31 are alpha, 16-23 are red, 8-15 are green,
142
     * 0-7 are blue).
143
     *
144
     * @return the RGB value of the color in the default sRGB
145
     * <code>ColorModel</code>.
146
     * @see #getRed
147
     * @see #getGreen
148
     * @see #getBlue
149
     */
150
    public int getRGB() {
151
        return value;
152
    }
153
154
    /**
155
     * Returns the red component in the range 0-255 in the default sRGB space.
156
     *
157
     * @return the red component.
158
     * @see #getRGB
159
     */
160
    public int getRed() {
161
        return (getRGB() >> 16) & 0xFF;
162
    }
163
164
    /**
165
     * Returns the green component in the range 0-255 in the default sRGB space.
166
     *
167
     * @return the green component.
168
     * @see #getRGB
169
     */
170
    public int getGreen() {
171
        return (getRGB() >> 8) & 0xFF;
172
    }
173
174
    /**
175
     * Returns the blue component in the range 0-255 in the default sRGB space.
176
     *
177
     * @return the blue component.
178
     * @see #getRGB
179
     */
180
    public int getBlue() {
181
        return (getRGB()) & 0xFF;
182
    }
183
184
    /**
185
     * Returns the alpha component in the range 0-255.
186
     *
187
     * @return the alpha component.
188
     * @see #getRGB
189
     */
190
    public int getAlpha() {
191
        return (getRGB() >> 24) & 0xff;
192
    }
193
}
(-)a/openide.io/src/org/openide/windows/FoldHandle.java (-22 / +11 lines)
Lines 40-67 Link Here
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
41
 */
42
42
43
package org.openide.windows;
43
package org.openide.io.base;
44
44
45
import java.util.logging.Level;
45
import java.util.logging.Level;
46
import java.util.logging.Logger;
46
import java.util.logging.Logger;
47
import org.netbeans.api.annotations.common.CheckForNull;
47
import org.netbeans.api.annotations.common.CheckForNull;
48
import org.openide.windows.IOFolding.FoldHandleDefinition;
48
import org.openide.io.base.BaseIOFolding.FoldHandleDefinition;
49
49
50
/**
50
/**
51
 * An object that refers to a fold in output window. It can be used to finish
51
 * An object that refers to a fold in output window. It can be used to finish
52
 * the fold, or to create nested folds.
52
 * the fold, or to create nested folds.
53
 *
53
 *
54
 * @author jhavlin
54
 * @author jhavlin
55
 * @since openide.io/1.38
56
 */
55
 */
57
public final class FoldHandle {
56
public final class BaseFoldHandle {
58
57
59
    private final FoldHandleDefinition definition;
58
    private final FoldHandleDefinition definition;
60
    private static final Logger LOG = Logger.getLogger(FoldHandle.class.getName());
59
    private static final Logger LOG = Logger.getLogger(BaseFoldHandle.class.getName());
61
    private FoldHandle currentChild;
60
    private BaseFoldHandle currentChild;
62
    private boolean finished = false;
61
    private boolean finished = false;
63
62
64
    FoldHandle(FoldHandleDefinition definition) {
63
    BaseFoldHandle(FoldHandleDefinition definition) {
65
        this.definition = definition;
64
        this.definition = definition;
66
    }
65
    }
67
66
Lines 85-92 Link Here
85
     * @throws IllegalStateException if the fold has been already finished, or
84
     * @throws IllegalStateException if the fold has been already finished, or
86
     * if an unfinished nested fold exists.
85
     * if an unfinished nested fold exists.
87
     */
86
     */
88
    public FoldHandle startFold(boolean expanded) {
87
    public BaseFoldHandle startFold(boolean expanded) {
89
        currentChild = new FoldHandle(definition.startFold(expanded));
88
        currentChild = new BaseFoldHandle(definition.startFold(expanded));
90
        return currentChild;
89
        return currentChild;
91
    }
90
    }
92
91
Lines 106-113 Link Here
106
     *
105
     *
107
     * @return True if {@link #finish()} or {@link #silentFinish()} has been
106
     * @return True if {@link #finish()} or {@link #silentFinish()} has been
108
     * already called on this fold handle, false otherwise.
107
     * already called on this fold handle, false otherwise.
109
     *
110
     * @since openide.io/1.42
111
     */
108
     */
112
    public boolean isFinished() {
109
    public boolean isFinished() {
113
        return finished;
110
        return finished;
Lines 119-128 Link Here
119
     * unfinished.
116
     * unfinished.
120
     *
117
     *
121
     * @return The last started nested fold. Can be null.
118
     * @return The last started nested fold. Can be null.
122
     *
123
     * @since openide.io/1.42
124
     */
119
     */
125
    public @CheckForNull FoldHandle getLastNestedFold() {
120
    public @CheckForNull BaseFoldHandle getLastNestedFold() {
126
        return currentChild;
121
        return currentChild;
127
    }
122
    }
128
123
Lines 131-140 Link Here
131
     * returns null if the last nested fold has been already finished.
126
     * returns null if the last nested fold has been already finished.
132
     *
127
     *
133
     * @return The last unfinished nested fold or null.
128
     * @return The last unfinished nested fold or null.
134
     *
135
     *  @since openide.io/1.42
136
     */
129
     */
137
    public @CheckForNull FoldHandle getCurrentNestedFold() {
130
    public @CheckForNull BaseFoldHandle getCurrentNestedFold() {
138
        return (currentChild != null && !currentChild.isFinished())
131
        return (currentChild != null && !currentChild.isFinished())
139
                ? currentChild
132
                ? currentChild
140
                : null;
133
                : null;
Lines 145-152 Link Here
145
     * handle has been already finished. If an unfinished child fold exists, it
138
     * handle has been already finished. If an unfinished child fold exists, it
146
     * will be finished too. Any exception that could happen will be caught and
139
     * will be finished too. Any exception that could happen will be caught and
147
     * logged.
140
     * logged.
148
     *
149
     * @since openide.io/1.42
150
     */
141
     */
151
    public void silentFinish() {
142
    public void silentFinish() {
152
        if (!finished) {
143
        if (!finished) {
Lines 170-179 Link Here
170
     * @param expanded True to expand the new fold, false to collapse it, parent
161
     * @param expanded True to expand the new fold, false to collapse it, parent
171
     * folds will not be collapsed/expanded.
162
     * folds will not be collapsed/expanded.
172
     * @return The new fold handle, or null if it cannot be created.
163
     * @return The new fold handle, or null if it cannot be created.
173
     *
174
     *  @since openide.io/1.42
175
     */
164
     */
176
    public @CheckForNull FoldHandle silentStartFold(boolean expanded) {
165
    public @CheckForNull BaseFoldHandle silentStartFold(boolean expanded) {
177
        if (!finished) {
166
        if (!finished) {
178
            if (currentChild != null && !currentChild.finished) {
167
            if (currentChild != null && !currentChild.finished) {
179
                currentChild.silentFinish();
168
                currentChild.silentFinish();
(-)a/openide.io/src/org/openide/windows/IOColorLines.java (-61 / +89 lines)
Lines 40-129 Link Here
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
41
 */
41
 */
42
42
43
package org.openide.windows;
43
package org.openide.io.base;
44
44
45
import java.awt.Color;
46
import java.io.IOException;
45
import java.io.IOException;
46
import org.netbeans.api.annotations.common.NonNull;
47
import org.netbeans.api.annotations.common.NullAllowed;
47
import org.openide.util.Lookup;
48
import org.openide.util.Lookup;
48
49
49
/**
50
/**
50
 * Line printing with custom color.
51
 * Line printing with custom color.
51
 * <p>
52
 * <p>
52
 * Client usage:
53
 * Client usage:
54
 * </p>
53
 * <pre>
55
 * <pre>
54
 *  // print green line
56
 *  // print green line
55
 *  InputOutput io = ...;
57
 *  {@link BaseInputOutput} io = ...;
56
 *  IOColorLines.println(io, "Green line", Color.GREEN);
58
 *  if (BaseIOColorLines.isSupported(io)) {
59
 *      BaseIOColorLines.println(io, "Green line", Color.GREEN);
60
 *  }
57
 * </pre>
61
 * </pre>
58
 * How to support {@link IOColorLines} in own {@link IOProvider} implementation:
62
 * How to support {@link BaseIOColorLines} in own {@link BaseIOProvider} implementation:
59
 * <ul>
63
 * <ul>
60
 *   <li> {@link InputOutput} provided by {@link IOProvider} has to implement {@link org.openide.util.Lookup.Provider}
64
 *   <li> Implement some {@link Provider} of BaseIOColorLines.</li>
61
 *   <li> Extend {@link IOColorLines} and implement its abstract methods
65
 *   <li> Place instance of {@link Provider} to {@link Lookup} provided by {@link BaseInputOutput}.</li>
62
 *   <li> Place instance of {@link IOColorLines} to {@link Lookup} provided by {@link InputOutput}
63
 * </ul>
66
 * </ul>
64
 * @see IOColors
67
 * @see BaseIOColors
65
 * @see IOColorPrint
68
 * @see BaseIOColorPrint
66
 * @since 1.16
69
 * @author Tomas Holy, Jaroslav Havlin
67
 * @author Tomas Holy
68
 */
70
 */
69
public abstract class IOColorLines {
71
public final class BaseIOColorLines {
70
72
71
    private static IOColorLines find(InputOutput io) {
73
    private BaseIOColorLines() {}
72
        if (io instanceof Lookup.Provider) {
74
73
            Lookup.Provider p = (Lookup.Provider) io;
75
    /**
74
            return p.getLookup().lookup(IOColorLines.class);
76
     * Prints line with selected color.
75
        }
77
     *
76
        return null;
78
     * @param io IO to print to.
79
     * @param text A string to print to the tab.
80
     * @param color A color for the line of text (null allowed). If null is
81
     * passed default color (see {@link BaseIOColors}) is used.
82
     * @throws java.io.IOException if printing to the output fails.
83
     * @throws IllegalArgumentException if the I/O does not support this
84
     * feature.
85
     */
86
    public static void println(
87
            @NonNull BaseInputOutput io,
88
            @NonNull CharSequence text,
89
            @NullAllowed BaseColor color) throws IOException {
90
        println(io, text, false, color);
77
    }
91
    }
78
92
79
    /**
93
    /**
80
     * Prints line with selected color
94
     * Prints line with selected color
81
     * @param io IO to print to
95
     *
82
     * @param text a string to print to the tab
96
     * @param io IO to print to.
83
     * @param color a color for the line of text (null allowed). If null is passed default color (see {@link IOColors}) is used.
97
     * @param text A string to print to the tab.
98
     * @param important Mark the line as important. Makes the UI respond
99
     * appropriately, eg. stop the automatic scrolling or highlight the
100
     * hyperlink.
101
     * @param color A color for the line of text (null allowed). If null is
102
     * passed default color (see {@link BaseIOColors}) is used.
103
     * @param extendedInfo Output listener, output tag, or similar objects. See
104
     * {@link BaseIOHyperlink}.
105
     * @throws java.io.IOException if printing to the output fails.
106
     * @throws IllegalArgumentException if the I/O does not support this
107
     * feature.
84
     */
108
     */
85
    public static void println(InputOutput io, CharSequence text, Color color) throws IOException {
109
    public static void println(
86
        IOColorLines iocl = find(io);
110
            @NonNull BaseInputOutput io,
87
        if (iocl != null) {
111
            @NonNull CharSequence text,
88
            iocl.println(text, null, false, color);
112
            boolean important,
89
        }
113
            @NullAllowed BaseColor color,
114
            @NonNull BaseIOLinkInfo... extendedInfo)
115
            throws IOException {
116
117
        ExtrasHelper.getExtras(io, BaseIOColorLines.Provider.class).println(
118
                text, important, color, extendedInfo);
119
    }
120
121
122
    /**
123
     * Checks whether this feature is supported for provided IO.
124
     * @param io IO to check on.
125
     * @return True if supported.
126
     */
127
    public static boolean isSupported(@NonNull BaseInputOutput io) {
128
        return ExtrasHelper.isSupported(io, BaseIOColorLines.Provider.class);
90
    }
129
    }
91
130
92
    /**
131
    /**
93
     * Prints line with selected color
132
     * SPI for implementing support for color printing.
94
     * @param io IO to print to
133
     * @see BaseIOColorLines
95
     * @param text a string to print to the tab
96
     * @param listener a listener that will receive events about this line
97
     * @param important  important mark the line as important.
98
     *        Makes the UI respond appropriately, eg. stop the automatic scrolling
99
     *        or highlight the hyperlink.
100
     * @param color a color for the line of text (null allowed). If null is passed default color (see {@link IOColors}) is used.
101
     */
134
     */
102
    public static void println(InputOutput io, CharSequence text, OutputListener listener, boolean important, Color color) throws IOException {
135
    public interface Provider {
103
        IOColorLines iocl = find(io);
136
104
        if (iocl != null) {
137
        /**
105
            iocl.println(text, listener, important, color);
138
         * Prints line with selected color
106
        }
139
         *
140
         * @param text A string to print to the tab. or other extension type,
141
         * see {@link BaseIOHyperlink}. (null allowed)
142
         * @param important Mark the line as important. Makes the UI respond
143
         * appropriately, eg. stop the automatic scrolling or highlight the
144
         * hyperlink.
145
         * @param color A color for the line of text (null allowed). If null is
146
         * passed default color (see {@link BaseIOColors}) is used.
147
         * @param extendedInfo Output listener, output tag, or similar objects.
148
         * See {@link BaseIOHyperlink}.
149
         * @throws java.io.IOException if printing to the output fails.
150
         */
151
        void println(
152
                @NonNull CharSequence text,
153
                boolean important,
154
                @NullAllowed BaseColor color,
155
                @NonNull BaseIOLinkInfo... extendedInfo) throws IOException;
107
    }
156
    }
108
109
110
    /**
111
     * Checks whether this feature is supported for provided IO
112
     * @param io IO to check on
113
     * @return true if supported
114
     */
115
    public static boolean isSupported(InputOutput io) {
116
        return find(io) != null;
117
    }
118
119
    /**
120
     * Prints line with selected color
121
     * @param text a string to print to the tab
122
     * @param listener a listener that will receive events about this line (null allowed)
123
     * @param important  important mark the line as important.
124
     *        Makes the UI respond appropriately, eg. stop the automatic scrolling
125
     *        or highlight the hyperlink.
126
     * @param color a color for the line of text (null allowed). If null is passed default color (see {@link IOColors}) is used.
127
     */
128
    abstract protected void println(CharSequence text, OutputListener listener, boolean important, Color color) throws IOException;
129
}
157
}
(-)a/openide.io/src/org/openide/windows/IOColorPrint.java (-55 / +76 lines)
Lines 40-112 Link Here
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
41
 */
41
 */
42
42
43
package org.openide.windows;
43
package org.openide.io.base;
44
44
45
import java.awt.Color;
46
import java.io.IOException;
45
import java.io.IOException;
46
import org.netbeans.api.annotations.common.NonNull;
47
import org.netbeans.api.annotations.common.NullAllowed;
47
import org.openide.util.Lookup;
48
import org.openide.util.Lookup;
48
49
49
/**
50
/**
50
 * Text printing with custom color.
51
 * Text printing with custom color.
51
 * <p>
52
 * <p>
52
 * Client usage:
53
 * Client usage:
54
 * </p>
53
 * <pre>
55
 * <pre>
54
 *  InputOutput io = ...;
56
  BaseInputOutput io = ...;
55
 *  OutputListener l = ...;
57
  BaseOutputListener l = ...;
56
 *  OutputListener l2 = ...;
58
  BaseOutputListener l2 = ...;
57
 *  IOColorPrint.print(io, "Green text", Color.GREEN);
59
  if (BaseIOColorPrint.isSupported(io)) {
58
 *  IOColorPrint.print(io, " orange hyperlink ", l, false, Color.ORANGE);
60
    BaseIOColorPrint.print(io, "Green text", Color.GREEN);
59
 *  IOColorPrint.print(io, " green hyperlink\n", l2, false, Color.GREEN);
61
    BaseIOColorPrint.print(io, " orange hyperlink ", false, Color.ORANGE, l);
60
 * </pre>
62
    BaseIOColorPrint.print(io, " green hyperlink\n", false, Color.GREEN, l2);
61
 * How to support {@link IOColorPrint} in own {@link IOProvider} implementation:
63
  }
64
 </pre>
65
 * How to support {@link BaseIOColorPrint} in own {@link BaseIOProvider} implementation:
62
 * <ul>
66
 * <ul>
63
 *   <li> {@link InputOutput} provided by {@link IOProvider} has to implement {@link org.openide.util.Lookup.Provider}
67
 *   <li> Implement some {@link Provider} of BaseIOColorPrint.</li>
64
 *   <li> Extend {@link IOColorPrint} and implement its abstract methods
68
 *   <li> Place instance of {@link Provider} to {@link Lookup} provided by {@link BaseInputOutput}.</li>
65
 *   <li> Place instance of {@link IOColorPrint} to {@link Lookup} provided by {@link InputOutput}
66
 * </ul>
69
 * </ul>
67
 * @see IOColors
70
 * @see BaseIOColors
68
 * @see IOColorLines
71
 * @see BaseIOColorLines
69
 * @since 1.18
72
 * @author Tomas Holy, Jaroslav Havlin
70
 * @author Tomas Holy
71
 */
73
 */
72
public abstract class IOColorPrint {
74
public final class BaseIOColorPrint {
73
75
74
    private static IOColorPrint find(InputOutput io) {
76
    private BaseIOColorPrint() {}
75
        if (io instanceof Lookup.Provider) {
76
            Lookup.Provider p = (Lookup.Provider) io;
77
            return p.getLookup().lookup(IOColorPrint.class);
78
        }
79
        return null;
80
    }
81
77
82
    /**
78
    /**
83
     * Prints text with selected color
79
     * Prints text with selected color
84
     * @param io IO to print to
80
     * @param io IO to print to.
85
     * @param text a string to print to the tab
81
     * @param text A string to print to the tab.
86
     * @param color a color for the text (null allowed). If null is passed default color (see {@link IOColors}) is used.
82
     * @param color A color for the text (null allowed). If null is passed
83
     * default color (see {@link BaseIOColors}) is used.
84
     * @throws java.io.IOException if printint to the output fails.
85
     * @throws IllegalArgumentException if the I/O does not support this
86
     * feature.
87
     */
87
     */
88
    public static void print(InputOutput io, CharSequence text, Color color) throws IOException {
88
    public static void print(
89
        IOColorPrint iocl = find(io);
89
            @NonNull BaseInputOutput io,
90
        if (iocl != null) {
90
            @NonNull CharSequence text,
91
            iocl.print(text, null, false, color);
91
            @NullAllowed BaseColor color) throws IOException {
92
        }
92
        print(io, text, false, color);
93
    }
93
    }
94
94
95
    /**
95
    /**
96
     * Prints text with selected color and add listener for it
96
     * Prints text with selected color and add listener for it
97
     * @param io IO to print to
97
     * @param io IO to print to.
98
     * @param text a string to print to the tab
98
     * @param text A string to print to the tab.
99
     * @param listener a listener that will receive events about this text (null allowed)
99
     * @param important  Mark the line as important.
100
     * @param important  important mark the line as important.
101
     *        Makes the UI respond appropriately, eg. stop the automatic scrolling
100
     *        Makes the UI respond appropriately, eg. stop the automatic scrolling
102
     *        or highlight the hyperlink.
101
     *        or highlight the hyperlink.
103
     * @param color a color for the text (null allowed). If null is passed default color (see {@link IOColors}) is used.
102
     * @param color A color for the text (null allowed). If null is passed
103
     * default color (see {@link BaseIOColors}) is used.
104
     * @param extendedInfo Output listeners, output tags or similar objects, see
105
     * {@link BaseIOHyperlink}.
106
     * @throws java.io.IOException if writing to the output fails.
107
     * @throws IllegalArgumentException if the I/O does not support this
108
     * feature.
104
     */
109
     */
105
    public static void print(InputOutput io, CharSequence text, OutputListener listener, boolean important, Color color) throws IOException {
110
    public static void print(
106
        IOColorPrint iocl = find(io);
111
            @NonNull BaseInputOutput io,
107
        if (iocl != null) {
112
            @NonNull CharSequence text,
108
            iocl.print(text, listener, important, color);
113
            boolean important,
109
        }
114
            @NullAllowed BaseColor color,
115
            @NonNull BaseIOLinkInfo... extendedInfo)
116
            throws IOException {
117
118
        ExtrasHelper.getExtras(io, BaseIOColorPrint.Provider.class).print(
119
                text, important, color, extendedInfo);
110
    }
120
    }
111
121
112
122
Lines 115-132 Link Here
115
     * @param io IO to check on
125
     * @param io IO to check on
116
     * @return true if supported
126
     * @return true if supported
117
     */
127
     */
118
    public static boolean isSupported(InputOutput io) {
128
    public static boolean isSupported(@NonNull BaseInputOutput io) {
119
        return find(io) != null;
129
        return ExtrasHelper.isSupported(io, BaseIOColorPrint.Provider.class);
120
    }
130
    }
121
131
122
    /**
132
    public interface Provider {
123
     * Prints text with selected color and optionaly add listener for it
133
124
     * @param text a string to print to the tab
134
        /**
125
     * @param listener a listener that will receive events about this text (null allowed)
135
         * Prints text with selected color and optionaly add listener for it
126
     * @param important  important mark the line as important.
136
         *
127
     *        Makes the UI respond appropriately, eg. stop the automatic scrolling
137
         * @param text A string to print to the tab.
128
     *        or highlight the hyperlink.
138
         * @param important Mark the line as important. Makes the UI
129
     * @param color a color for the text (null allowed). If null is passed default color (see {@link IOColors}) is used.
139
         * respond appropriately, eg. stop the automatic scrolling or highlight
130
     */
140
         * the hyperlink.
131
    abstract protected void print(CharSequence text, OutputListener listener, boolean important, Color color) throws IOException;
141
         * @param color A color for the text (null allowed). If null is passed
142
         * default color (see {@link BaseIOColors}) is used.
143
         * @param extendedInfo Output listener, output tag or similar objects,
144
         * see {@link BaseIOHyperlink}.
145
         * @throws java.io.IOException if writing to the output fails.
146
         */
147
        void print(
148
                @NonNull CharSequence text,
149
                boolean important,
150
                @NullAllowed BaseColor color,
151
                @NonNull BaseIOLinkInfo... extendedInfo) throws IOException;
152
    }
132
}
153
}
(-)a/openide.io/src/org/openide/windows/IOColors.java (-50 / +64 lines)
Lines 40-80 Link Here
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
41
 */
41
 */
42
42
43
package org.openide.windows;
43
package org.openide.io.base;
44
44
45
import java.awt.Color;
45
import org.netbeans.api.annotations.common.CheckForNull;
46
import org.netbeans.api.annotations.common.NonNull;
46
import org.openide.util.Lookup;
47
import org.openide.util.Lookup;
47
48
48
/**
49
/**
49
 * Settings of colors for normal, error, hyperlink, important hyperlink lines.
50
 * Settings of colors for normal, error, hyperlink, important hyperlink lines.
50
 * Change is global for text past and future.
51
 * Change is global for text past and future.
51
 * <p>
52
 * <p>
52
 * Client usage:
53
 *   Client usage:
54
 * </p>
53
 * <pre>
55
 * <pre>
54
 *  // set important hyperlink color to red
56
   // set important hyperlink color to red
55
 *  InputOutput io = ...;
57
   BaseInputOutput io = ...;
56
 *  IOColors.setColor(io, IOColors.OutputType.HYPERLINK_IMPORTANT, Color.RED);
58
   if (BaseIOColors.isSupported(io)) {
57
 * </pre>
59
       BaseIOColors.setColor(io, BaseIOColors.OutputType.HYPERLINK_IMPORTANT, Color.RED);
58
 * How to support {@link IOColors} in own {@link IOProvider} implementation:
60
   }
61
 </pre>
62
 * How to support {@link BaseIOColors} in own {@link BaseIOProvider} implementation:
59
 * <ul>
63
 * <ul>
60
 *   <li> {@link InputOutput} provided by {@link IOProvider} has to implement {@link org.openide.util.Lookup.Provider}
64
 *   <li> Implement some {@link Provider} of BaseIOColors.
61
 *   <li> Extend {@link IOColors} and implement its abstract methods
65
 *   <li> Place instance of {@link BaseIOColors} to {@link Lookup} provided by {@link BaseInputOutput}.
62
 *   <li> Place instance of {@link IOColors} to {@link Lookup} provided by {@link InputOutput}
63
 * </ul>
66
 * </ul>
64
 * @see IOColorLines
67
 * @see BaseIOColorLines
65
 * @see IOColorPrint
68
 * @see BaseIOColorPrint
66
 * @since 1.16
69
 * @author Tomas Holy, Jaroslav Havlin
67
 * @author Tomas Holy
68
 */
70
 */
69
public abstract class IOColors {
71
public final class BaseIOColors {
70
72
71
    private static IOColors find(InputOutput io) {
73
    private BaseIOColors() {}
72
        if (io instanceof Lookup.Provider) {
73
            Lookup.Provider p = (Lookup.Provider) io;
74
            return p.getLookup().lookup(IOColors.class);
75
        }
76
        return null;
77
    }
78
74
79
    /**
75
    /**
80
     * output types
76
     * output types
Lines 110-158 Link Here
110
    }
106
    }
111
107
112
    /**
108
    /**
113
     * Gets current color for output
109
     * Gets current color for output.
114
     * @param io InputOutput to operate on
110
     * @param io {@link BaseInputOutput} to operate on.
115
     * @param type output type to get color for
111
     * @param type Output type to get color for.
116
     * @return current color for specified output type or null if not supported
112
     * @return Current color for specified output type or null if not supported.
117
     */
113
     */
118
    public static Color getColor(InputOutput io, OutputType type) {
114
    public static @CheckForNull BaseColor getColor(
119
        IOColors ioc = find(io);
115
            @NonNull BaseInputOutput io,
116
            @NonNull OutputType type) {
117
118
        Provider ioc = ExtrasHelper.find(io, BaseIOColors.Provider.class);
120
        return ioc != null ? ioc.getColor(type) : null;
119
        return ioc != null ? ioc.getColor(type) : null;
121
    }
120
    }
122
121
123
    /**
122
    /**
124
     * Sets specified color for output
123
     * Sets specified color for output.
125
     * @param io InputOutput to operate on
124
     *
126
     * @param type output type to set color for
125
     * @param io {@link BaseInputOutput} to operate on.
127
     * @param color new color for specified output type
126
     * @param type Output type to set color for.
127
     * @param color New color for specified output type.
128
     */
128
     */
129
    public static void setColor(InputOutput io, OutputType type, Color color) {
129
    public static void setColor(
130
        IOColors ioc = find(io);
130
            @NonNull BaseInputOutput io,
131
            @NonNull OutputType type,
132
            @NonNull BaseColor color) {
133
        Provider ioc = ExtrasHelper.find(io, BaseIOColors.Provider.class);
131
        if (ioc != null) {
134
        if (ioc != null) {
132
            ioc.setColor(type, color);
135
            ioc.setColor(type, color);
133
        }
136
        }
134
    }
137
    }
135
138
136
    /**
139
    /**
137
     * Checks whether this feature is supported for provided IO
140
     * Checks whether this feature is supported for provided IO.
138
     * @param io IO to check on
141
     *
139
     * @return true if supported
142
     * @param io IO to check on.
143
     * @return True if supported.
140
     */
144
     */
141
    public static boolean isSupported(InputOutput io) {
145
    public static boolean isSupported(@NonNull BaseInputOutput io) {
142
        return find(io) != null;
146
        return ExtrasHelper.isSupported(io, BaseIOColors.Provider.class);
143
    }
147
    }
144
148
145
    /**
149
    /**
146
     * Gets current color for output
150
     * SPI for implementing support for output coloring.
147
     * @param type output type to get color for
151
     *
148
     * @return current color for specified output
152
     * @see BaseIOColors
149
     */
153
     */
150
    abstract protected Color getColor(OutputType type);
154
    public interface Provider {
151
155
152
    /**
156
        /**
153
     * Sets specified color for output
157
         * Gets current color for output.
154
     * @param type output type to set color for
158
         *
155
     * @param color new color for specified output type
159
         * @param type Output type to get color for.
156
     */
160
         * @return Current color for specified output.
157
    abstract protected void setColor(OutputType type, Color color);
161
         */
162
        @NonNull BaseColor getColor(@NonNull OutputType type);
163
164
        /**
165
         * Sets specified color for output
166
         *
167
         * @param type Output type to set color for.
168
         * @param color New color for specified output type.
169
         */
170
        void setColor(@NonNull OutputType type, @NonNull BaseColor color);
171
    }
158
}
172
}
(-)a/openide.io/src/org/openide/windows/IOFolding.java (-56 / +44 lines)
Lines 39-50 Link Here
39
 *
39
 *
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2013 Sun Microsystems, Inc.
41
 */
41
 */
42
package org.openide.windows;
42
package org.openide.io.base;
43
43
44
import org.netbeans.api.annotations.common.CheckReturnValue;
44
import org.netbeans.api.annotations.common.CheckReturnValue;
45
import org.netbeans.api.annotations.common.NonNull;
45
import org.netbeans.api.annotations.common.NonNull;
46
import org.openide.util.Lookup;
46
import org.openide.util.Lookup;
47
import org.openide.util.Lookup.Provider;
48
import org.openide.util.Parameters;
47
import org.openide.util.Parameters;
49
48
50
/**
49
/**
Lines 53-67 Link Here
53
 * Client usage:
52
 * Client usage:
54
 * </p>
53
 * </p>
55
 * <pre>
54
 * <pre>
56
 *  InputOutput io = ...;
55
 *  BaseInputOutput io = ...;
57
 *  if (!IOFolding.isSupported(io)) {
56
 *  if (!BaseIOFolding.isSupported(io)) {
58
 *    throw new Exception("Folding is not supported");
57
 *    throw new Exception("Folding is not supported");
59
 *  }
58
 *  }
60
 *  io.getOut().println("First Line - start of fold");
59
 *  io.getOut().println("First Line - start of fold");
61
 *  FoldHandle fold = IOFolding.startFold(io, true);
60
 *  BaseFoldHandle fold = BaseIOFolding.startFold(io, true);
62
 *  io.getOut().println("  Fold Content 1");
61
 *  io.getOut().println("  Fold Content 1");
63
 *  io.getOut().println("  The first line of nested fold");
62
 *  io.getOut().println("  The first line of nested fold");
64
 *  FoldHandle nestedFold = fold.startFold(true);
63
 *  BaseFoldHandle nestedFold = fold.startFold(true);
65
 *  io.getOut().println("     Nested fold content 1");
64
 *  io.getOut().println("     Nested fold content 1");
66
 *  nestedFold.finish();
65
 *  nestedFold.finish();
67
 *  io.getOut().println("  Fold Content 2");
66
 *  io.getOut().println("  Fold Content 2");
Lines 69-156 Link Here
69
 *  io.getOut().println("Text outside of the fold.");
68
 *  io.getOut().println("Text outside of the fold.");
70
 * </pre>
69
 * </pre>
71
 * <p>
70
 * <p>
72
 * How to support {@link IOFolding} in own {@link IOProvider} implementation:
71
 * How to support {@link BaseIOFolding} in own {@link BaseIOProvider} implementation:
73
 * </p>
72
 * </p>
74
 * <ul>
73
 * <ul>
75
 * <li> {@link InputOutput} provided by {@link IOProvider} has to implement
74
 * <li> Implement some {@link Provider} of BaseIOFolding</li>
76
 * {@link Provider}</li>
77
 * <li> Extend {@link IOFolding} and implement its abstract methods</li>
78
 * <li> Extend {@link FoldHandleDefinition}</li>
75
 * <li> Extend {@link FoldHandleDefinition}</li>
79
 * <li> Place instance of {@link IOFolding} to {@link Lookup} provided by
76
 * <li> Place instance of {@link Provider} to {@link Lookup} provided by
80
 * {@link InputOutput}</li>
77
 * {@link BaseInputOutput}</li>
81
 * </ul>
78
 * </ul>
82
 *
79
 *
83
 * @author jhavlin
80
 * @author jhavlin
84
 * @since openide.io/1.38
81
 * @since openide.io/1.38
85
 */
82
 */
86
public abstract class IOFolding {
83
public final class BaseIOFolding {
84
85
    private BaseIOFolding() {}
87
86
88
    /**
87
    /**
89
     * Check whether an {@link InputOutput} supports folding.
88
     * Check whether an {@link BaseInputOutput} supports folding.
90
     *
89
     *
91
     * @param io The InputOutput to check.
90
     * @param io The {@link BaseInputOutput} to check.
92
     * @return True if {@link #startFold(InputOutput, boolean)} can be used with
91
     * @return True if {@link #startFold(BaseInputOutput, boolean)} can be used
93
     * {@code io}, false otherwise.
92
     * with {@code io}, false otherwise.
94
     */
93
     */
95
    public static boolean isSupported(@NonNull InputOutput io) {
94
    public static boolean isSupported(@NonNull BaseInputOutput io) {
96
        Parameters.notNull("parent", io);                               //NOI18N
95
        Parameters.notNull("parent", io);                               //NOI18N
97
        return findIOFolding(io) != null;
96
        return ExtrasHelper.isSupported(io, BaseIOFolding.Provider.class);
98
    }
97
    }
99
98
100
    /**
99
    public interface Provider {
101
     * Find folding support in an {@link InputOutput} object.
100
102
     *
101
        /**
103
     * @return IOFolding object if folding is supported by the {@code parent}
102
         * Create a fold handle definition for the current last line in the
104
     * object, null otherwise.
103
         * output window.
105
     */
104
         *
106
    private static IOFolding findIOFolding(InputOutput parent) {
105
         * @param expanded Initial state of the fold.
107
        return (parent instanceof Lookup.Provider)
106
         * @return FoldHandleDefinition for the fold handle. Never null.
108
                ? ((Lookup.Provider) parent).getLookup().lookup(IOFolding.class)
107
         *
109
                : null;
108
         * @throws IllegalStateException if the last fold hasn't been finished
109
         * yet.
110
         */
111
        @NonNull
112
        FoldHandleDefinition startFold(boolean expanded);
110
    }
113
    }
111
114
112
    /**
115
    /**
113
     * Create a fold handle definition for the current last line in the output
114
     * window.
115
     *
116
     * @param expanded Initial state of the fold.
117
     * @return FoldHandleDefinition for the fold handle. Never null.
118
     *
119
     * @throws IllegalStateException if the last fold hasn't been finished yet.
120
     */
121
    @NonNull
122
    protected abstract FoldHandleDefinition startFold(boolean expanded);
123
124
    /**
125
     * Create a fold handle for the current last line in the output window.
116
     * Create a fold handle for the current last line in the output window.
126
     *
117
     *
127
     * @param io InputOutput to create the fold in.
118
     * @param io {@link BaseInputOutput} to create the fold in.
128
     * @param expanded Initial state of the fold.
119
     * @param expanded Initial state of the fold.
129
     * @return The fold handle that can be used to finish the fold or to create
120
     * @return The fold handle that can be used to finish the fold or to create
130
     * nested folds.
121
     * nested folds.
131
     * @throws IllegalStateException if the last fold hasn't been finished yet.
122
     * @throws IllegalStateException if the last fold hasn't been finished yet.
132
     * @throws UnsupportedOperationException if folding is not supported by the
123
     * @throws UnsupportedOperationException if folding is not supported by the
133
     * InputOutput object.
124
     * {@link BaseInputOutput} object.
134
     */
125
     */
135
    @CheckReturnValue
126
    @CheckReturnValue
136
    @NonNull
127
    @NonNull
137
    public static FoldHandle startFold(
128
    public static BaseFoldHandle startFold(
138
            @NonNull InputOutput io, boolean expanded) {
129
            @NonNull BaseInputOutput io, boolean expanded) {
139
130
140
        Parameters.notNull("io", io);                                   //NOI18N
131
        Parameters.notNull("io", io);                                   //NOI18N
141
        IOFolding folding = findIOFolding(io);
132
        BaseIOFolding.Provider folding = ExtrasHelper.getExtras(io,
142
        if (folding == null) {
133
                BaseIOFolding.Provider.class);
143
            throw new UnsupportedOperationException(
134
144
                    "The InputOutput doesn't support folding");         //NOI18N
135
        return new BaseFoldHandle(folding.startFold(expanded));
145
        } else {
146
            return new FoldHandle(folding.startFold(expanded));
147
        }
148
    }
136
    }
149
137
150
    /**
138
    /**
151
     * An SPI for creating custom FoldHandle implementations.
139
     * An SPI for creating custom FoldHandle implementations.
152
     */
140
     */
153
    protected static abstract class FoldHandleDefinition {
141
    public interface FoldHandleDefinition {
154
142
155
        /**
143
        /**
156
         * Finish the fold at the current last line. Ensure that nested folds
144
         * Finish the fold at the current last line. Ensure that nested folds
Lines 159-165 Link Here
159
         * @throws IllegalStateException if parent fold has been already
147
         * @throws IllegalStateException if parent fold has been already
160
         * finished, or if there is an unfinished nested fold.
148
         * finished, or if there is an unfinished nested fold.
161
         */
149
         */
162
        public abstract void finish();
150
        public void finish();
163
151
164
        /**
152
        /**
165
         * Start a new fold at the current last line. Ensure that the parent
153
         * Start a new fold at the current last line. Ensure that the parent
Lines 171-177 Link Here
171
         * @throws IllegalStateException if the fold has been already finished,
159
         * @throws IllegalStateException if the fold has been already finished,
172
         * or if the last nested fold hasn't been finished yet.
160
         * or if the last nested fold hasn't been finished yet.
173
         */
161
         */
174
        public abstract FoldHandleDefinition startFold(boolean expanded);
162
        public FoldHandleDefinition startFold(boolean expanded);
175
163
176
        /**
164
        /**
177
         * Set state of the fold.
165
         * Set state of the fold.
Lines 180-185 Link Here
180
         *
168
         *
181
         * @param expanded True to expand the fold, false to collapse it.
169
         * @param expanded True to expand the fold, false to collapse it.
182
         */
170
         */
183
        public abstract void setExpanded(boolean expanded);
171
        public void setExpanded(boolean expanded);
184
    }
172
    }
185
}
173
}
(-)a/openide.io.base/src/org/openide/io/base/BaseIOHyperlink.java (+201 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2014 Sun Microsystems, Inc.
41
 */
42
package org.openide.io.base;
43
44
import java.io.IOException;
45
import org.netbeans.api.annotations.common.NonNull;
46
import org.openide.util.Lookup;
47
48
/**
49
 * Text printing with listeners, tags, or custom extension types.
50
 *
51
 * <p>
52
 * Client usage:
53
 * </p>
54
 * <pre>
55
  BaseInputOutput io = ...;
56
  BaseOutputListener l = ...;
57
  BaseOutputTag t = ...;
58
59
  // check only one extension type
60
  if (BaseIOHyperlink.isSupported(io, BaseOutputListener.class) {
61
    BaseIOHyperlink.println(io, "Link", false, l);
62
  }
63
64
  // to print a single line with several extensions
65
  if (BaseIOHyperlink.isSupported(io)) { //check extensions supported at all
66
    List&ltObject&gt exts = new LinkedList&lt;Object&gt;();
67
    if (BaseIOHyperlink.isSupported(io, BaseOutputListener.class)) {
68
      exts.add(new MyOutputListener());
69
    }
70
    if (BaseIOHyperlink.isSupported(io, BaseOutputTag.class)) {
71
      exts.add(new MyOutputTag());
72
    }
73
    BaseIOHyperlink.println(io, "Link 2", false, exts.toArray(new Object[exts.size()]));
74
  }
75
76
 </pre>
77
 * How to support {@link BaseIOHyperlink} in own {@link BaseIOProvider} implementation:
78
 * <ul>
79
 *   <li> Implement some {@link Provider} of BaseIOHyperlink.</li>
80
 *   <li> Place instance of {@link Provider} to {@link Lookup} provided by {@link BaseInputOutput}.</li>
81
 * </ul>
82
 *
83
 * @author Jaroslav Havlin
84
 */
85
public final class BaseIOHyperlink {
86
87
    private BaseIOHyperlink() {}
88
89
    public enum Type {
90
91
        OUT, ERR;
92
    }
93
94
    /**
95
     * Check whether BaseIOHyperlink extension is supported by the I/O.
96
     *
97
     * @param io The I/O to check for support of BaseIOHyperlink.
98
     * @return True if BaseIOHyperlink is supported by the I/O, false otherwise.
99
     */
100
    public static boolean isSupported(@NonNull BaseInputOutput io) {
101
        return ExtrasHelper.isSupported(io, BaseIOHyperlink.Provider.class);
102
    }
103
104
    /**
105
     * Print a line which will be displayed as a hyperlink, calling the action
106
     * specified in the array object if it is clicked.
107
     *
108
     * @param io I/O to print into.
109
     * @param type Type of output, standard or error.
110
     * @param str a string to print to the tab
111
     * @param important mark the line as important. Makes the UI respond
112
     * appropriately, eg. stop the automatic scrolling or highlight the
113
     * hyperlink.
114
     * @param linkInfo array containing extending info for the text, e.g.
115
     * an output listener and/or an output tag.
116
     * @throws IOException if the string could not be printed
117
     * @throws IllegalArgumentException if the I/O does not support this feature.
118
     */
119
    public static void println(
120
            @NonNull BaseInputOutput io,
121
            @NonNull Type type,
122
            @NonNull String str,
123
            boolean important,
124
            @NonNull BaseIOLinkInfo... linkInfo) throws IOException {
125
        ExtrasHelper.getExtras(io, BaseIOHyperlink.Provider.class).println(
126
                type, str, important, linkInfo);
127
    }
128
129
    /**
130
     * Print a line which will be displayed as a hyperlink, calling the action
131
     * specifided in the {@link Lookup} object if it is clicked, if the caret
132
     * enters it, or if the enter key is pressed over it.
133
     *
134
     * @param io I/O to print into.
135
     * @param type Type of output, standard or error.
136
     * @param str a string to print to the tab
137
     * @param linkInfo array containing extending info for the text, e.g.
138
     * an output listener and/or an output tag.
139
     * @throws IOException if the string could not be printed
140
     * @throws IllegalArgumentException if the I/O does not support this feature.
141
     */
142
    public static void println(
143
            @NonNull BaseInputOutput io,
144
            @NonNull Type type,
145
            @NonNull String str,
146
            @NonNull BaseIOLinkInfo... linkInfo) throws IOException {
147
        println(io, type, str, false, linkInfo);
148
    }
149
150
    /**
151
     * Check whether BaseIOHyperlink is supported by the I/O and that its lines
152
     * can be extended with link info of class {@code cls}.
153
     *
154
     * @param io I/O object to get extending types from.
155
     * @param cls The link info class that we want to check the support for.
156
     * @return True if the I/O supports {@link BaseIOHyperlink} and if it can be
157
     * extended with instances of class {@code cls}.
158
     */
159
    public static boolean isSupported(
160
            @NonNull BaseInputOutput io,
161
            @NonNull Class<? extends BaseIOLinkInfo> cls) {
162
        Provider p = ExtrasHelper.find(io, Provider.class);
163
        return p == null
164
                ? false
165
                : p.isSupported(cls);
166
    }
167
168
    /**
169
     * SPI for implementing support for {@link BaseIOHyperlink}.
170
     */
171
    public interface Provider {
172
173
        /**
174
         * Check whether passed class or interface is supported by this
175
         * implementation of BaseOutputWriter and can be put to the array passed
176
         * to
177
         * {@link #println(BaseIOHyperlink.Type, String, boolean, BaseIOLinkInfo...)}.
178
         *
179
         * @param cls Class or interface to check
180
         * @return True if class or interface {@code cls} is supported.
181
         */
182
        boolean isSupported(@NonNull Class<? extends BaseIOLinkInfo> cls);
183
184
        /**
185
         * Print a line which will be displayed as a hyperlink, calling the
186
         * action specifided in the array object if it is clicked.
187
         *
188
         * @param type Type of the output, {@link Type#OUT} for standard output,
189
         * {@link Type#ERR} for error output.
190
         * @param s a string to print to the tab
191
         * @param linkInfo array containing extending info for the text,
192
         * e.g. an output listener and/or an output tag.
193
         * @param important mark the line as important. Makes the UI respond
194
         * appropriately, eg. stop the automatic scrolling or highlight the
195
         * hyperlink.
196
         * @throws IOException if the string could not be printed.
197
         */
198
        void println(@NonNull Type type, @NonNull String s, boolean important,
199
                @NonNull BaseIOLinkInfo... linkInfo) throws IOException;
200
    }
201
}
(-)a/openide.io.base/src/org/openide/io/base/BaseIOLinkInfo.java (+51 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2014 Sun Microsystems, Inc.
41
 */
42
package org.openide.io.base;
43
44
/**
45
 * Marker interface for classes that can be used as extending link info for
46
 * {@link BaseIOHyperlink}.
47
 *
48
 * @author jhavlin
49
 */
50
public interface BaseIOLinkInfo {
51
}
(-)a/openide.io/src/org/openide/windows/IOPosition.java (-34 / +37 lines)
Lines 40-79 Link Here
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
41
 */
41
 */
42
42
43
package org.openide.windows;
43
package org.openide.io.base;
44
44
45
import org.netbeans.api.annotations.common.CheckForNull;
46
import org.netbeans.api.annotations.common.NonNull;
45
import org.openide.util.Lookup;
47
import org.openide.util.Lookup;
46
48
47
/**
49
/**
48
 * Navigation (scrolling) in IO component.
50
 * Navigation (scrolling) in IO component.
49
  * <p>
51
 * <p>
50
 * Client usage:
52
 * Client usage:
53
 * </p>
51
 * <pre>
54
 * <pre>
52
 *  InputOutput io = ...;
55
 BaseInputOutput io = ...;
53
 *  // store current position of IO
56
 // store current position of IO
54
 *  IOPosition.Position pos = IOPosition.currentPosition(io);
57
 Position pos = BaseIOPosition.currentPosition(io);
55
 *  ...
58
 ...
56
 *  // scroll to stored position
59
 // scroll to stored position
57
 *  pos.scrollTo();
60
 pos.scrollTo();
58
 * </pre>
61
 </pre> How to support {@link BaseIOPosition} in own {@link BaseIOProvider}
59
 * How to support {@link IOPosition} in own {@link IOProvider} implementation:
62
 * implementation:
60
 * <ul>
63
 * <ul>
61
 *   <li> {@link InputOutput} provided by {@link IOProvider} has to implement {@link org.openide.util.Lookup.Provider}
64
 * <li> Implement {@link Provider} and implement its methods.
62
 *   <li> Extend {@link IOPosition} and implement its abstract methods
65
 * <li> Place instance of {@link Provider} to {@link Lookup} provided by
63
 *   <li> Place instance of {@link IOPosition} to {@link Lookup} provided by {@link InputOutput}
66
 * {@link BaseInputOutput}
64
 * </ul>
67
 * </ul>
65
 * @since 1.16
68
 *
66
 * @author Tomas Holy
69
 * @author Tomas Holy, Jaroslav Havlin
67
 */
70
 */
68
public abstract class IOPosition {
71
public final class BaseIOPosition {
69
72
70
    private static IOPosition find(InputOutput io) {
73
    private BaseIOPosition() {}
71
        if (io instanceof Lookup.Provider) {
72
            Lookup.Provider p = (Lookup.Provider) io;
73
            return p.getLookup().lookup(IOPosition.class);
74
        }
75
        return null;
76
    }
77
74
78
    public interface Position {
75
    public interface Position {
79
        void scrollTo();
76
        void scrollTo();
Lines 81-91 Link Here
81
78
82
    /**
79
    /**
83
     * Gets current position (in number of chars) in IO
80
     * Gets current position (in number of chars) in IO
84
     * @param io IO to operate on
81
     * @param io IO to operate on.
85
     * @return current position or null if not supported
82
     * @return Current position or null if not supported.
86
     */
83
     */
87
    public static Position currentPosition(InputOutput io) {
84
    public static @CheckForNull Position currentPosition(
88
        IOPosition iop = find(io);
85
            @NonNull BaseInputOutput io) {
86
87
        Provider iop = ExtrasHelper.find(io, Provider.class);
89
        return iop != null ? iop.currentPosition() : null;
88
        return iop != null ? iop.currentPosition() : null;
90
    }
89
    }
91
90
Lines 94-106 Link Here
94
     * @param io IO to check on
93
     * @param io IO to check on
95
     * @return true if supported
94
     * @return true if supported
96
     */
95
     */
97
    public static boolean isSupported(InputOutput io) {
96
    public static boolean isSupported(BaseInputOutput io) {
98
        return find(io) != null;
97
        return ExtrasHelper.isSupported(io, Provider.class);
99
    }
98
    }
100
99
101
    /**
100
    public interface Provider {
102
     * Gets current position in IO
101
103
     * @return current position
102
        /**
104
     */
103
         * Gets current position in IO
105
    abstract protected Position currentPosition();
104
         *
105
         * @return current position
106
         */
107
        Position currentPosition();
108
    }
106
}
109
}
(-)a/openide.io.base/src/org/openide/io/base/BaseIOProvider.java (+333 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2014 Sun Microsystems, Inc.
41
 */
42
package org.openide.io.base;
43
44
import java.io.BufferedReader;
45
import java.io.IOException;
46
import java.io.InputStreamReader;
47
import java.io.PrintStream;
48
import java.io.PrintWriter;
49
import java.io.Reader;
50
import java.io.StringWriter;
51
import java.util.Collection;
52
import java.util.EventListener;
53
import org.netbeans.api.annotations.common.NonNull;
54
import org.netbeans.api.annotations.common.NullAllowed;
55
import org.openide.util.Lookup;
56
57
/**
58
 * A factory for IO tabs. To create a new tab to write to, call e.g.
59
 * <code>BaseIOProvider.getDefault().getIO("MyTab", false)</code> (pass true if
60
 * there may be an existing tab with the same name and you want to write to a
61
 * new tab).
62
 *
63
 * @author jhavlin
64
 */
65
public abstract class BaseIOProvider {
66
67
    public static @NonNull BaseIOProvider getDefault() {
68
        BaseIOProvider iopb = Lookup.getDefault().lookup(BaseIOProvider.class);
69
        if (iopb == null) {
70
            iopb = new Trivial();
71
        }
72
        return iopb;
73
    }
74
75
    /**
76
     * Gets BaseIOProvider of selected name or delegates to getDefault() if none
77
     * was found.
78
     *
79
     * @param name ID of provider.
80
     * @return The instance corresponding to provided name or default instance
81
     * if not found.
82
     */
83
    public static @NonNull BaseIOProvider get(@NonNull String name) {
84
        Collection<? extends BaseIOProvider> res = Lookup.getDefault().lookupAll(
85
                BaseIOProvider.class);
86
        for (BaseIOProvider iop : res) {
87
            if (iop.getName().equals(name)) {
88
                return iop;
89
            }
90
        }
91
        return getDefault();
92
    }
93
94
    /**
95
     * Gets name (ID) of provider
96
     *
97
     * @return name of provider
98
     */
99
    public abstract @NonNull String getName();
100
101
    /**
102
     * Get a named instance of {@link BaseInputOutput}, which represents an
103
     * output tab in the output window. Streams for reading/writing can be
104
     * accessed via getters on the returned instance.
105
     *
106
     * @param name A localised display name for the tab.
107
     * @param newIO If <tt>true</tt>, a new {@link BaseInputOutput} is returned,
108
     * else an existing {@link BaseInputOutput} of the same name may be
109
     * returned.
110
     * @param context Various context objects that may be required by specific
111
     * implementations of the provider.
112
     * @param actions Objects that specify actions available in the I/O tab,
113
     * usually {@link javax.swing.Action} instances, possibly
114
     * {@link BaseOutputTag} instances, depending on what the BaseIOProvider
115
     * supports.
116
     * @return An {@link BaseInputOutput} instance for accessing the new tab.
117
     * @see BaseInputOutput
118
     */
119
    public abstract @NonNull
120
    BaseInputOutput getIO(
121
            @NonNull String name, boolean newIO,
122
            @NullAllowed Lookup context, EventListener... actions);
123
124
    /**
125
     * Check whether this implementation supports action type {@code cls}.
126
     *
127
     * @param cls Action type to check the support for.
128
     *
129
     * @return True if the passed type can be used for specifying actions for
130
     * the output tab, false if the passed type is not supported.
131
     *
132
     * @see #getIO(java.lang.String, boolean, java.util.EventListener...)
133
     */
134
    public abstract boolean isActionTypeSupported(
135
            @NonNull Class<? extends EventListener> cls);
136
137
    /**
138
     * Fallback implementation.
139
     */
140
    private static final class Trivial extends BaseIOProvider {
141
142
        private static final Reader in = new BufferedReader(
143
                new InputStreamReader(System.in));
144
        private static final PrintStream out = System.out;
145
        private static final PrintStream err = System.err;
146
147
        public Trivial() {
148
        }
149
150
        @Override
151
        public String getName() {
152
            return "Trivial";                                           //NOI18N
153
        }
154
155
        @Override
156
        public BaseInputOutput getIO(String name, boolean newIO,
157
                Lookup context, EventListener... actions) {
158
            return new TrivialIO(name);
159
        }
160
161
        @Override
162
        public boolean isActionTypeSupported(
163
                Class<? extends EventListener> cls) {
164
            return false;
165
        }
166
167
        @SuppressWarnings("deprecation")
168
        private final class TrivialIO implements BaseInputOutput {
169
170
            private final String name;
171
172
            public TrivialIO(String name) {
173
                this.name = name;
174
            }
175
176
            @Override
177
            public Reader getIn() {
178
                return in;
179
            }
180
181
            @Override
182
            public PrintWriter getOut() {
183
                return new TrivialOW(out, name);
184
            }
185
186
            @Override
187
            public PrintWriter getErr() {
188
                return new TrivialOW(err, name);
189
            }
190
191
            public Reader flushReader() {
192
                return getIn();
193
            }
194
195
            @Override
196
            public boolean isClosed() {
197
                return false;
198
            }
199
200
            @Override
201
            public void closeInputOutput() {
202
            }
203
204
            @Override
205
            public void reset() {
206
            }
207
208
            @Override
209
            public Lookup getLookup() {
210
                return Lookup.EMPTY;
211
            }
212
        }
213
214
        private static final class TrivialOW extends PrintWriter {
215
216
            private static int count = 0;
217
            private final String name;
218
            private final PrintStream stream;
219
220
            @SuppressWarnings("ValueOfIncrementOrDecrementUsed")
221
            public TrivialOW(PrintStream stream, String name) {
222
                // XXX using super(new PrintWriter(stream)) does not seem to work for some reason!
223
                super(new StringWriter());
224
                this.stream = stream;
225
                if (name != null) {
226
                    this.name = name;
227
                } else {
228
                    this.name = "anon-" + ++count; // NOI18N
229
                }
230
            }
231
232
            private void prefix(boolean hyperlink) {
233
                if (hyperlink) {
234
                    stream.print("[" + name + "]* "); // NOI18N
235
                } else {
236
                    stream.print("[" + name + "]  "); // NOI18N
237
                }
238
            }
239
240
            @Override
241
            public void println(float x) {
242
                prefix(false);
243
                stream.println(x);
244
            }
245
246
            @Override
247
            public void println(double x) {
248
                prefix(false);
249
                stream.println(x);
250
            }
251
252
            @Override
253
            public void println() {
254
                prefix(false);
255
                stream.println();
256
            }
257
258
            @Override
259
            public void println(Object x) {
260
                prefix(false);
261
                stream.println(x);
262
            }
263
264
            @Override
265
            public void println(int x) {
266
                prefix(false);
267
                stream.println(x);
268
            }
269
270
            @Override
271
            public void println(char x) {
272
                prefix(false);
273
                stream.println(x);
274
            }
275
276
            @Override
277
            public void println(long x) {
278
                prefix(false);
279
                stream.println(x);
280
            }
281
282
            @Override
283
            @SuppressWarnings("ImplicitArrayToString")
284
            public void println(char[] x) {
285
                prefix(false);
286
                stream.println(x);
287
            }
288
289
            @Override
290
            public void println(boolean x) {
291
                prefix(false);
292
                stream.println(x);
293
            }
294
295
            @Override
296
            public void println(String x) {
297
                prefix(false);
298
                stream.println(x);
299
            }
300
301
            @Override
302
            public void write(int c) {
303
                stream.write(c);
304
            }
305
306
            @Override
307
            public void write(char[] buf, int off, int len) {
308
                String s = new String(buf, off, len);
309
                if (s.endsWith("\n")) {
310
                    println(s.substring(0, s.length() - 1));
311
                } else {
312
                    try {
313
                        stream.write(s.getBytes());
314
                    } catch (IOException x) {
315
                    }
316
                }
317
            }
318
319
            @Override
320
            public void write(String s, int off, int len) {
321
                String sub = s.substring(off, off + len);
322
                if (sub.endsWith("\n")) {
323
                    println(sub.substring(0, sub.length() - 1));
324
                } else {
325
                    try {
326
                        stream.write(sub.getBytes());
327
                    } catch (IOException x) {
328
                    }
329
                }
330
            }
331
        }
332
    }
333
}
(-)a/openide.io/src/org/openide/windows/IOSelect.java (-42 / +42 lines)
Lines 40-113 Link Here
40
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
41
 */
41
 */
42
42
43
package org.openide.windows;
43
package org.openide.io.base;
44
44
45
import java.util.Set;
45
import java.util.Set;
46
import org.openide.util.Lookup;
46
import org.netbeans.api.annotations.common.NonNull;
47
import org.openide.util.Parameters;
47
import org.openide.util.Parameters;
48
48
49
/**
49
/**
50
 * Capability of an InputOutput of finer grained selection of a component.
50
 * Capability of an {@link BaseInputOutput} of fine grained selection of a
51
 * <p>
51
 * component.
52
 * InputOutput.select() does too much.
52
 *
53
 * @author ivan
53
 * @author ivan, Jaroslav Havlin
54
 * @since 1.23
55
 */
54
 */
56
public abstract class IOSelect {
55
public final class BaseIOSelect {
56
57
    private BaseIOSelect() {}
57
58
58
    /**
59
    /**
59
     * Additional operations to perform when issuing {@link IOSelect#select}.
60
     * Additional operations to perform when selecting the output tab.
60
     * @author ivan
61
     * @author ivan
61
     */
62
     */
62
    public static enum AdditionalOperation {
63
    public static enum AdditionalOperation {
63
	/**
64
        /**
64
	 * Additionally issue open() on the TopComponent containing the InputOutput.
65
         * Additionally issue open() on the TopComponent containing the
65
	 */
66
         * {@link BaseInputOutput}.
67
         */
66
	OPEN,
68
	OPEN,
67
69
68
	/**
70
	/**
69
	 * Additionally issue requestVisible() on the TopComponent containing the InputOutput.
71
	 * Additionally issue requestVisible() on the TopComponent containing
72
         * the {@link BaseInputOutput}.
70
	 */
73
	 */
71
	REQUEST_VISIBLE,
74
	REQUEST_VISIBLE,
72
75
73
	/**
76
	/**
74
	 * Additionally issue requestActive() on the TopComponent containing the InputOutput.
77
	 * Additionally issue requestActive() on the TopComponent containing
78
         * the {@link BaseInputOutput}.
75
	 */
79
	 */
76
	REQUEST_ACTIVE
80
	REQUEST_ACTIVE
77
    }
81
    }
78
82
79
    private static IOSelect find(InputOutput io) {
80
        if (io instanceof Lookup.Provider) {
81
            Lookup.Provider p = (Lookup.Provider) io;
82
            return p.getLookup().lookup(IOSelect.class);
83
        }
84
        return null;
85
    }
86
87
    /**
83
    /**
88
     * With an empty 'extraOps' simply selects this io
84
     * With an empty 'extraOps' simply selects this io
89
     * without involving it's containing TopComponent.
85
     * without involving it's containing TopComponent.
90
     * <p>
86
     * <p>
91
     * For example:
87
     * For example:
88
     * </p>
92
     * <pre>
89
     * <pre>
93
     * if (IOSelect.isSupported(io) {
90
     * if (BaseIOSelect.isSupported(io) {
94
     *     IOSelect.select(io, EnumSet.noneOf(IOSelect.AdditionalOperation.class));
91
     *     BaseIOSelect.select(io, EnumSet.noneOf(IOSelect.AdditionalOperation.class));
95
     * }
92
     * }
96
     * </pre>
93
     * </pre>
97
     * <p>
94
     * <p>
98
     * If this capability is not supported then regular InputOutput.select()
95
     * If this capability is not supported then no operation will be performed.
99
     * will be called.
96
     * </p>
100
     * @param io InputOutput to operate on.
97
     * @param io {@link BaseInputOutput} to operate on.
101
     * @param extraOps Additional operations to apply to the containing
98
     * @param extraOps Additional operations to apply to the containing
102
     * TopComponent.
99
     * TopComponent.
103
     */
100
     */
104
    public static void select(InputOutput io, Set<AdditionalOperation> extraOps) {
101
    public static void select(BaseInputOutput io, Set<AdditionalOperation> extraOps) {
105
	Parameters.notNull("extraOps", extraOps);	// NOI18N
102
	Parameters.notNull("extraOps", extraOps);	// NOI18N
106
	IOSelect ios = find(io);
103
	Provider ios = ExtrasHelper.find(io, Provider.class);
107
	if (ios != null)
104
	if (ios != null) {
108
	    ios.select(extraOps);
105
            ios.select(extraOps);
109
	else
106
        }
110
	    io.select();	// fallback
111
    }
107
    }
112
108
113
    /**
109
    /**
Lines 115-129 Link Here
115
     * @param io IO to check on
111
     * @param io IO to check on
116
     * @return true if supported
112
     * @return true if supported
117
     */
113
     */
118
    public static boolean isSupported(InputOutput io) {
114
    public static boolean isSupported(BaseInputOutput io) {
119
        return find(io) != null;
115
        return ExtrasHelper.isSupported(io, Provider.class);
120
    }
116
    }
121
117
122
    /**
118
    public interface Provider {
123
     * With an empty 'extraOps' simply selects this io
119
124
     * without involving it's containing TopComponent.
120
        /**
125
     * @param extraOps Additional operations to apply to the containing
121
         * With an empty 'extraOps' simply selects this io without involving
126
     * TopComponent.
122
         * it's containing TopComponent.
127
     */
123
         *
128
    abstract protected void select(Set<AdditionalOperation> extraOps);
124
         * @param extraOps Additional operations to apply to the containing
125
         * TopComponent.
126
         */
127
        void select(@NonNull Set<AdditionalOperation> extraOps);
128
    }
129
}
129
}
(-)a/openide.io/src/org/openide/windows/IOTab.java (-73 / +43 lines)
Lines 40-48 Link Here
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
41
 */
41
 */
42
42
43
package org.openide.windows;
43
package org.openide.io.base;
44
44
45
import javax.swing.Icon;
45
import org.netbeans.api.annotations.common.CheckForNull;
46
import org.netbeans.api.annotations.common.NonNull;
47
import org.netbeans.api.annotations.common.NullAllowed;
46
import org.openide.util.Lookup;
48
import org.openide.util.Lookup;
47
49
48
/**
50
/**
Lines 51-118 Link Here
51
 * Client usage:
53
 * Client usage:
52
 * <pre>
54
 * <pre>
53
 *  // settings of IO tab icon, tooltip
55
 *  // settings of IO tab icon, tooltip
54
 *  InputOutput io = ...;
56
 *  BaseInputOutput io = ...;
55
 *  Icon icon = ...;
57
 *  BaseIOTab.setToolTipText(io, "text");
56
 *  IOTab.setIcon(io, icon);
57
 *  IOTab.setToolTipText(io, "text");
58
 * </pre>
58
 * </pre>
59
 * How to support {@link IOTab} in own {@link IOProvider} implementation:
59
 * How to support {@link BaseIOTab} in own {@link BaseIOProvider} implementation:
60
 * <ul>
60
 * <ul>
61
 *   <li> {@link InputOutput} provided by {@link IOProvider} has to implement {@link org.openide.util.Lookup.Provider}
61
 *   <li> Implement {@link Provider}.</li>
62
 *   <li> Extend {@link IOTab} and implement its abstract methods
62
 *   <li> Place instance of {@link Provider} to {@link Lookup} provided by {@link BaseInputOutput}.</li>
63
 *   <li> Place instance of {@link IOTab} to {@link Lookup} provided by {@link InputOutput}
64
 * </ul>
63
 * </ul>
65
 * @since 1.15
64
 * @author Tomas Holy, Jaroslav Havlin
66
 * @author Tomas Holy
67
 */
65
 */
68
public abstract class IOTab {
66
public final class BaseIOTab {
69
    private static IOTab find(InputOutput io) {
70
        if (io instanceof Lookup.Provider) {
71
            Lookup.Provider p = (Lookup.Provider) io;
72
            return p.getLookup().lookup(IOTab.class);
73
        }
74
        return null;
75
    }
76
67
77
    /**
68
    private BaseIOTab() {}
78
     * Gets current tab icon for specified IO
79
     * @param io IO to operate on
80
     * @return current tab icon or null if not supported
81
     */
82
    public static Icon getIcon(InputOutput io) {
83
        IOTab iot = find(io);
84
        return iot != null ? iot.getIcon() : null;
85
    }
86
87
    /**
88
     * Sets icon to tab corresponding to specified IO
89
     * @param io IO to operate on
90
     * @param icon tab icon
91
     */
92
    public static void setIcon(InputOutput io, Icon icon) {
93
        IOTab iot = find(io);
94
        if (iot != null) {
95
            iot.setIcon(icon);
96
        }
97
    }
98
69
99
    /**
70
    /**
100
     * Gets current tool tip text for specified IO
71
     * Gets current tool tip text for specified IO
101
     * @param io IO to operate on
72
     * @param io IO to operate on.
102
     * @return current tool tip text or null if not supported
73
     * @return Current tool tip text or null if not supported.
103
     */
74
     */
104
    public static String getToolTipText(InputOutput io) {
75
    public static @CheckForNull String getToolTipText(
105
        IOTab iot = find(io);
76
            @NonNull BaseInputOutput io) {
77
78
        Provider iot = ExtrasHelper.find(io, Provider.class);
106
        return iot != null ? iot.getToolTipText() : null;
79
        return iot != null ? iot.getToolTipText() : null;
107
    }
80
    }
108
81
109
    /**
82
    /**
110
     * Sets tool tip text to tab corresponding to specified IO
83
     * Sets tool tip text to tab corresponding to specified IO
111
     * @param io IO to operate on
84
     * @param io IO to operate on.
112
     * @param text new tool tip text
85
     * @param text New tool tip text.
113
     */
86
     */
114
    public static void setToolTipText(InputOutput io, String text) {
87
    public static void setToolTipText(
115
        IOTab iot = find(io);
88
            @NonNull BaseInputOutput io,
89
            @NullAllowed String text) {
90
        Provider iot = ExtrasHelper.find(io, Provider.class);
116
        if (iot != null) {
91
        if (iot != null) {
117
            iot.setToolTipText(text);
92
            iot.setToolTipText(text);
118
        }
93
        }
Lines 120-154 Link Here
120
95
121
    /**
96
    /**
122
     * Checks whether this feature is supported for provided IO
97
     * Checks whether this feature is supported for provided IO
123
     * @param io IO to check on
98
     * @param io IO to check on.
124
     * @return true if supported
99
     * @return True if supported.
125
     */
100
     */
126
    public static boolean isSupported(InputOutput io) {
101
    public static boolean isSupported(BaseInputOutput io) {
127
        return find(io) != null;
102
        return ExtrasHelper.isSupported(io, Provider.class);
128
    }
103
    }
129
104
130
    /**
105
    /**
131
     * Gets current tab icon
106
     * SPI for implementation of {@link BaseIOTab} support.
132
     * @return current tab icon
133
     */
107
     */
134
    abstract protected Icon getIcon();
108
    public interface Provider {
135
109
110
        /**
111
         * Gets current tool tip text.
112
         *
113
         * @return Current tool tip text.
114
         */
115
        @CheckForNull String getToolTipText();
136
116
137
    /**
117
        /**
138
     * Sets icon to tab
118
         * Sets tool tip text to tab.
139
     * @param icon tab icon
119
         *
140
     */
120
         * @param text New tool tip text.
141
    abstract protected void setIcon(Icon icon);
121
         */
142
122
        void setToolTipText(@NullAllowed String text);
143
    /**
123
    }
144
     * Gets current tool tip text
145
     * @return current tool tip text
146
     */
147
    abstract protected String getToolTipText();
148
149
    /**
150
     * Sets tool tip text to tab
151
     * @param text new tool tip text
152
     */
153
    abstract protected void setToolTipText(String text);
154
}
124
}
(-)a/openide.io.base/src/org/openide/io/base/BaseInputOutput.java (+112 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2014 Sun Microsystems, Inc.
41
 */
42
package org.openide.io.base;
43
44
import java.io.IOException;
45
import java.io.PrintWriter;
46
import java.io.Reader;
47
import org.openide.util.Lookup;
48
49
/**
50
 * An I/O connection to one tab on the Output Window. To acquire an instance to
51
 * write to, call, e.g.,
52
 * <code>BaseIOProvider.getDefault().getIO("someName", false)</code>. To get
53
 * actual streams to write to, call <code>getOut()</code> or <code>
54
 * getErr()</code> on the returned instance.
55
 * <p>
56
 * Generally it is preferable not to hold a reference to an instance of
57
 * {@link org.openide.io.base.BaseInputOutput}, but rather to fetch it by name
58
 * from {@link org.openide.io.base.BaseIOProvider} as needed.
59
 * </p>
60
 *
61
 * @author Ian Formanek, Jaroslav Tulach, Petr Hamernik, Ales Novak, Jan
62
 * Jancura, Jaroslav Havlin
63
 */
64
public interface BaseInputOutput extends Lookup.Provider {
65
66
    /**
67
     * Acquire an output writer to write to the tab. This is the usual use of a
68
     * tab--it writes to the main output pane.
69
     *
70
     * @return the writer
71
     */
72
    public PrintWriter getOut();
73
74
    /**
75
     * Get a reader to read from the tab. If a reader is ever requested, an
76
     * input line is added to the tab and used to read one line at a time.
77
     *
78
     * @return the reader
79
     */
80
    public Reader getIn();
81
82
    /**
83
     * Get an output writer to write to the tab in error mode. This might show
84
     * up in a different color than the regular output, e.g., or appear in a
85
     * separate pane.
86
     *
87
     * @return the writer
88
     */
89
    public PrintWriter getErr();
90
91
    /**
92
     * Closes this tab. The effect of calling any method on an instance of
93
     * {@link BaseInputOutput} after calling {@link #closeInputOutput()} on it
94
     * is undefined.
95
     */
96
    public void closeInputOutput();
97
98
    /**
99
     * Test whether this tab has been closed, either by a call to
100
     * <code>closeInputOutput()</code> or by the user closing the tab in the UI.
101
     *
102
     * @see #closeInputOutput
103
     * @return <code>true</code> if it is closed
104
     */
105
    public boolean isClosed();
106
107
    /**
108
     * Clean the output area.
109
     * @throws java.io.IOException
110
     */
111
    void reset() throws IOException;
112
}
(-)a/openide.io.base/src/org/openide/io/base/BaseOutputEvent.java (+70 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2014 Sun Microsystems, Inc.
41
 */
42
package org.openide.io.base;
43
44
/**
45
 * Event fired when something happens to a line in the Output Window.
46
 *
47
 * @author Jaroslav Tulach, Petr Hamernik, Jaroslav Havlin
48
 */
49
public abstract class BaseOutputEvent extends java.util.EventObject {
50
    /** generated Serialized Version UID */
51
    static final long serialVersionUID = 4809584286971828815L;
52
    /** Create an event.
53
    * @param src the tab in question
54
    */
55
    public BaseOutputEvent (BaseInputOutput src) {
56
        super (src);
57
    }
58
59
    /** Get the text on the line.
60
    * @return the text
61
    */
62
    public abstract String getLine ();
63
64
    /** Get the Output Window tab in question.
65
    * @return the tab
66
    */
67
    public BaseInputOutput getInputOutput() {
68
        return (BaseInputOutput) getSource();
69
    }
70
}
(-)a/openide.io.base/src/org/openide/io/base/BaseOutputListener.java (+59 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2014 Sun Microsystems, Inc.
41
 */
42
package org.openide.io.base;
43
44
/**
45
 * Listener to actions taken on a line in the Output Window.
46
 *
47
 * @author Jaroslav Tulach
48
 * @version 0.11 Dec 01, 1997
49
 */
50
public interface BaseOutputListener extends java.util.EventListener,
51
        BaseIOLinkInfo {
52
53
    /**
54
     * Called when some sort of action is performed on a line.
55
     *
56
     * @param ev the event describing the line
57
     */
58
    void outputLineAction(BaseOutputEvent ev);
59
}
(-)a/openide.io.base/src/org/openide/io/base/BaseOutputTag.java (+77 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2014 Sun Microsystems, Inc.
41
 */
42
package org.openide.io.base;
43
44
import java.util.EventListener;
45
import java.util.Set;
46
47
/**
48
 * Base class for adding tagging information to output text.
49
 *
50
 * @author jhavlin
51
 */
52
public interface BaseOutputTag extends BaseIOLinkInfo, EventListener {
53
54
    /**
55
     * Get type of this tag.
56
     *
57
     * @return Type of the tag.
58
     */
59
    String getType();
60
61
    /**
62
     * Get value of an attribute specified by name.
63
     *
64
     * @param attributeName Name of the attribute.
65
     * @return Value of the attribute, or null if it is not available.
66
     * @throws IllegalArgumentException If tag of this type should not be
67
     * queried for attribute of name {@code  attributeName}.
68
     */
69
    Object getAttribute(String attributeName);
70
71
    /**
72
     * Get set of names of available attributes.
73
     *
74
     * @return Set of attribute names.
75
     */
76
    Set<String> getAttributeNames();
77
}
(-)a/openide.io.base/src/org/openide/io/base/Bundle.properties (+1 lines)
Line 0 Link Here
1
OpenIDE-Module-Name=Base I/O APIs
(-)a/openide.io.base/src/org/openide/io/base/ExtrasHelper.java (+100 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2014 Sun Microsystems, Inc.
41
 */
42
package org.openide.io.base;
43
44
/**
45
 * Helper class for finding extensions in I/O's lookup.
46
 *
47
 * @author jhavlin
48
 */
49
class ExtrasHelper {
50
51
    private ExtrasHelper() {}
52
53
    /**
54
     * Check whether class {@code extras} is present in the I/O's lookup.
55
     *
56
     * @param io I/O to check
57
     * @param extras Extension class that should be supported.
58
     *
59
     * @return True if the I/O supports the extension class, false otherwise.
60
     */
61
    static boolean isSupported(BaseInputOutput io, Class<?> extras) {
62
        Object o = io.getLookup().lookup(extras);
63
        return o != null;
64
    }
65
66
    /**
67
     * Get extension of given type, or throw an exception if it is not present.
68
     *
69
     * @param <T> Type of the extension.
70
     * @param io I/O to get the extension for.
71
     * @param cls Extension class.
72
     *
73
     * @return The extension object of given type.
74
     * @throws IllegalArgumentException If the I/O does not support this
75
     * extension type.
76
     */
77
    static <T> T getExtras(BaseInputOutput io, Class<T> cls) {
78
        T extras = io.getLookup().lookup(cls);
79
        if (extras == null) {
80
            throw new IllegalArgumentException("BaseInputOutput " + io
81
                    + " does not support " + cls);
82
        } else {
83
            return extras;
84
        }
85
    }
86
87
    /**
88
     * Get extension of given type, or return null if it is not present.
89
     *
90
     * @param <T> Type of the extension.
91
     * @param io I/O to get the extension for.
92
     * @param cls Extension class.
93
     *
94
     * @return The extension object of given type, or null if it is not
95
     * supported.
96
     */
97
    static <T> T find(BaseInputOutput io, Class<T> cls) {
98
        return io.getLookup().lookup(cls);
99
    }
100
}

Return to bug 245014