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 247404
Collapse All | Expand All

(-)a/api.io/arch.xml (+1188 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="jhavlin@netbeans.org"
9
>
10
<!-- This file was based on arch.xml file in module openide.io. -->
11
12
  &api-questions;
13
14
15
    <!--
16
            <question id="arch-overall" when="init">
17
                Describe the overall architecture.
18
                <hint>
19
                What will be API for
20
                <a href="http://wiki.netbeans.org/API_Design#Separate_API_for_clients_from_support_API">
21
                    clients and what support API</a>?
22
                What parts will be pluggable?
23
                How will plug-ins be registered? Please use <code>&lt;api type="export"/&gt;</code>
24
                to describe your general APIs and specify their
25
                <a href="http://wiki.netbeans.org/API_Stability#Private">
26
                stability categories</a>.
27
                If possible please provide simple diagrams.
28
                </hint>
29
            </question>
30
    -->
31
    <answer id="arch-overall">
32
        <api
33
            name="NbInputOutputAPI"
34
            group="java"
35
            type="export"
36
            category="official"
37
            url="@org-netbeans-api-io@/org/netbeans/api/io/package-summary.html"
38
        >
39
            <p>
40
                The module contains APIs for creating output panes (e.g. output tabs in Output Window in the IDE)
41
                and for writing data into them. It also supports some advanced techniques, e.g. color text,
42
                hyperlinks, code folding, scrolling to stored positions.
43
            </p>
44
        </api>
45
        <api
46
            name="NbInputOutputSPI"
47
            group="java"
48
            type="export"
49
            category="official"
50
            url="@org-netbeans-api-io@/org/netbeans/spi/io/package-summary.html"
51
        >
52
            <p>
53
                SPI for providing custom implementations of output window is also included in this module, in package
54
                <code>org.netbeans.spi.io</code>
55
            </p>
56
        </api>
57
    </answer>
58
59
60
61
    <!--
62
            <question id="arch-quality" when="init">
63
                How will the <a href="http://www.netbeans.org/community/guidelines/q-evangelism.html">quality</a>
64
                of your code be tested and
65
                how are future regressions going to be prevented?
66
                <hint>
67
                What kind of testing do
68
                you want to use? How much functionality, in which areas,
69
                should be covered by the tests? How you find out that your
70
                project was successful?
71
                </hint>
72
            </question>
73
    -->
74
    <answer id="arch-quality">
75
        <p>
76
            Unit test will be prepared for invocable code in API classes. But most of the
77
            code is just definition of API and SPI.
78
        </p>
79
    </answer>
80
81
82
83
    <!--
84
            <question id="arch-time" when="init">
85
                What are the time estimates of the work?
86
                <hint>
87
                Please express your estimates of how long the design, implementation,
88
                stabilization are likely to last. How many people will be needed to
89
                implement this and what is the expected milestone by which the work should be
90
                ready?
91
                </hint>
92
            </question>
93
    -->
94
    <answer id="arch-time">
95
        <p>
96
            The design, implementation, preparing unit tests and reviews will
97
            probably take several weeks.
98
        </p>
99
    </answer>
100
101
102
103
<!--
104
        <question id="arch-usecases" when="init">
105
            <hint>
106
                Content of this answer will be displayed as part of page at
107
                http://www.netbeans.org/download/dev/javadoc/usecases.html
108
                You can use tags &lt;usecase name="name&gt; regular html description &lt;/usecase&gt;
109
                and if you want to use an URL you can prefix if with @TOP@ to begin
110
                at the root of your javadoc
111
            </hint>
112
113
                Describe the main <a href="http://wiki.netbeans.org/API_Design#The_Importance_of_Being_Use_Case_Oriented">
114
                use cases</a> of the new API. Who will use it under
115
                what circumstances? What kind of code would typically need to be written
116
                to use the module?
117
            </question>
118
    -->
119
    <answer id="arch-usecases">
120
121
        <usecase id="print" name="Print a simple output to a new output tab">
122
            <p>
123
                The basic use-case is printing a simple text, e.g. text output of an application,
124
                into a dedicated pane in the UI, e.g. a tab in Output Window in the IDE.
125
            </p>
126
            <pre>
127
    InputOutput io = InputOutput.get("UseCase1", true);
128
    io.getOut().println("This is a simple output");
129
    io.getOut().close();
130
            </pre>
131
        </usecase>
132
133
        <usecase id="printUriHyperlink" name="Reuse existing tab and print a line containing a hyperlink for a URI">
134
            <p>
135
                Implementations can support hyperlinks. If the hyperlink is defined by a URI,
136
                it will be opened by the UI part of the application when the hyperlink is clicked
137
                in the output window. The following example will open a file and place the cursor
138
                at line and column specified by query part of the URI (after question mark).
139
            </p>
140
            <pre>
141
    InputOutput io = InputOutput.get("UseCase2", false);
142
    io.getOut().print("A line containing a ");
143
    io.getOut().print("hyperlink", Hyperlink.forURI(new URI("file://n:/test/Test.java?line=4&amp;col=2")));
144
    io.getOut().println(" for a URI.");
145
    io.getOut().close();
146
            </pre>
147
        </usecase>
148
149
        <usecase id="printOnClickHyperlink" name="Print a line with hyperlink for invocation of arbitrary code">
150
            <p>
151
                Hyperlinks can be also used to invoke some code when clicked.
152
            </p>
153
            <pre>
154
    InputOutput io = InputOutput.get("UseCase3", true);
155
    io.getOut().print("A line containing a ");
156
    io.getOut().print("hyperlink", Hyperlink.onClick(new Runnable() {
157
        public void run() {
158
            System.gc();
159
        }
160
    }));
161
    io.getOut().println(" for invocation of custom code.");
162
    io.getOut().close();
163
            </pre>
164
        </usecase>
165
166
        <usecase id="printColor" name="Print color text">
167
            <p>
168
                Print a color text. Users can select a predefined color for
169
                common cases (debug, warning, failure, success), or custom
170
                color specified as RGB value.
171
            </p>
172
            <pre>
173
    InputOutput io = InputOutput.get("UseCase4", true);
174
    io.getOut().println("Let's print some info", OutputColor.debug());
175
    io.getOut().println("or warning with appropriate color", OutputColor.warning());
176
    io.getOut().println("Maybe also text with custom reddish color", OutputColor.rgb(255, 16, 16));
177
    io.getOut().close();
178
            </pre>
179
        </usecase>
180
181
        <usecase id="printAndReset" name="Reset an InputOutput to clear all previosly printed text">
182
            <p>
183
                It is possible to reuse already created output pane and clear
184
                all the previously printed text if it is not needed any more.
185
            </p>
186
            <pre>
187
    InputOutput io = InputOutput.get("UseCase5", true);
188
    io.getOut().println("Let's print some text");
189
    io.getErr().println("and reset the pane immediately.");
190
    io.reset();
191
    io.getOut().println("The pane is now empty and we can reuse it simply");
192
    io.getOut().close();
193
            </pre>
194
        </usecase>
195
196
    </answer>
197
198
199
200
    <!--
201
            <question id="arch-what" when="init">
202
                What is this project good for?
203
                <hint>
204
                Please provide here a few lines describing the project, 
205
                what problem it should solve, provide links to documentation, 
206
                specifications, etc.
207
                </hint>
208
            </question>
209
    -->
210
    <answer id="arch-what">
211
        <p>
212
            The Input/Output API and SPI is a small module
213
            which contains <code>InputOutput</code> and related interfaces used in
214
            driving the Output Window.
215
        </p>
216
        <p>
217
            The normal implementation is <code>org.netbeans.core.output2</code>.
218
        </p>
219
    </answer>
220
221
222
223
    <!--
224
            <question id="arch-where" when="impl">
225
                Where one can find sources for your module?
226
                <hint>
227
                    Please provide link to the Hg web client at
228
                    http://hg.netbeans.org/
229
                    or just use tag defaultanswer generate='here'
230
                </hint>
231
            </question>
232
    -->
233
    <answer id="arch-where">
234
        <defaultanswer generate='here' />
235
    </answer>
236
237
238
239
    <!--
240
            <question id="compat-deprecation" when="init">
241
                How the introduction of your project influences functionality
242
                provided by previous version of the product?
243
                <hint>
244
                If you are planning to deprecate/remove/change any existing APIs,
245
                list them here accompanied with the reason explaining why you
246
                are doing so.
247
                </hint>
248
            </question>
249
    -->
250
    <answer id="compat-deprecation">
251
        <p>
252
            Backward compatibility of other modules is not broken.
253
        </p>
254
        <p>
255
            This module should replace original I/O API module
256
            <code>org.openide.io</code>, which has the same goals, but which is
257
            not UI independent, and which is difficult to extend.
258
        </p>
259
    </answer>
260
261
262
263
    <!--
264
            <question id="compat-i18n" when="impl">
265
                Is your module correctly internationalized?
266
                <hint>
267
                Correct internationalization means that it obeys instructions
268
                at <a href="http://www.netbeans.org/download/dev/javadoc/org-openide-modules/org/openide/modules/doc-files/i18n-branding.html">
269
                NetBeans I18N pages</a>.
270
                </hint>
271
            </question>
272
    -->
273
    <answer id="compat-i18n">
274
        <p>
275
            Yes. There is not much to internationalize.
276
        </p>
277
    </answer>
278
279
280
281
    <!--
282
            <question id="compat-standards" when="init">
283
                Does the module implement or define any standards? Is the 
284
                implementation exact or does it deviate somehow?
285
            </question>
286
    -->
287
    <answer id="compat-standards">
288
        <p>
289
            The module defines an API.
290
        </p>
291
    </answer>
292
293
294
295
    <!--
296
        <question id="compat-version" when="impl">
297
            Can your module coexist with earlier and future
298
            versions of itself? Can you correctly read all old settings? Will future
299
            versions be able to read your current settings? Can you read
300
            or politely ignore settings stored by a future version?
301
302
                <hint>
303
                Very helpful for reading settings is to store version number
304
                there, so future versions can decide whether how to read/convert
305
                the settings and older versions can ignore the new ones.
306
                </hint>
307
            </question>
308
    -->
309
    <answer id="compat-version">
310
        <p>
311
            N/A. No settings are read or written by this module.
312
        </p>
313
    </answer>
314
315
316
317
    <!--
318
            <question id="dep-jre" when="final">
319
                Which version of JRE do you need (1.2, 1.3, 1.4, etc.)?
320
                <hint>
321
                It is expected that if your module runs on 1.x that it will run 
322
                on 1.x+1 if no, state that please. Also describe here cases where
323
                you run different code on different versions of JRE and why.
324
                </hint>
325
            </question>
326
    -->
327
    <answer id="dep-jre">
328
        1.7
329
    </answer>
330
331
332
333
    <!--
334
            <question id="dep-jrejdk" when="final">
335
                Do you require the JDK or is the JRE enough?
336
            </question>
337
    -->
338
    <answer id="dep-jrejdk">
339
        JRE
340
    </answer>
341
342
343
344
    <!--
345
            <question id="dep-nb" when="init">
346
                What other NetBeans projects and modules does this one depend on?
347
                <hint>
348
                Depending on other NetBeans projects influnces the ability of
349
                users of your work to customize their own branded version of
350
                NetBeans by enabling and disabling some modules. Too
351
                much dependencies restrict this kind of customization. If that
352
                is your case, then you may want to split your functionality into
353
                pieces of autoload, eager and regular modules which can be
354
                enabled independently. Usually the answer to this question
355
                is generated from your <code>project.xml</code> file, but
356
                if it is not guessed correctly, you can suppress it by
357
                specifying &lt;defaultanswer generate="none"/&gt; and
358
                write here your own. Please describe such projects as imported APIs using
359
                the <code>&lt;api name="identification" type="import or export" category="stable" url="where is the description" /&gt;</code>.
360
                By doing this information gets listed in the summary page of your
361
                javadoc.
362
                </hint>
363
            </question>
364
    -->
365
    <answer id="dep-nb">
366
        <defaultanswer generate='here' />
367
    </answer>
368
369
370
371
<!--
372
        <question id="dep-non-nb" when="init">
373
            What other projects outside NetBeans does this one depend on?
374
375
                <hint>
376
                Depending on 3rd party libraries is always problematic,
377
                especially if they are not open source, as that complicates
378
                the licensing scheme of NetBeans. Please enumerate your
379
                external dependencies here, so it is correctly understood since
380
                the begining what are the legal implications of your project.
381
                Also please note that
382
                some non-NetBeans projects are packaged as NetBeans modules
383
                (see <a href="http://libs.netbeans.org/">libraries</a>) and
384
                it is preferred to use this approach when more modules may
385
                depend and share such third-party libraries.
386
                </hint>
387
            </question>
388
    -->
389
    <answer id="dep-non-nb">
390
        None.
391
    </answer>
392
393
394
395
    <!--
396
            <question id="dep-platform" when="init">
397
                On which platforms does your module run? Does it run in the same
398
                way on each?
399
                <hint>
400
                If you plan any dependency on OS or any usage of native code,
401
                please describe why you are doing so and describe how you envision
402
                to enforce the portability of your code.
403
                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
404
                enabled modules</a> which together with autoload/eager modules
405
                can allow you to enable to provide the best OS aware support
406
                on certain OSes while providing compatibility bridge on the not
407
                supported ones.
408
                Also please list the supported
409
                OSes/HW platforms and mentioned the lovest version of JDK required
410
                for your project to run on. Also state whether JRE is enough or
411
                you really need JDK.
412
                </hint>
413
            </question>
414
    -->
415
    <answer id="dep-platform">
416
        Any.
417
    </answer>
418
419
420
421
    <!--
422
            <question id="deploy-dependencies" when="final">
423
                What do other modules need to do to declare a dependency on this one,
424
                in addition to or instead of the normal module dependency declaration
425
                (e.g. tokens to require)?
426
                <hint>
427
                    Provide a sample of the actual lines you would add to a module manifest
428
                    to declare a dependency, for example OpenIDE-Module-Requires: some.token.
429
                    If other modules should not depend on this module, or should just use a
430
                    simple regular module dependency, you can just answer "nothing". If you
431
                    intentionally expose a semistable API to clients using implementation
432
                    dependencies, you should mention that here (but there is no need to give
433
                    an example of usage).
434
                </hint>
435
            </question>
436
    -->
437
    <answer id="deploy-dependencies">
438
        <p>
439
            Normal module dependency is enough.
440
        </p>
441
        <p>
442
            Availability of some implementation of the SPI is guaranteed by
443
            "OpenIDE-Module-Needs: org.netbeans.spi.io.InputOutputProvider" in
444
            the manifest of this module.
445
        </p>
446
    </answer>
447
448
449
450
    <!--
451
        <question id="deploy-jar" when="impl">
452
            Do you deploy just module JAR file(s) or other files as well?
453
            <hint>
454
            Usually a module consist of one JAR file (perhaps with Class-Path
455
            extensions) and also a configuration file that enables it. If you
456
            have any other files, use
457
            &lt;api group="java.io.File" name="yourname" type="export" category="friend"&gt;...&lt;/api&gt;
458
            to define the location, name and stability of your files (of course
459
            changing "yourname" and "friend" to suit your needs).
460
461
                If it uses more than one JAR, describe where they are located, how
462
                they refer to each other.
463
                If it consist of module JAR(s) and other files, please describe
464
                what is their purpose, why other files are necessary. Please
465
                make sure that installation/uninstallation leaves the system
466
                in state as it was before installation.
467
                </hint>
468
            </question>
469
    -->
470
    <answer id="deploy-jar">
471
        <p>
472
            Just the module JAR.
473
        </p>
474
    </answer>
475
476
477
478
    <!--
479
            <question id="deploy-nbm" when="impl">
480
                Can you deploy an NBM via the Update Center?
481
                <hint>
482
                If not why?
483
                </hint>
484
            </question>
485
    -->
486
    <answer id="deploy-nbm">
487
        <p>
488
            Yes.
489
        </p>
490
    </answer>
491
492
493
494
    <!--
495
        <question id="deploy-packages" when="init">
496
            Are packages of your module made inaccessible by not declaring them
497
            public?
498
499
                <hint>
500
                By default NetBeans build harness treats all packages are private.
501
                If you export some of them - either as public or friend packages,
502
                you should have a reason. If the reason is described elsewhere
503
                in this document, you can ignore this question.
504
                </hint>
505
            </question>
506
    -->
507
    <answer id="deploy-packages">
508
        <p>
509
            No; only API classes are public.
510
        </p>
511
    </answer>
512
513
514
515
    <!--
516
            <question id="deploy-shared" when="final">
517
                Do you need to be installed in the shared location only, or in the user directory only,
518
                or can your module be installed anywhere?
519
                <hint>
520
                Installation location shall not matter, if it does explain why.
521
                Consider also whether <code>InstalledFileLocator</code> can help.
522
                </hint>
523
            </question>
524
    -->
525
    <answer id="deploy-shared">
526
        <p>
527
            Anywhere.
528
        </p>
529
    </answer>
530
531
532
533
    <!--
534
        <question id="exec-ant-tasks" when="impl">
535
            Do you define or register any ant tasks that other can use?
536
537
                <hint>
538
                If you provide an ant task that users can use, you need to be very
539
                careful about its syntax and behaviour, as it most likely forms an
540
                      API for end users and as there is a lot of end users, their reaction
541
                when such API gets broken can be pretty strong.
542
                </hint>
543
            </question>
544
    -->
545
    <answer id="exec-ant-tasks">
546
        <p>
547
            No.
548
        </p>
549
    </answer>
550
551
552
553
    <!--
554
            <question id="exec-classloader" when="impl">
555
                Does your code create its own class loader(s)?
556
                <hint>
557
                A bit unusual. Please explain why and what for.
558
                </hint>
559
            </question>
560
    -->
561
    <answer id="exec-classloader">
562
        <p>
563
            No.
564
        </p>
565
    </answer>
566
567
568
569
    <!--
570
        <question id="exec-component" when="impl">
571
            Is execution of your code influenced by any (string) property
572
            of any of your components?
573
574
                <hint>
575
                Often <code>JComponent.getClientProperty</code>, <code>Action.getValue</code>
576
                or <code>PropertyDescriptor.getValue</code>, etc. are used to influence
577
                a behavior of some code. This of course forms an interface that should
578
                be documented. Also if one depends on some interface that an object
579
                implements (<code>component instanceof Runnable</code>) that forms an
580
                API as well.
581
                </hint>
582
            </question>
583
    -->
584
    <answer id="exec-component">
585
        <p>
586
            No.
587
        </p>
588
    </answer>
589
590
591
592
    <!--
593
            <question id="exec-introspection" when="impl">
594
                Does your module use any kind of runtime type information (<code>instanceof</code>,
595
                work with <code>java.lang.Class</code>, etc.)?
596
                <hint>
597
                Check for cases when you have an object of type A and you also
598
                expect it to (possibly) be of type B and do some special action. That
599
                should be documented. The same applies on operations in meta-level
600
                (Class.isInstance(...), Class.isAssignableFrom(...), etc.).
601
                </hint>
602
            </question>
603
    -->
604
    <answer id="exec-introspection">
605
        <p>
606
            No.
607
        </p>
608
    </answer>
609
610
611
612
    <!--
613
            <question id="exec-privateaccess" when="final">
614
                Are you aware of any other parts of the system calling some of 
615
                your methods by reflection?
616
                <hint>
617
                If so, describe the "contract" as an API. Likely private or friend one, but
618
                still API and consider rewrite of it.
619
                </hint>
620
            </question>
621
    -->
622
    <answer id="exec-privateaccess">
623
        <p>
624
            No.
625
        </p>
626
    </answer>
627
628
629
630
    <!--
631
            <question id="exec-process" when="impl">
632
                Do you execute an external process from your module? How do you ensure
633
                that the result is the same on different platforms? Do you parse output?
634
                Do you depend on result code?
635
                <hint>
636
                If you feed an input, parse the output please declare that as an API.
637
                </hint>
638
            </question>
639
    -->
640
    <answer id="exec-process">
641
        <p>
642
            No.
643
        </p>
644
    </answer>
645
646
647
648
    <!--
649
            <question id="exec-property" when="impl">
650
                Is execution of your code influenced by any environment or
651
                Java system (<code>System.getProperty</code>) property?
652
                On a similar note, is there something interesting that you
653
                pass to <code>java.util.logging.Logger</code>? Or do you observe
654
                what others log?
655
                <hint>
656
                If there is a property that can change the behavior of your 
657
                code, somebody will likely use it. You should describe what it does 
658
                and the <a href="http://wiki.netbeans.org/API_Stability">stability category</a>
659
                of this API. You may use
660
                <pre>
661
                    &lt;api type="export" group="property" name="id" category="private" url="http://..."&gt;
662
                        description of the property, where it is used, what it influence, etc.
663
                    &lt;/api&gt;
664
                </pre>
665
                </hint>
666
            </question>
667
    -->
668
    <answer id="exec-property">
669
        <p>
670
            No.
671
        </p>
672
    </answer>
673
674
675
676
    <!--
677
            <question id="exec-reflection" when="impl">
678
                Does your code use Java Reflection to execute other code?
679
                <hint>
680
                This usually indicates a missing or insufficient API in the other
681
                part of the system. If the other side is not aware of your dependency
682
                this contract can be easily broken.
683
                </hint>
684
            </question>
685
    -->
686
    <answer id="exec-reflection">
687
        <p>
688
            No.
689
        </p>
690
    </answer>
691
692
693
694
    <!--
695
            <question id="exec-threading" when="init">
696
                What threading models, if any, does your module adhere to? How the
697
                project behaves with respect to threading?
698
                <hint>
699
                    Is your API threadsafe? Can it be accessed from any threads or
700
                    just from some dedicated ones? Any special relation to AWT and
701
                    its Event Dispatch thread? Also
702
                    if your module calls foreign APIs which have a specific threading model,
703
                    indicate how you comply with the requirements for multithreaded access
704
                    (synchronization, mutexes, etc.) applicable to those APIs.
705
                    If your module defines any APIs, or has complex internal structures
706
                    that might be used from multiple threads, declare how you protect
707
                    data against concurrent access, race conditions, deadlocks, etc.,
708
                    and whether such rules are enforced by runtime warnings, errors, assertions, etc.
709
                    Examples: a class might be non-thread-safe (like Java Collections); might
710
                    be fully thread-safe (internal locking); might require access through a mutex
711
                    (and may or may not automatically acquire that mutex on behalf of a client method);
712
                    might be able to run only in the event queue; etc.
713
                    Also describe when any events are fired: synchronously, asynchronously, etc.
714
                    Ideas: <a href="http://core.netbeans.org/proposals/threading/index.html#recommendations">Threading Recommendations</a> (in progress)
715
                </hint>
716
            </question>
717
    -->
718
    <answer id="exec-threading">
719
        <p>
720
            API classes are thread safe, they mostly represent immutable
721
            objects, or delegate to the SPI.
722
        </p>
723
        <p>
724
            Implementators of the SPI should ensure that their code is properly
725
            synchronized, as it can be called from any thread.
726
        </p>
727
    </answer>
728
729
730
731
<!--
732
        <question id="format-clipboard" when="impl">
733
            Which data flavors (if any) does your code read from or insert to
734
            the clipboard (by access to clipboard on means calling methods on <code>java.awt.datatransfer.Transferable</code>?
735
736
                <hint>
737
                Often Node's deal with clipboard by usage of <code>Node.clipboardCopy, Node.clipboardCut and Node.pasteTypes</code>.
738
                Check your code for overriding these methods.
739
                </hint>
740
            </question>
741
    -->
742
    <answer id="format-clipboard">
743
        <p>
744
            Plain Unicode text only.
745
        </p>
746
    </answer>
747
748
749
750
    <!--
751
            <question id="format-dnd" when="impl">
752
                Which protocols (if any) does your code understand during Drag &amp; Drop?
753
                <hint>
754
                Often Node's deal with clipboard by usage of <code>Node.drag, Node.getDropType</code>. 
755
                Check your code for overriding these methods. Btw. if they are not overridden, they
756
                by default delegate to <code>Node.clipboardCopy, Node.clipboardCut and Node.pasteTypes</code>.
757
                </hint>
758
            </question>
759
    -->
760
    <answer id="format-dnd">
761
        <p>
762
            N/A
763
        </p>
764
    </answer>
765
766
767
768
    <!--
769
        <question id="format-types" when="impl">
770
            Which protocols and file formats (if any) does your module read or write on disk,
771
            or transmit or receive over the network? Do you generate an ant build script?
772
            Can it be edited and modified?
773
774
            <hint>
775
                <p>
776
                Files can be read and written by other programs, modules and users. If they influence
777
                your behaviour, make sure you either document the format or claim that it is a private
778
                api (using the &lt;api&gt; tag).
779
                </p>
780
                <p>
781
                If you generate an ant build file, this is very likely going to be seen by end users and
782
                they will be attempted to edit it. You should be ready for that and provide here a link
783
                to documentation that you have for such purposes and also describe how you are going to
784
                understand such files during next release, when you (very likely) slightly change the 
785
                format.
786
                </p>
787
            </hint>
788
        </question>
789
    -->
790
    <answer id="format-types">
791
        <p>
792
            None.
793
        </p>
794
    </answer>
795
796
797
798
    <!--
799
        <question id="lookup-lookup" when="init">
800
            Does your module use <code>org.openide.util.Lookup</code>
801
            or any similar technology to find any components to communicate with? Which ones?
802
803
                <hint>
804
                NetBeans is build around a generic registry of services called
805
                lookup. It is preferable to use it for registration and discovery
806
                if possible. See
807
                <a href="http://www.netbeans.org/download/dev/javadoc/org-openide-util/org/openide/util/lookup/doc-files/index.html">
808
                The Solution to Comunication Between Components
809
                </a>. If you do not plan to use lookup and insist usage
810
                of other solution, then please describe why it is not working for
811
                you.
812
                <br/>
813
                When filling the final version of your arch document, please
814
                describe the interfaces you are searching for, where 
815
                are defined, whether you are searching for just one or more of them,
816
                if the order is important, etc. Also classify the stability of such
817
                API contract. Use &lt;api group=&amp;lookup&amp; /&gt; tag, so
818
                your information gets listed in the summary page of your javadoc.
819
                </hint>
820
            </question>
821
    -->
822
    <answer id="lookup-lookup">
823
        <p>
824
            <code>IOProvider.getDefault()</code> asks lookup for the first instance
825
            of <code>InputOutputProvider</code>. This is normally provided by
826
            <code>org.netbeans.core.output2</code>.
827
        </p>
828
    </answer>
829
830
831
832
    <!--
833
            <question id="lookup-register" when="final">
834
                Do you register anything into lookup for other code to find?
835
                <hint>
836
                Do you register using layer file or using a declarative annotation such as <code>@ServiceProvider</code>?
837
                Who is supposed to find your component?
838
                </hint>
839
            </question>
840
    -->
841
    <answer id="lookup-register">
842
        <p>
843
            No.
844
        </p>
845
    </answer>
846
847
848
849
    <!--
850
            <question id="lookup-remove" when="final">
851
                Do you remove entries of other modules from lookup?
852
                <hint>
853
                Why? Of course, that is possible, but it can be dangerous. Is the module
854
                your are masking resource from aware of what you are doing?
855
                </hint>
856
            </question>
857
    -->
858
    <answer id="lookup-remove">
859
        <p>
860
            No.
861
        </p>
862
    </answer>
863
864
865
866
    <!--
867
            <question id="perf-exit" when="final">
868
                Does your module run any code on exit?
869
            </question>
870
    -->
871
    <answer id="perf-exit">
872
        <p>
873
            No.
874
        </p>
875
    </answer>
876
877
878
879
    <!--
880
            <question id="perf-huge_dialogs" when="final">
881
                Does your module contain any dialogs or wizards with a large number of
882
                GUI controls such as combo boxes, lists, trees, or text areas?
883
            </question>
884
    -->
885
    <answer id="perf-huge_dialogs">
886
        <p>
887
            No.
888
        </p>
889
    </answer>
890
891
892
893
    <!--
894
            <question id="perf-limit" when="init">
895
                Are there any hard-coded or practical limits in the number or size of
896
                elements your code can handle?
897
                <hint>
898
                    Most of algorithms have increasing memory and speed complexity
899
                    with respect to size of data they operate on. What is the critical
900
                    part of your project that can be seen as a bottleneck with
901
                    respect to speed or required memory? What are the practical
902
                    sizes of data you tested your project with? What is your estimate
903
                    of potential size of data that would cause visible performance
904
                    problems? Is there some kind of check to detect such situation
905
                    and prevent "hard" crashes - for example the CloneableEditorSupport
906
                    checks for size of a file to be opened in editor
907
                    and if it is larger than 1Mb it shows a dialog giving the
908
                    user the right to decide - e.g. to cancel or commit suicide.
909
                </hint>
910
            </question>
911
    -->
912
    <answer id="perf-limit">
913
        <p>
914
            No.
915
        </p>
916
    </answer>
917
918
919
920
    <!--
921
            <question id="perf-mem" when="final">
922
                How much memory does your component consume? Estimate
923
                with a relation to the number of windows, etc.
924
            </question>
925
    -->
926
    <answer id="perf-mem">
927
        <p>
928
            N/A
929
        </p>
930
    </answer>
931
932
933
934
    <!--
935
            <question id="perf-menus" when="final">
936
                Does your module use dynamically updated context menus, or
937
                context-sensitive actions with complicated and slow enablement logic?
938
                <hint>
939
                    If you do a lot of tricks when adding actions to regular or context menus, you can significantly
940
                    slow down display of the menu, even when the user is not using your action. Pay attention to
941
                    actions you add to the main menu bar, and to context menus of foreign nodes or components. If
942
                    the action is conditionally enabled, or changes its display dynamically, you need to check the
943
                    impact on performance. In some cases it may be more appropriate to make a simple action that is
944
                    always enabled but does more detailed checks in a dialog if it is actually run.
945
                </hint>
946
            </question>
947
    -->
948
    <answer id="perf-menus">
949
        <p>
950
            No.
951
        </p>
952
    </answer>
953
954
955
956
    <!--
957
        <question id="perf-progress" when="final">
958
            Does your module execute any long-running tasks?
959
960
                <hint>Long running tasks should never block
961
                AWT thread as it badly hurts the UI
962
                <a href="http://performance.netbeans.org/responsiveness/issues.html">
963
                responsiveness</a>.
964
                Tasks like connecting over
965
                network, computing huge amount of data, compilation
966
                be done asynchronously (for example
967
                using <code>RequestProcessor</code>), definitively it should
968
                not block AWT thread.
969
                </hint>
970
            </question>
971
    -->
972
    <answer id="perf-progress">
973
        <p>
974
            No.
975
        </p>
976
    </answer>
977
978
979
980
    <!--
981
            <question id="perf-scale" when="init">
982
                Which external criteria influence the performance of your
983
                program (size of file in editor, number of files in menu,
984
                in source directory, etc.) and how well your code scales?
985
                <hint>
986
                Please include some estimates, there are other more detailed
987
                questions to answer in later phases of implementation.`
988
                </hint>
989
            </question>
990
    -->
991
    <answer id="perf-scale">
992
        <p>
993
            Scalability in GUI speed and memory consumption is probably limited
994
            only by the Output Window implementation.
995
        </p>
996
    </answer>
997
998
999
1000
    <!--
1001
            <question id="perf-spi" when="init">
1002
                How the performance of the plugged in code will be enforced?
1003
                <hint>
1004
                If you allow foreign code to be plugged into your own module, how
1005
                do you enforce that it will behave correctly and quickly and will not
1006
                negatively influence the performance of your own module?
1007
                </hint>
1008
            </question>
1009
    -->
1010
    <answer id="perf-spi">
1011
        <p>
1012
            No special behavior.
1013
        </p>
1014
    </answer>
1015
1016
1017
1018
    <!--
1019
            <question id="perf-startup" when="final">
1020
                Does your module run any code on startup?
1021
            </question>
1022
    -->
1023
    <answer id="perf-startup">
1024
        <p>
1025
            No.
1026
        </p>
1027
    </answer>
1028
1029
1030
1031
    <!--
1032
            <question id="perf-wakeup" when="final">
1033
                Does any piece of your code wake up periodically and do something
1034
                even when the system is otherwise idle (no user interaction)?
1035
            </question>
1036
    -->
1037
    <answer id="perf-wakeup">
1038
        <p>
1039
            No.
1040
        </p>
1041
    </answer>
1042
1043
1044
1045
    <!--
1046
        <question id="resources-file" when="final">
1047
            Does your module use <code>java.io.File</code> directly?
1048
1049
                <hint>
1050
                NetBeans provide a logical wrapper over plain files called
1051
                <code>org.openide.filesystems.FileObject</code> that
1052
                provides uniform access to such resources and is the preferred
1053
                way that should be used. But of course there can be situations when
1054
                this is not suitable.
1055
                </hint>
1056
            </question>
1057
    -->
1058
    <answer id="resources-file">
1059
        <p>
1060
            No, but the implementation may.
1061
        </p>
1062
    </answer>
1063
1064
1065
1066
    <!--
1067
        <question id="resources-layer" when="final">
1068
            Does your module provide own layer? Does it create any files or
1069
            folders in it? What it is trying to communicate by that and with which 
1070
            components?
1071
1072
                <hint>
1073
                NetBeans allows automatic and declarative installation of resources 
1074
                by module layers. Module register files into appropriate places
1075
                and other components use that information to perform their task
1076
                (build menu, toolbar, window layout, list of templates, set of
1077
                options, etc.).
1078
                </hint>
1079
            </question>
1080
    -->
1081
    <answer id="resources-layer">
1082
        <p>
1083
            No.
1084
        </p>
1085
    </answer>
1086
1087
1088
1089
    <!--
1090
        <question id="resources-mask" when="final">
1091
            Does your module mask/hide/override any resources provided by other modules in
1092
            their layers?
1093
1094
                <hint>
1095
                If you mask a file provided by another module, you probably depend
1096
                on that and do not want the other module to (for example) change
1097
                the file's name. That module shall thus make that file available as an API
1098
                of some stability category.
1099
                </hint>
1100
            </question>
1101
    -->
1102
    <answer id="resources-mask">
1103
        <p>
1104
            No.
1105
        </p>
1106
    </answer>
1107
1108
1109
1110
    <!--
1111
            <question id="resources-preferences" when="final">
1112
                Does your module uses preferences via Preferences API? Does your module use NbPreferences or
1113
                or regular JDK Preferences ? Does it read, write or both ?
1114
                Does it share preferences with other modules ? If so, then why ?
1115
                <hint>
1116
                    You may use
1117
                        &lt;api type="export" group="preferences"
1118
                        name="preference node name" category="private"&gt;
1119
                        description of individual keys, where it is used, what it
1120
                        influences, whether the module reads/write it, etc.
1121
                        &lt;/api&gt;
1122
                    Due to XML ID restrictions, rather than /org/netbeans/modules/foo give the "name" as org.netbeans.modules.foo.
1123
                    Note that if you use NbPreferences this name will then be the same as the code name base of the module.
1124
                </hint>
1125
            </question>
1126
    -->
1127
    <answer id="resources-preferences">
1128
        <p>
1129
            No.
1130
        </p>
1131
    </answer>
1132
1133
1134
1135
    <!--
1136
        <question id="resources-read" when="final">
1137
            Does your module read any resources from layers? For what purpose?
1138
1139
                <hint>
1140
                As this is some kind of intermodule dependency, it is a kind of API.
1141
                Please describe it and classify according to
1142
                <a href="http://wiki.netbeans.org/API_Design#What_is_an_API.3F">
1143
                common stability categories</a>.
1144
                </hint>
1145
            </question>
1146
    -->
1147
    <answer id="resources-read">
1148
        <p>
1149
            No.
1150
        </p>
1151
    </answer>
1152
1153
1154
1155
    <!--
1156
            <question id="security-grant" when="final">
1157
                Does your code grant additional rights to some other code?
1158
                <hint>Avoid using a class loader that adds extra
1159
                permissions to loaded code unless really necessary.
1160
                Also note that your API implementation
1161
                can also expose unneeded permissions to enemy code by
1162
                calling AccessController.doPrivileged().</hint>
1163
            </question>
1164
    -->
1165
    <answer id="security-grant">
1166
        <p>
1167
            No.
1168
        </p>
1169
    </answer>
1170
1171
1172
1173
    <!--
1174
            <question id="security-policy" when="final">
1175
                Does your functionality require modifications to the standard policy file?
1176
                <hint>Your code might pass control to third-party code not
1177
                coming from trusted domains. This could be code downloaded over the
1178
                network or code coming from libraries that are not bundled
1179
                with NetBeans. Which permissions need to be granted to which domains?</hint>
1180
            </question>
1181
    -->
1182
    <answer id="security-policy">
1183
        <p>
1184
            No.
1185
        </p>
1186
    </answer>
1187
1188
</api-answers>
(-)a/api.io/build.xml (+5 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project basedir="." default="netbeans" name="api.io">
3
    <description>Builds, tests, and runs the project org.netbeans.api.io</description>
4
    <import file="../nbbuild/templates/projectized.xml"/>
5
</project>
(-)a/api.io/manifest.mf (+6 lines)
Line 0 Link Here
1
Manifest-Version: 1.0
2
AutoUpdate-Show-In-Client: true
3
OpenIDE-Module: org.netbeans.api.io
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/api/io/Bundle.properties
5
OpenIDE-Module-Specification-Version: 1.0
6
OpenIDE-Module-Needs: org.netbeans.spi.io.InputOutputProvider
(-)a/api.io/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/api.io/nbproject/project.xml (+54 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.netbeans.api.io</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.25</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.26</specification-version>
31
                    </run-dependency>
32
                </dependency>
33
            </module-dependencies>
34
            <test-dependencies>
35
                <test-type>
36
                    <name>unit</name>
37
                    <test-dependency>
38
                        <code-name-base>org.netbeans.libs.junit4</code-name-base>
39
                        <compile-dependency/>
40
                    </test-dependency>
41
                    <test-dependency>
42
                        <code-name-base>org.netbeans.modules.nbjunit</code-name-base>
43
                        <compile-dependency/>
44
                    </test-dependency>
45
                </test-type>
46
            </test-dependencies>
47
            <public-packages>
48
                <package>org.netbeans.api.io</package>
49
                <package>org.netbeans.spi.io</package>
50
                <package>org.netbeans.spi.io.hyperlink</package>
51
            </public-packages>
52
        </data>
53
    </configuration>
54
</project>
(-)a/api.io/src/org/netbeans/api/io/Bundle.properties (+6 lines)
Line 0 Link Here
1
OpenIDE-Module-Display-Category=Infrastructure
2
OpenIDE-Module-Long-Description=\
3
    API classes for creating output panes (e.g. tabs in output window) and for writing data into them.\n\
4
    SPI for custom implementations of output window.
5
OpenIDE-Module-Name=I/O API and SPI
6
OpenIDE-Module-Short-Description=APIs and SPIs related to displaying output.
(-)a/api.io/src/org/netbeans/api/io/Fold.java (+131 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.api.io;
43
44
import java.io.PrintWriter;
45
import org.netbeans.spi.io.InputOutputProvider;
46
47
/**
48
 * A fold (nested or standalone) in the output window.
49
 *
50
 * <p>
51
 * Methods of this class can be called in any thread.
52
 * </p>
53
 *
54
 * @author jhavlin
55
 */
56
public abstract class Fold {
57
58
    static final Fold UNSUPPORTED = new Fold() {
59
60
        @Override
61
        public void setExpanded(boolean expanded) {
62
        }
63
64
        @Override
65
        void endFold() {
66
        }
67
    };
68
69
    private Fold() {
70
    }
71
72
    static <IO, OW extends PrintWriter, P, F> Fold create(
73
            InputOutputProvider<IO, OW, P, F> provider, IO io, OW writer,
74
            F fold) {
75
        if (fold == null) {
76
            return UNSUPPORTED;
77
        } else {
78
            return new Impl<IO, OW, P, F>(provider, io, writer, fold);
79
        }
80
    }
81
82
    /**
83
     * Set fold expansion state.
84
     *
85
     * @param expanded True to expand the fold, false to collapse it.
86
     */
87
    public abstract void setExpanded(boolean expanded);
88
89
    abstract void endFold();
90
91
    /**
92
     * Expand the fold.
93
     */
94
    public final void expand() {
95
        setExpanded(true);
96
    }
97
98
    /**
99
     * Collapse the fold.
100
     */
101
    public final void collapse() {
102
        setExpanded(false);
103
    }
104
105
    private static class Impl<IO, OW extends PrintWriter, P, F> extends Fold {
106
107
        private final InputOutputProvider<IO, OW, P, F> provider;
108
        private final IO io;
109
        private final OW writer;
110
        private final F fold;
111
112
        public Impl(InputOutputProvider<IO, OW, P, F> provider, IO io,
113
                OW writer, F fold) {
114
115
            this.provider = provider;
116
            this.io = io;
117
            this.writer = writer;
118
            this.fold = fold;
119
        }
120
121
        @Override
122
        public void setExpanded(boolean expanded) {
123
            provider.setFoldExpanded(io, writer, fold, expanded);
124
        }
125
126
        @Override
127
        void endFold() {
128
            provider.endFold(io, writer, fold);
129
        }
130
    }
131
}
(-)a/api.io/src/org/netbeans/api/io/Hyperlink.java (+159 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.api.io;
43
44
import java.net.URI;
45
import org.netbeans.api.annotations.common.NonNull;
46
import org.netbeans.modules.io.HyperlinkAccessor;
47
import org.openide.util.Parameters;
48
49
/**
50
 * Hyperlink in output window. It can be specified by a URI to open (e.g. file +
51
 * row + col), or a {@link Runnable} to invoke when the hyperlink is clicked.
52
 *
53
 * @author jhavlin
54
 */
55
public abstract class Hyperlink {
56
57
    private final boolean important;
58
59
    private Hyperlink(boolean important) {
60
        this.important = important;
61
    }
62
63
    static {
64
        HyperlinkAccessor.setDefault(new HyperlinkAccessorImpl());
65
    }
66
67
    /**
68
     * @return True if the hyperlink has been marked as important, false if it
69
     * is a standard link.
70
     */
71
    boolean isImportant() {
72
        return important;
73
    }
74
75
    /**
76
     * Create a new hyperlink for specified URI.
77
     *
78
     * @param uri Hyperlink targed.
79
     *
80
     * @return The new hyperlink.
81
     */
82
    @NonNull
83
    public static Hyperlink forURI(@NonNull URI uri) {
84
        return forURI(uri, false);
85
    }
86
87
    /**
88
     * Create a new hyperlink for specified {@link Runnable}, which will be
89
     * invoked when the line is clicked.
90
     *
91
     * @param runnable The runnable to run on click.
92
     * @return The new hyperlink.
93
     */
94
    @NonNull
95
    public static Hyperlink onClick(@NonNull Runnable runnable) {
96
        return onClick(runnable, false);
97
    }
98
99
    /**
100
     * Create a new hyperlink for specified URI.
101
     *
102
     * @param uri Hyperlink targed.
103
     * @param important True if the hyperlink should be handled as an important
104
     * one, false if it is a standard one.
105
     *
106
     * @return The new hyperlink.
107
     */
108
    @NonNull
109
    public static Hyperlink forURI(@NonNull URI uri, boolean important) {
110
        Parameters.notNull("uri", uri);
111
        return new UriHyperlink(uri, important);
112
    }
113
114
    /**
115
     * Create a new hyperlink for specified {@link Runnable}, which will be
116
     * invoked when the line is clicked.
117
     *
118
     * @param runnable The runnable to run on click.
119
     * @param important True if the hyperlink should be handled as an important
120
     * one, false if it is a standard one.
121
     * @return The new hyperlink.
122
     */
123
    @NonNull
124
    public static Hyperlink onClick(@NonNull Runnable runnable,
125
            boolean important) {
126
        Parameters.notNull("runnable", runnable);
127
        return new OnClickHyperlink(runnable, important);
128
    }
129
130
    @SuppressWarnings("PackageVisibleInnerClass")
131
    static class OnClickHyperlink extends Hyperlink {
132
133
        private final Runnable runnable;
134
135
        public OnClickHyperlink(Runnable runnable, boolean important) {
136
            super(important);
137
            this.runnable = runnable;
138
        }
139
140
        public Runnable getRunnable() {
141
            return runnable;
142
        }
143
    }
144
145
    @SuppressWarnings("PackageVisibleInnerClass")
146
    static class UriHyperlink extends Hyperlink {
147
148
        private final URI uri;
149
150
        public UriHyperlink(URI uri, boolean important) {
151
            super(important);
152
            this.uri = uri;
153
        }
154
155
        public URI getUri() {
156
            return uri;
157
        }
158
    }
159
}
(-)a/api.io/src/org/netbeans/api/io/HyperlinkAccessorImpl.java (+89 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.api.io;
43
44
import java.net.URI;
45
import org.netbeans.modules.io.HyperlinkAccessor;
46
import org.netbeans.spi.io.HyperlinkType;
47
48
/**
49
 * Implementation of accessor that enables retrieving information about
50
 * hyperlinks in SPI.
51
 *
52
 * @author jhavlin
53
 */
54
class HyperlinkAccessorImpl extends HyperlinkAccessor {
55
56
    @Override
57
    public HyperlinkType getType(Hyperlink hyperlink) {
58
        if (hyperlink instanceof Hyperlink.OnClickHyperlink) {
59
            return HyperlinkType.ON_CLICK;
60
        } else if (hyperlink instanceof Hyperlink.UriHyperlink) {
61
            return HyperlinkType.FOR_URI;
62
        } else {
63
            throw new IllegalArgumentException("Unknown hyperlink.");   //NOI18N
64
        }
65
    }
66
67
    @Override
68
    public boolean isImportant(Hyperlink hyperlink) {
69
        return hyperlink.isImportant();
70
    }
71
72
    @Override
73
    public Runnable getRunnable(Hyperlink hyperlink) {
74
        if (hyperlink instanceof Hyperlink.OnClickHyperlink) {
75
            return ((Hyperlink.OnClickHyperlink) hyperlink).getRunnable();
76
        } else {
77
            throw new IllegalArgumentException("Not an ON_CLICK link.");//NOI18N
78
        }
79
    }
80
81
    @Override
82
    public URI getURI(Hyperlink hyperlink) {
83
        if (hyperlink instanceof Hyperlink.UriHyperlink) {
84
            return ((Hyperlink.UriHyperlink) hyperlink).getUri();
85
        } else {
86
            throw new IllegalArgumentException("Not a FOR_URI link.");  //NOI18N
87
        }
88
    }
89
}
(-)a/api.io/src/org/netbeans/api/io/IOProvider.java (+296 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.api.io;
43
44
import java.io.InputStreamReader;
45
import java.io.PrintWriter;
46
import java.io.Reader;
47
import java.util.Collection;
48
import java.util.Set;
49
import org.netbeans.api.annotations.common.NonNull;
50
import org.netbeans.spi.io.InputOutputProvider;
51
import org.openide.util.Lookup;
52
import org.openide.util.Parameters;
53
54
/**
55
 * A factory for IO tabs shown in the output window. To create a new tab to
56
 * write to, call e.g.
57
 * <code>IOProvider.getDefault().getIO("MyTab", false)</code> (pass true if
58
 * there may be an existing tab with the same name and you want to write to a
59
 * new tab).
60
 *
61
 * <p>
62
 * Methods of this class can be called in any thread.
63
 * </p>
64
 *
65
 * @author Jesse Glick, Jaroslav Havlin
66
 */
67
public abstract class IOProvider {
68
69
    private IOProvider() {
70
    }
71
72
    /**
73
     * Get the default I/O provider.
74
     * <p>
75
     * Normally this is taken from {@link Lookup#getDefault} but if there is no
76
     * instance in lookup, a fallback instance is created which just uses the
77
     * standard system I/O streams. This is useful for unit tests and perhaps
78
     * for standalone usage of various libraries.
79
     * </p>
80
     *
81
     * @return The default instance (never null).
82
     */
83
    @NonNull
84
    public static IOProvider getDefault() {
85
        InputOutputProvider<?, ?, ?, ?> def
86
                = Lookup.getDefault().lookup(InputOutputProvider.class);
87
        if (def != null) {
88
            return wrapProvider(def);
89
        } else {
90
            return wrapProvider(new Trivial());
91
        }
92
    }
93
94
    private static <IO, OW extends PrintWriter, P, F> IOProvider wrapProvider(
95
            InputOutputProvider<IO, OW, P, F> provider) {
96
97
        return new Impl<IO, OW, P, F>(provider);
98
    }
99
100
    /**
101
     * Gets IOProvider of selected name or delegates to getDefault() if none was
102
     * found.
103
     *
104
     * @param name ID of provider.
105
     * @return The instance corresponding to provided name or default instance
106
     * if not found.
107
     */
108
    @NonNull
109
    public static IOProvider get(@NonNull String name) {
110
        Parameters.notNull("name", name);
111
112
        @SuppressWarnings("rawtypes")
113
        Collection<? extends InputOutputProvider> providers
114
                = Lookup.getDefault().lookupAll(InputOutputProvider.class);
115
116
        for (InputOutputProvider<?, ?, ?, ?> p : providers) {
117
            if (p.getName().equals(name)) {
118
                return wrapProvider(p);
119
            }
120
        }
121
        return getDefault();
122
    }
123
124
    /**
125
     * Gets name (id) of provider.
126
     *
127
     * @return Name of this provider.
128
     */
129
    @NonNull
130
    public abstract String getName();
131
132
    /**
133
     * Get a named instance of InputOutput, which represents an output tab in
134
     * the output window. Streams for reading/writing can be accessed via
135
     * getters on the returned instance.
136
     *
137
     * @param name A localised display name for the tab.
138
     * @param newIO If <tt>true</tt>, a new <code>InputOutput</code> is
139
     * returned, else an existing <code>InputOutput</code> of the same name may
140
     * be returned.
141
     * @return An <code>InputOutput</code> instance for accessing the new tab.
142
     * @see InputOutput
143
     */
144
    @NonNull
145
    public abstract InputOutput getIO(@NonNull String name, boolean newIO);
146
147
    /**
148
     * Get a named instance of InputOutput, which represents an output tab in
149
     * the output window. Streams for reading/writing can be accessed via
150
     * getters on the returned instance.
151
     *
152
     * @param name A localised display name for the tab.
153
     * @param newIO If <tt>true</tt>, a new <code>InputOutput</code> is
154
     * returned, else an existing <code>InputOutput</code> of the same name may
155
     * be returned.
156
     * @param lookup Lookup which may contain additional information for various
157
     * implementations of output window.
158
     * @return An <code>InputOutput</code> instance for accessing the new tab.
159
     * @see InputOutput
160
     */
161
    @NonNull
162
    public abstract InputOutput getIO(@NonNull String name, boolean newIO,
163
            @NonNull Lookup lookup);
164
165
    /**
166
     * Implementation of IOProvider that uses {@link InputOutputProvider} SPI
167
     * internally.
168
     *
169
     * @param <IO>
170
     * @param <OW>
171
     * @param <POS>
172
     */
173
    private static class Impl<IO, OW extends PrintWriter, P, F>
174
            extends IOProvider {
175
176
        private final InputOutputProvider<IO, OW, P, F> impl;
177
178
        public Impl(InputOutputProvider<IO, OW, P, F> impl) {
179
            this.impl = impl;
180
        }
181
182
        @Override
183
        public String getName() {
184
            return impl.getName();
185
        }
186
187
        @Override
188
        public InputOutput getIO(String name, boolean newIO) {
189
            return getIO(name, newIO, Lookup.EMPTY);
190
        }
191
192
        @Override
193
        public InputOutput getIO(String name, boolean newIO, Lookup lookup) {
194
            Parameters.notNull("name", name);
195
            Parameters.notNull("lookup", lookup);
196
            return InputOutput.create(impl, impl.getIO(name, newIO, lookup));
197
        }
198
    }
199
200
    /**
201
     * Trivial implementation of {@link IOProvider} that uses system input,
202
     * output and error streams.
203
     */
204
    private static class Trivial
205
            implements InputOutputProvider<Object, PrintWriter, Void, Void> {
206
207
        @Override
208
        public String getName() {
209
            return "Trivial";
210
        }
211
212
        @Override
213
        public Object getIO(String name, boolean newIO, Lookup lookup) {
214
            return this;
215
        }
216
217
        @Override
218
        public Reader getIn(Object io) {
219
            return new InputStreamReader(System.in);
220
        }
221
222
        @Override
223
        public PrintWriter getOut(Object io) {
224
            return new PrintWriter(System.out);
225
        }
226
227
        @Override
228
        public PrintWriter getErr(Object io) {
229
            return new PrintWriter(System.err);
230
        }
231
232
        @Override
233
        public void print(Object io, PrintWriter writer, String text,
234
                Hyperlink link, OutputColor color, boolean printLineEnd) {
235
            writer.print(text);
236
            if (printLineEnd) {
237
                writer.println();
238
            }
239
        }
240
241
        @Override
242
        public Lookup getIOLookup(Object io) {
243
            return Lookup.EMPTY;
244
        }
245
246
        @Override
247
        public void resetIO(Object io) {
248
        }
249
250
        @Override
251
        public void showIO(Object io, PrintWriter writer,
252
                Set<ShowOperation> operations) {
253
        }
254
255
        @Override
256
        public void closeIO(Object io) {
257
        }
258
259
        @Override
260
        public boolean isIOClosed(Object io) {
261
            return false;
262
        }
263
264
        @Override
265
        public Void getCurrentPosition(Object io, PrintWriter writer) {
266
            return null;
267
        }
268
269
        @Override
270
        public void scrollTo(Object io, PrintWriter writer, Void position) {
271
        }
272
273
        @Override
274
        public Void startFold(Object io, PrintWriter writer, boolean expanded) {
275
            return null;
276
        }
277
278
        @Override
279
        public void endFold(Object io, PrintWriter writer, Void fold) {
280
        }
281
282
        @Override
283
        public void setFoldExpanded(Object io, PrintWriter writer, Void fold,
284
                boolean expanded) {
285
        }
286
287
        @Override
288
        public String getIODescription(Object io) {
289
            return null;
290
        }
291
292
        @Override
293
        public void setIODescription(Object io, String description) {
294
        }
295
    }
296
}
(-)a/api.io/src/org/netbeans/api/io/InputOutput.java (+274 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.api.io;
43
44
import java.io.PrintWriter;
45
import java.io.Reader;
46
import java.util.Collections;
47
import java.util.Map;
48
import java.util.WeakHashMap;
49
import org.netbeans.api.annotations.common.CheckForNull;
50
import org.netbeans.api.annotations.common.NonNull;
51
import org.netbeans.api.annotations.common.NullAllowed;
52
import org.netbeans.spi.io.InputOutputProvider;
53
import org.openide.util.Lookup;
54
55
/**
56
 * An I/O connection to one tab on the Output Window. To acquire an instance to
57
 * write to, call, e.g.,
58
 * <code>IOProvider.getDefault().getInputOutput("someName", false)</code>. To
59
 * get actual streams to write to, call <code>getOut()</code> or <code>
60
 * getErr()</code> on the returned instance.
61
 * <p>
62
 * Generally it is preferable not to hold a reference to an instance of
63
 * {@link org.netbeans.api.io.InputOutput}, but rather to fetch it by name from
64
 * {@link org.netbeans.api.io.IOProvider} as needed.
65
 * </p>
66
 *
67
 * <p>
68
 * Methods of this class can be called in any thread.
69
 * </p>
70
 *
71
 * @see OutputWriter
72
 * @author Ian Formanek, Jaroslav Tulach, Petr Hamernik, Ales Novak, Jan
73
 * Jancura, Jaroslav Havlin
74
 */
75
public abstract class InputOutput implements Lookup.Provider {
76
77
    private InputOutput() {
78
    }
79
80
    /**
81
     * Get a named instance of InputOutput from the default {@link IOProvider},
82
     * which represents an output tab in the output window. Streams for
83
     * reading/writing can be accessed via getters on the returned instance.
84
     *
85
     * <p>
86
     * This is a shorthand for {@code IOProvider.getDefault().getIO(...)}.
87
     * </p>
88
     *
89
     * @param name A localised display name for the tab.
90
     * @param newIO If <tt>true</tt>, a new <code>InputOutput</code> is
91
     * returned, else an existing <code>InputOutput</code> of the same name may
92
     * be returned.
93
     * @return An <code>InputOutput</code> instance for accessing the new tab.
94
     * @see IOProvider
95
     */
96
    @NonNull
97
    public static InputOutput get(@NonNull String name, boolean newIO) {
98
        return IOProvider.getDefault().getIO(name, newIO);
99
    }
100
101
     /**
102
     * Get a named instance of InputOutput from the default {@link IOProvider},
103
     * which represents an output tab in the output window. Streams for
104
     * reading/writing can be accessed via getters on the returned instance.
105
     *
106
     * <p>
107
     * This is a shorthand for {@code IOProvider.getDefault().getIO(...)}.
108
     * </p>
109
     *
110
     * @param name A localised display name for the tab.
111
     * @param newIO If <tt>true</tt>, a new <code>InputOutput</code> is
112
     * returned, else an existing <code>InputOutput</code> of the same name may
113
     * be returned.
114
     * @param lookup Lookup which may contain additional information for various
115
     * implementations of output window.
116
     * @return An <code>InputOutput</code> instance for accessing the new tab.
117
     * @see IOProvider
118
     */
119
    @NonNull
120
    public static InputOutput get(@NonNull String name, boolean newIO,
121
            @NonNull Lookup lookup) {
122
        return IOProvider.getDefault().getIO(name, newIO, lookup);
123
    }
124
125
    /**
126
     * Get a reader to read from the tab.
127
     *
128
     * @return The reader.
129
     */
130
    @NonNull
131
    public abstract Reader getIn();
132
133
    /**
134
     * Acquire an output writer to write to the tab.
135
     *
136
     * @return The writer.
137
     */
138
    @NonNull
139
    public abstract OutputWriter getOut();
140
141
    /**
142
     * Get an output writer to write to the tab in error mode. This might show
143
     * up in a different color than the regular output, e.g., or appear in a
144
     * separate pane.
145
     *
146
     * @return The writer.
147
     */
148
    @NonNull
149
    public abstract OutputWriter getErr();
150
151
    /**
152
     * Clear the output pane.
153
     */
154
    public abstract void reset();
155
156
    /**
157
     * Get lookup which may contain extensions provided by implementation of
158
     * output window.
159
     *
160
     * @return The lookup.
161
     */
162
    @NonNull
163
    @Override
164
    public abstract Lookup getLookup();
165
166
    /**
167
     * Closes this tab. The effect of calling any method on an instance of
168
     * InputOutput after calling <code>closeInputOutput()</code> on it is
169
     * undefined.
170
     */
171
    public abstract void closeInputOutput();
172
173
    /**
174
     * Test whether this tab has been closed, either by a call to
175
     * {@link #closeInputOutput()} or by the user closing the tab in the UI.
176
     *
177
     * @return Value <code>true</code> if it is closed.
178
     */
179
    public abstract boolean isClosed();
180
181
    /**
182
     * Get description of this I/O instance.
183
     *
184
     * @return The description, or null if not set.
185
     */
186
    @CheckForNull
187
    public abstract String getDescription();
188
189
    /**
190
     * Set description of this I/O instance. It can be used e.g. as tooltip for
191
     * output tab in the GUI.
192
     *
193
     * @param description The description, can be null.
194
     */
195
    public abstract void setDescription(@NullAllowed String description);
196
197
    static <IO, OW extends PrintWriter, P, F> InputOutput create(
198
            InputOutputProvider<IO, OW, P, F> provider, IO io) {
199
200
        return new Impl<IO, OW, P, F>(provider, io);
201
    }
202
203
    private static class Impl<IO, OW extends PrintWriter, P, F>
204
            extends InputOutput {
205
206
        private final Map<OW, OutputWriter> cache
207
                = Collections.synchronizedMap(
208
                        new WeakHashMap<OW, OutputWriter>());
209
210
        private final InputOutputProvider<IO, OW, P, F> provider;
211
        private final IO ioObject;
212
213
        public Impl(InputOutputProvider<IO, OW, P, F> provider, IO ioObject) {
214
215
            this.provider = provider;
216
            this.ioObject = ioObject;
217
        }
218
219
        @Override
220
        public Reader getIn() {
221
            return provider.getIn(ioObject);
222
        }
223
224
        @Override
225
        public OutputWriter getOut() {
226
            return createOrGetCachedWrapper(provider.getOut(ioObject));
227
        }
228
229
        @Override
230
        public OutputWriter getErr() {
231
            return createOrGetCachedWrapper(provider.getErr(ioObject));
232
        }
233
234
        @Override
235
        @NonNull
236
        public Lookup getLookup() {
237
            return provider.getIOLookup(ioObject);
238
        }
239
240
        @Override
241
        public void reset() {
242
            provider.resetIO(ioObject);
243
        }
244
245
        private OutputWriter createOrGetCachedWrapper(OW pw) {
246
            OutputWriter ow = cache.get(pw);
247
            if (ow == null) {
248
                ow = OutputWriter.create(provider, ioObject, pw);
249
                cache.put(pw, ow);
250
            }
251
            return ow;
252
        }
253
254
        @Override
255
        public void closeInputOutput() {
256
            provider.closeIO(ioObject);
257
        }
258
259
        @Override
260
        public boolean isClosed() {
261
            return provider.isIOClosed(ioObject);
262
        }
263
264
        @Override
265
        public String getDescription() {
266
            return provider.getIODescription(ioObject);
267
        }
268
269
        @Override
270
        public void setDescription(String description) {
271
            provider.setIODescription(ioObject, description);
272
        }
273
    }
274
}
(-)a/api.io/src/org/netbeans/api/io/OutputColor.java (+198 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.api.io;
43
44
import org.netbeans.spi.io.OutputColorType;
45
import org.netbeans.api.annotations.common.NonNull;
46
import org.netbeans.modules.io.OutputColorAccessor;
47
48
/**
49
 * A color specified for part of text in output pane. It can be a predefined
50
 * color for some type of text (success, debug, warning, failure), or arbitrary
51
 * RGB color.
52
 * <p>
53
 * Although using wide range of custom RGB colors may be tempting, predefined
54
 * colors are recommended, as they can be configured to respect GUI theme in
55
 * use.
56
 * </p>
57
 *
58
 * @author jhavlin
59
 */
60
public abstract class OutputColor {
61
62
63
    private final OutputColorType type;
64
    private static final OutputColor CLR_WARNING = new TypeColor(OutputColorType.WARNING);
65
    private static final OutputColor CLR_FAILURE = new TypeColor(OutputColorType.FAILURE);
66
    private static final OutputColor CLR_DEBUG = new TypeColor(OutputColorType.DEBUG);
67
    private static final OutputColor CLR_SUCCESS = new TypeColor(OutputColorType.SUCCESS);
68
69
    static {
70
        OutputColorAccessor.setDefault(new OutputColorAccessorImpl());
71
    }
72
73
    private OutputColor(OutputColorType type) {
74
        this.type = type;
75
    }
76
77
    OutputColorType getType() {
78
        return type;
79
    }
80
81
    /**
82
     * Warning text color.
83
     *
84
     * @return Predefined color for text of type "warning".
85
     */
86
    @NonNull
87
    public static OutputColor warning() {
88
        return CLR_WARNING;
89
    }
90
91
    /**
92
     * Failure text color.
93
     *
94
     * @return Predefined color for text of type "failure".
95
     */
96
    @NonNull
97
    public static OutputColor failure() {
98
        return CLR_FAILURE;
99
    }
100
101
    /**
102
     * Debug text color.
103
     *
104
     * @return Predefined color for text of type "debug".
105
     */
106
    @NonNull
107
    public static OutputColor debug() {
108
        return CLR_DEBUG;
109
    }
110
111
    /**
112
     * Success text color.
113
     *
114
     * @return Predefined color for text of type "success".
115
     */
116
    @NonNull
117
    public static OutputColor success() {
118
        return CLR_SUCCESS;
119
    }
120
121
    /**
122
     * Arbitrary constant RGB color.
123
     *
124
     * <p>
125
     * Please note that it is recommended to use colors for predefined text
126
     * types, which can respect color theme used by the GUI.
127
     * </p>
128
     *
129
     * @param r The red component, in the range (0 - 255).
130
     * @param g The green component, in the range (0 - 255).
131
     * @param b The blue component, in the range (0 - 255).
132
     *
133
     * @return Color specified for a constant RGB value.
134
     * @throws IllegalArgumentException If some of color components is out of
135
     * range.
136
     */
137
    @NonNull
138
    public static OutputColor rgb(int r, int g, int b) {
139
        checkColorComponentRange("r", r);
140
        checkColorComponentRange("g", g);
141
        checkColorComponentRange("b", b);
142
        int value = ((r & 0xFF) << 16)
143
                | ((g & 0xFF) << 8)
144
                | ((b & 0xFF));
145
        return rgb(value);
146
    }
147
148
    /**
149
     * Arbitrary constant RGB color. Creates an opaque sRGB color with the
150
     * specified combined RGB value consisting of the red component in bits
151
     * 16-23, the green component in bits 8-15, and the blue component in bits
152
     * 0-7.
153
     *
154
     * <p>
155
     * Please note that it is recommended to use colors for predefined text
156
     * types, which can respect color theme used by the GUI.
157
     * </p>
158
     *
159
     * @param rgbValue The combined RGB components.
160
     *
161
     * @return Color specified for a constant RGB value.
162
     */
163
    @NonNull
164
    public static OutputColor rgb(int rgbValue) {
165
        return new RgbColor(rgbValue);
166
    }
167
168
    private static void checkColorComponentRange(String name,
169
            int colorComponent) {
170
171
        if (colorComponent < 0 || colorComponent > 255) {
172
            throw new IllegalArgumentException("Color component " + name//NOI18N
173
                    + " is out of range (0 - 255): " + colorComponent); //NOI18N
174
        }
175
    }
176
177
    private static class TypeColor extends OutputColor {
178
179
        public TypeColor(OutputColorType type) {
180
            super(type);
181
        }
182
    }
183
184
    @SuppressWarnings("PackageVisibleInnerClass")
185
    static class RgbColor extends OutputColor {
186
187
        private final int value;
188
189
        public RgbColor(int value) {
190
            super(OutputColorType.RGB);
191
            this.value = value;
192
        }
193
194
        public int getRGB() {
195
            return value;
196
        }
197
    }
198
}
(-)a/api.io/src/org/netbeans/api/io/OutputColorAccessorImpl.java (+68 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.api.io;
43
44
import org.netbeans.modules.io.OutputColorAccessor;
45
import org.netbeans.spi.io.OutputColorType;
46
47
/**
48
 * Implementation of accessor that enables retrieving information about output
49
 * colors in SPI.
50
 *
51
 * @author jhavlin
52
 */
53
class OutputColorAccessorImpl extends OutputColorAccessor{
54
55
    @Override
56
    public OutputColorType getType(OutputColor color) {
57
        return color.getType();
58
    }
59
60
    @Override
61
    public int getRgb(OutputColor color) {
62
        if (color instanceof OutputColor.RgbColor) {
63
            return ((OutputColor.RgbColor) color).getRGB();
64
        } else {
65
            throw new IllegalArgumentException("Not an RGB color.");    //NOI18N
66
        }
67
    }
68
}
(-)a/api.io/src/org/netbeans/api/io/OutputWriter.java (+404 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.api.io;
43
44
import java.io.IOException;
45
import java.io.PrintWriter;
46
import java.io.Writer;
47
import java.util.Collections;
48
import java.util.EnumSet;
49
import java.util.Locale;
50
import java.util.Set;
51
import org.netbeans.api.annotations.common.NullAllowed;
52
import org.netbeans.spi.io.InputOutputProvider;
53
54
/**
55
 * Extended {@link PrintWriter} for writing into output window or similar output
56
 * GUI component. It can support features like color printing, hyperlinks, or
57
 * folding.
58
 *
59
 * <p>
60
 * Methods of this class can be called in any thread.
61
 * </p>
62
 *
63
 * @author jhavlin
64
 */
65
public abstract class OutputWriter extends PrintWriter {
66
67
    private static final Set<ShowOperation> DEFAULT_SHOW_OPERATIONS =
68
            EnumSet.of(ShowOperation.OPEN, ShowOperation.MAKE_VISIBLE);
69
70
    private OutputWriter() {
71
        super(new DummyWriter());
72
    }
73
74
    /**
75
     * Show this I/O stream, if possible (e.g. in tabbed pane).
76
     * <p>
77
     * Calling this method is the same as calling:
78
     * </p>
79
     * <pre>
80
     * show(EnumSet.of(ShowOperation.OPEN, ShowOperation.MAKE_VISIBLE));
81
     * </pre>
82
     *
83
     * @see #show(java.util.Set)
84
     */
85
    public final void show() {
86
        show(DEFAULT_SHOW_OPERATIONS);
87
    }
88
89
    /**
90
     * Show this I/O stream, if possible (e.g. in tabbed pane).
91
     *
92
     * @param operations Set of operations that should be invoked to show the
93
     * output. If the set is empty or null, pane for this I/O will be only
94
     * selected, but its component will not be opened or made visible. So it
95
     * will stay closed or hidden if it is not opened or not visible.
96
     *
97
     * @see ShowOperation
98
     */
99
    public abstract void show(@NullAllowed Set<ShowOperation> operations);
100
101
    /**
102
     * Get current position in the output stream.
103
     *
104
     * @return The position.
105
     */
106
    public abstract Position getCurrentPosition();
107
108
    /**
109
     * Start a new fold. If a fold already exists, a nested fold will be
110
     * created.
111
     *
112
     * @param expanded True if the fold should be expanded by default, false if
113
     * it should be collapsed.
114
     *
115
     * @return The fold handle.
116
     */
117
    public abstract Fold startFold(boolean expanded);
118
119
    /**
120
     * Finish a fold. If it contains some unfinished nested folds, they will be
121
     * finished as well.
122
     *
123
     * @param fold The fold to finish.
124
     */
125
    public abstract void endFold(Fold fold);
126
127
    public abstract void print(String s, Hyperlink link, OutputColor color);
128
129
    public abstract void print(String s, Hyperlink link);
130
131
    public abstract void print(String s, OutputColor color);
132
133
    public abstract void println(String s, Hyperlink link, OutputColor color);
134
135
    public abstract void println(String s, Hyperlink link);
136
137
    public abstract void println(String s, OutputColor color);
138
139
    static <IO, OW extends PrintWriter, P, F> OutputWriter create(
140
            InputOutputProvider<IO, OW, P, F> provider, IO io, OW writer) {
141
142
        return new Impl<IO, OW, P, F>(provider, io, writer);
143
    }
144
145
    private static class Impl<IO, OW extends PrintWriter, P, F>
146
            extends OutputWriter {
147
148
        private final InputOutputProvider<IO, OW, P, F> provider;
149
        private final IO io;
150
        private final OW writer;
151
152
        public Impl(InputOutputProvider<IO, OW, P, F> provider,
153
                IO io, OW writer) {
154
155
            this.provider = provider;
156
            this.io = io;
157
            this.writer = writer;
158
        }
159
160
        @Override
161
        public void show(Set<ShowOperation> operations) {
162
            provider.showIO(io, writer,
163
                    operations != null
164
                            ? operations
165
                            : Collections.<ShowOperation>emptySet());
166
        }
167
168
        @Override
169
        public Position getCurrentPosition() {
170
            return Position.create(provider, io, writer,
171
                    provider.getCurrentPosition(io, writer));
172
        }
173
174
        @Override
175
        public void print(String s, Hyperlink link, OutputColor color) {
176
            provider.print(io, writer, s, link, color, false);
177
        }
178
179
        @Override
180
        public void print(String s, Hyperlink link) {
181
            provider.print(io, writer, s, link, null, false);
182
        }
183
184
        @Override
185
        public void print(String s, OutputColor color) {
186
            provider.print(io, writer, s, null, color, false);
187
        }
188
189
        @Override
190
        public void println(String s, Hyperlink link, OutputColor color) {
191
            provider.print(io, writer, s, link, color, true);
192
        }
193
194
        @Override
195
        public void println(String s, Hyperlink link) {
196
            provider.print(io, writer, s, link, null, true);
197
        }
198
199
        @Override
200
        public void println(String s, OutputColor color) {
201
            provider.print(io, writer, s, null, color, true);
202
        }
203
204
        @Override
205
        public void flush() {
206
            writer.flush();
207
        }
208
209
        @Override
210
        public void close() {
211
            writer.close();
212
        }
213
214
        @Override
215
        public boolean checkError() {
216
            return writer.checkError();
217
        }
218
219
        @Override
220
        public void write(int c) {
221
            writer.write(c);
222
        }
223
224
        @Override
225
        public void write(char[] buf, int off, int len) {
226
            writer.write(buf, off, len);
227
        }
228
229
        @Override
230
        public void write(char[] buf) {
231
            writer.write(buf);
232
        }
233
234
        @Override
235
        public void write(String s, int off, int len) {
236
            writer.write(s, off, len);
237
        }
238
239
        @Override
240
        public void write(String s) {
241
            writer.write(s);
242
        }
243
244
        @Override
245
        public void print(boolean b) {
246
            writer.print(b);
247
        }
248
249
        @Override
250
        public void print(char c) {
251
            writer.print(c);
252
        }
253
254
        @Override
255
        public void print(int i) {
256
            writer.print(i);
257
        }
258
259
        @Override
260
        public void print(long l) {
261
            writer.print(l);
262
        }
263
264
        @Override
265
        public void print(float f) {
266
            writer.print(f);
267
        }
268
269
        @Override
270
        public void print(double d) {
271
            writer.print(d);
272
        }
273
274
        @Override
275
        @SuppressWarnings("ImplicitArrayToString")
276
        public void print(char[] s) {
277
            writer.print(s);
278
        }
279
280
        @Override
281
        public void print(String s) {
282
            writer.print(s);
283
        }
284
285
        @Override
286
        public void print(Object obj) {
287
            writer.print(obj);
288
        }
289
290
        @Override
291
        public void println() {
292
            writer.println();
293
        }
294
295
        @Override
296
        public void println(boolean x) {
297
            writer.println(x);
298
        }
299
300
        @Override
301
        public void println(char x) {
302
            writer.println(x);
303
        }
304
305
        @Override
306
        public void println(int x) {
307
            writer.println(x);
308
        }
309
310
        @Override
311
        public void println(long x) {
312
            writer.println(x);
313
        }
314
315
        @Override
316
        public void println(float x) {
317
            writer.println(x);
318
        }
319
320
        @Override
321
        public void println(double x) {
322
            writer.println(x);
323
        }
324
325
        @Override
326
        @SuppressWarnings("ImplicitArrayToString")
327
        public void println(char[] x) {
328
            writer.println(x);
329
        }
330
331
        @Override
332
        public void println(String x) {
333
            writer.println(x);
334
        }
335
336
        @Override
337
        public void println(Object x) {
338
            writer.println(x);
339
        }
340
341
        @Override
342
        public PrintWriter printf(String format, Object... args) {
343
            return writer.printf(format, args);
344
        }
345
346
        @Override
347
        public PrintWriter printf(Locale l, String format, Object... args) {
348
            return writer.printf(l, format, args);
349
        }
350
351
        @Override
352
        public PrintWriter format(String format, Object... args) {
353
            return writer.format(format, args);
354
        }
355
356
        @Override
357
        public PrintWriter format(Locale l, String format, Object... args) {
358
            return writer.format(l, format, args);
359
        }
360
361
        @Override
362
        public PrintWriter append(CharSequence csq) {
363
            return writer.append(csq);
364
        }
365
366
        @Override
367
        public PrintWriter append(CharSequence csq, int start, int end) {
368
            return writer.append(csq, start, end);
369
        }
370
371
        @Override
372
        public PrintWriter append(char c) {
373
            return writer.append(c);
374
        }
375
376
        @Override
377
        public Fold startFold(boolean expanded) {
378
            F fold = provider.startFold(io, writer, expanded);
379
            return Fold.create(provider, io, writer, fold);
380
        }
381
382
        @Override
383
        public void endFold(Fold fold) {
384
            if (fold != Fold.UNSUPPORTED) {
385
                fold.endFold();
386
            }
387
        }
388
    }
389
390
    private static class DummyWriter extends Writer {
391
392
        @Override
393
        public void write(char[] cbuf, int off, int len) throws IOException {
394
        }
395
396
        @Override
397
        public void flush() throws IOException {
398
        }
399
400
        @Override
401
        public void close() throws IOException {
402
        }
403
    }
404
}
(-)a/api.io/src/org/netbeans/api/io/Position.java (+106 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.api.io;
43
44
import java.io.PrintWriter;
45
import org.netbeans.spi.io.InputOutputProvider;
46
47
/**
48
 *
49
 * Stored position in the output window.
50
 *
51
 * <p>
52
 * Methods of this class can be called in any thread.
53
 * </p>
54
 *
55
 * @author jhavlin
56
 */
57
public abstract class Position {
58
59
    static final Position UNSUPPORTED = new Position() {
60
61
        @Override
62
        public void scrollTo() {
63
        }
64
    };
65
66
    private Position() {
67
    }
68
69
    /**
70
     * Scroll to this position.
71
     */
72
    public abstract void scrollTo();
73
74
    static <IO, OW extends PrintWriter, P, F> Position create(
75
            InputOutputProvider<IO, OW, P, F> provider, IO io,
76
            OW writer, P position) {
77
78
        if (position == null) {
79
            return UNSUPPORTED;
80
        } else {
81
            return new Impl<IO, OW, P, F>(provider, io, writer, position);
82
        }
83
    }
84
85
    private static class Impl<IO, OW extends PrintWriter, P, F>
86
            extends Position {
87
88
        private final InputOutputProvider<IO, OW, P, F> provider;
89
        private final IO io;
90
        private final OW ow;
91
        private final P position;
92
93
        public Impl(InputOutputProvider<IO, OW, P, F> provider, IO io, OW ow,
94
                P position) {
95
            this.provider = provider;
96
            this.io = io;
97
            this.ow = ow;
98
            this.position = position;
99
        }
100
101
        @Override
102
        public void scrollTo() {
103
            provider.scrollTo(io, ow, position);
104
        }
105
    }
106
}
(-)a/api.io/src/org/netbeans/api/io/ShowOperation.java (+65 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.api.io;
43
44
/**
45
 * Operations that should take part when showing a component. The actual
46
 * behavior depends on implementation (some features may be unsupported).
47
 *
48
 * @author jhavlin
49
 */
50
public enum ShowOperation {
51
    /**
52
     * Open the GUI component (Output Window) if it is closed.
53
     */
54
    OPEN,
55
    /**
56
     * Make the GUI component (Output Window) visible. E.g. show it if it is
57
     * minimized.
58
     */
59
    MAKE_VISIBLE,
60
    /**
61
     * Activate the GUI component (Output Window). E.g. highlight and possibly
62
     * focus it.
63
     */
64
    ACTIVATE
65
}
(-)a/api.io/src/org/netbeans/modules/io/HyperlinkAccessor.java (+89 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.modules.io;
43
44
import java.net.URI;
45
import org.netbeans.api.io.Hyperlink;
46
import org.netbeans.spi.io.HyperlinkType;
47
48
/**
49
 *
50
 * @author jhavlin
51
 */
52
public abstract class HyperlinkAccessor {
53
54
    /**
55
     * The default implementation is set in static initializer of
56
     * {@link Hyperlink}.
57
     */
58
    private static HyperlinkAccessor DEFAULT;
59
60
    public static void setDefault(HyperlinkAccessor def) {
61
        HyperlinkAccessor.DEFAULT = def;
62
    }
63
64
    public static HyperlinkAccessor getDefault() {
65
        if (DEFAULT != null) {
66
            return DEFAULT;
67
        }
68
69
        // invokes static initializer of Item.class
70
        // that will assign value to the DEFAULT field above
71
        Class<Hyperlink> c = Hyperlink.class;
72
        try {
73
            Class.forName(c.getName(), true, c.getClassLoader());
74
        } catch (ClassNotFoundException ex) {
75
            assert false : ex;
76
        }
77
        assert DEFAULT != null :
78
                "The DEFAULT field must be initialized";                //NOI18N
79
        return DEFAULT;
80
    }
81
82
    public abstract HyperlinkType getType(Hyperlink hyperlink);
83
84
    public abstract boolean isImportant(Hyperlink hyperlink);
85
86
    public abstract Runnable getRunnable(Hyperlink hyperlink);
87
88
    public abstract URI getURI(Hyperlink hyperlink);
89
}
(-)a/api.io/src/org/netbeans/modules/io/OutputColorAccessor.java (+84 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.modules.io;
43
44
import org.netbeans.api.io.OutputColor;
45
import org.netbeans.spi.io.OutputColorType;
46
47
/**
48
 *
49
 * @author jhavlin
50
 */
51
public abstract class OutputColorAccessor {
52
53
    /**
54
     * The default implementation is set in static initializer of
55
     * {@link OutputColor}.
56
     */
57
    private static OutputColorAccessor DEFAULT;
58
59
    public static void setDefault(OutputColorAccessor def) {
60
        OutputColorAccessor.DEFAULT = def;
61
    }
62
63
    public static OutputColorAccessor getDefault() {
64
        if (DEFAULT != null) {
65
            return DEFAULT;
66
        }
67
68
        // invokes static initializer of Item.class
69
        // that will assign value to the DEFAULT field above
70
        Class<OutputColor> c = OutputColor.class;
71
        try {
72
            Class.forName(c.getName(), true, c.getClassLoader());
73
        } catch (ClassNotFoundException ex) {
74
            assert false : ex;
75
        }
76
        assert DEFAULT != null :
77
                "The DEFAULT field must be initialized";                //NOI18N
78
        return DEFAULT;
79
    }
80
81
    public abstract OutputColorType getType(OutputColor color);
82
83
    public abstract int getRgb(OutputColor color);
84
}
(-)a/api.io/src/org/netbeans/spi/io/HyperlinkType.java (+54 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.spi.io;
43
44
/**
45
 * Type of the hyperlink.
46
 * <p>
47
 * Note: New items may be added in the future.
48
 * </p>
49
 *
50
 * @author jhavlin
51
 */
52
public enum HyperlinkType {
53
    ON_CLICK, FOR_URI
54
}
(-)a/api.io/src/org/netbeans/spi/io/Hyperlinks.java (+115 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.spi.io;
43
44
import java.net.URI;
45
import org.netbeans.api.annotations.common.NonNull;
46
import org.netbeans.api.io.Hyperlink;
47
import org.netbeans.modules.io.HyperlinkAccessor;
48
49
/**
50
 * Helper class for accessing information from {@link Hyperlink} objects.
51
 *
52
 * @author jhavlin
53
 */
54
public final class Hyperlinks {
55
56
    private Hyperlinks() {
57
    }
58
59
    /**
60
     * Get hyperlink type.
61
     *
62
     * @param hyperlink The hyperlink to get type of.
63
     * @return The type of the hyperlink.
64
     */
65
    @NonNull
66
    public static HyperlinkType getType(@NonNull Hyperlink hyperlink) {
67
        return HyperlinkAccessor.getDefault().getType(hyperlink);
68
    }
69
70
    /**
71
     * Check whether a hyperlink is important.
72
     *
73
     * @param hyperlink The hyperlink to check.
74
     *
75
     * @return True if the hyperlink has been marked as important, false if it
76
     * is a standard link.
77
     */
78
    public static boolean isImportant(@NonNull Hyperlink hyperlink) {
79
        return HyperlinkAccessor.getDefault().isImportant(hyperlink);
80
    }
81
82
    /**
83
     * Get URI associated with a hyperlink of type
84
     * {@link HyperlinkType#FOR_URI}.
85
     *
86
     * @param hyperlink The hyperlink to get URI from.
87
     *
88
     * @return The URI.
89
     * @throws IllegalArgumentException if type of the hyperlink is not
90
     * {@link HyperlinkType#FOR_URI}.
91
     * @see #getType(org.netbeans.api.io.Hyperlink)
92
     * @see HyperlinkType
93
     */
94
    @NonNull
95
    public static URI getURI(@NonNull Hyperlink hyperlink) {
96
        return HyperlinkAccessor.getDefault().getURI(hyperlink);
97
    }
98
99
    /**
100
     * Get runnable associated with a hyperlink of type
101
     * {@link HyperlinkType#ON_CLICK}.
102
     *
103
     * @param hyperlink The hyperlink to get runnable from.
104
     *
105
     * @return A runnable.
106
     * @throws IllegalArgumentException if type of the hyperlink is not
107
     * {@link HyperlinkType#ON_CLICK}.
108
     * @see #getType(org.netbeans.api.io.Hyperlink)
109
     * @see HyperlinkType
110
     */
111
    @NonNull
112
    public static Runnable getRunnable(@NonNull Hyperlink hyperlink) {
113
        return HyperlinkAccessor.getDefault().getRunnable(hyperlink);
114
    }
115
}
(-)a/api.io/src/org/netbeans/spi/io/InputOutputProvider.java (+331 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.spi.io;
43
44
import java.io.PrintWriter;
45
import java.io.Reader;
46
import java.util.Set;
47
import org.netbeans.api.annotations.common.CheckForNull;
48
import org.netbeans.api.annotations.common.NonNull;
49
import org.netbeans.api.annotations.common.NullAllowed;
50
import org.netbeans.api.io.Hyperlink;
51
import org.netbeans.api.io.InputOutput;
52
import org.netbeans.api.io.OutputColor;
53
import org.netbeans.api.io.ShowOperation;
54
import org.openide.util.Lookup;
55
import org.openide.util.lookup.ServiceProvider;
56
57
/**
58
 *
59
 * SPI for custom output window implementations.
60
 * <p>
61
 * Use {@link ServiceProvider} annotation for registration.
62
 * </p>
63
 *
64
 * <p>
65
 * Note: Methods of this interface can be called in any thread by the
66
 * infrastructure, so implementations should ensure proper synchronization.
67
 * </p>
68
 *
69
 * @author jhavlin
70
 *
71
 * @param <IO> Type of objects that will represent I/O instances (e.g. tabs in
72
 * output window).
73
 * @param <WRITER> Type of writers for standard and error streams.
74
 * @param <POS> Type of object that describes position of a character in the
75
 * output window. If the implementation does not support this type of
76
 * information, use {@link Void} here.
77
 * @param <FOLD> Type of object that describes a fold in output window. If the
78
 * implementation does not support this type of information, use {@link Void}
79
 * here.
80
 */
81
public interface InputOutputProvider<IO, WRITER extends PrintWriter, POS, FOLD> {
82
83
    /**
84
     * Get name of this provider.
85
     *
86
     * @return Name of this provider, never null.
87
     */
88
    @NonNull
89
    String getName();
90
91
    /**
92
     * Get or create an object that encapsulates state of a single I/O instance
93
     * (e.g. tab in output window).
94
     *
95
     * @param name Display name of the output pane.
96
     * @param newIO True to always create new I/O, false to return already
97
     * existing instance if available.
98
     * @param lookup Lookup with additional information.
99
     *
100
     * @return A single I/O instance, a newly created or already existing.
101
     * @see InputOutput
102
     */
103
    @NonNull
104
    IO getIO(@NonNull String name, boolean newIO, @NonNull Lookup lookup);
105
106
    /**
107
     * Get input of the passed I/O.
108
     *
109
     * @param io I/O instance.
110
     *
111
     * @return {@link Reader} Reader for the input entered in the output pane.
112
     */
113
    @NonNull
114
    Reader getIn(@NonNull IO io);
115
116
    /**
117
     * Get output stream of the passed I/O.
118
     *
119
     * @param io I/O instance.
120
     *
121
     * @return {@link PrintWriter} for the output stream.
122
     */
123
    @NonNull
124
    WRITER getOut(@NonNull IO io);
125
126
    /**
127
     * Get error stream of the passed I/O.
128
     *
129
     * @param io The I/O instance.
130
     *
131
     * @return {@link PrintWriter} for the error stream.
132
     */
133
    @NonNull
134
    WRITER getErr(@NonNull IO io);
135
136
    /**
137
     * Print enhanced text. It can represent a clickable hyperlink, and can be
138
     * assigned some color.
139
     *
140
     * <p>
141
     * If the implementation doesn't support this feature, this method should
142
     * call something like
143
     * {@code writer.print(text); if (printLineEnd) {writer.println();}}.
144
     * </p>
145
     *
146
     * @param io The I/O instance.
147
     * @param writer The Stream to write into.
148
     * @param text Text to print.
149
     * @param link Link which should be represented by the text, can be null for
150
     * standard text.
151
     * @param color Color of the text, can be null for the default color of the
152
     * stream.
153
     * @param printLineEnd True if new-line should be appended after printing
154
     * {code text}.
155
     */
156
    void print(@NonNull IO io, @NonNull WRITER writer, @NullAllowed String text,
157
            @NullAllowed Hyperlink link, @NullAllowed OutputColor color,
158
            boolean printLineEnd);
159
160
    /**
161
     * Get lookup of an I/O instance, which can contain various extensions and
162
     * additional info.
163
     *
164
     * @param io The I/O instance.
165
     *
166
     * @return The lookup, which can be empty, but never null.
167
     */
168
    @NonNull
169
    Lookup getIOLookup(@NonNull IO io);
170
171
    /**
172
     * Reset the I/O. Clear previously written data and prepare it for new data.
173
     * <p>
174
     * If the implementation doesn't support this feature, this method should do
175
     * nothing.
176
     * </p>
177
     *
178
     * @param io The I/O instance.
179
     */
180
    void resetIO(@NonNull IO io);
181
182
    /**
183
     * Show output pane for the passed I/O instance.
184
     * <p>
185
     * If the implementation doesn't support this feature, this method should do
186
     * nothing.
187
     * </p>
188
     *
189
     * @param io The I/O instance.
190
     * @param writer Output or error writer. If the streams are merged, this
191
     * argument can be ignored.
192
     * @param operations Operations that should be performed to show the output.
193
     * If the set is empty, the output pane (e.g. tab) can be selected, but no
194
     * GUI component should be shown or made visible if it is currently closed
195
     * or hidden.
196
     *
197
     * @see ShowOperation
198
     */
199
    void showIO(@NonNull IO io, @NonNull WRITER writer,
200
            Set<ShowOperation> operations);
201
202
    /**
203
     * Close the I/O, its output pane and release resources.
204
     *
205
     * @param io The I/O instance.
206
     *
207
     * @see #isIOClosed(java.lang.Object)
208
     */
209
    void closeIO(@NonNull IO io);
210
211
    /**
212
     * Check whether the I/O is closed.
213
     *
214
     * @param io The I/O instance.
215
     *
216
     * @return True if the I/O was closed, false otherwise.
217
     *
218
     * @see #closeIO(java.lang.Object)
219
     */
220
    boolean isIOClosed(@NonNull IO io);
221
222
    /**
223
     * Get current position.
224
     *
225
     * @param io The I/O instance.
226
     * @param writer Output or error writer. If the streams are merged, the
227
     * value can be ignored.
228
     *
229
     * @return The current position in the output pane. If this feature is not
230
     * supported, return null.
231
     */
232
    @CheckForNull
233
    POS getCurrentPosition(@NonNull IO io, @NonNull WRITER writer);
234
235
    /**
236
     * Scroll to a position.
237
     * <p>
238
     * If this feature is not supported
239
     * ({@link #getCurrentPosition(Object, PrintWriter)} returns null), this
240
     * method should do nothing, it will be never called.
241
     * </p>
242
     *
243
     * @param io The I/O instance.
244
     * @param writer Output or error writer. If the streams are merged, the
245
     * value can be ignored.
246
     * @param position The position to scroll to.
247
     *
248
     * @see #getCurrentPosition(java.lang.Object, java.io.PrintWriter)
249
     */
250
    void scrollTo(@NonNull IO io, @NonNull WRITER writer,
251
            @NonNull POS position);
252
253
    /**
254
     * Start fold at the current position. If a fold is already open, start a
255
     * new nested fold (but if a fold with the same start position already
256
     * exists, no nested fold will be created, and the same start position will
257
     * be returned).
258
     *
259
     * @param io The I/O instance.
260
     * @param writer Output or error writer. If the streams are merged, the
261
     * value can be ignored.
262
     * @param expanded True if the new fold should be expanded by default, false
263
     * if it should be collapsed.
264
     *
265
     * @return Object the fold. If the implementation doesn't support this
266
     * feature, return null.
267
     */
268
    @CheckForNull
269
    FOLD startFold(@NonNull IO io, @NonNull WRITER writer, boolean expanded);
270
271
    /**
272
     * Finish a fold specified by its start position. If some nested folds
273
     * exist, they will be finished as well if needed.
274
     *
275
     * <p>
276
     * If this feature is not supported
277
     * ({@link #startFold(Object, PrintWriter, boolean)} returns null), this
278
     * method should do nothing, it will be never called.
279
     * </p>
280
     *
281
     * @param io The I/O instance.
282
     * @param writer Output or error writer. If the streams are merged, the
283
     * value can be ignored.
284
     * @param fold The fold to finish.
285
     */
286
    void endFold(@NonNull IO io, @NonNull WRITER writer,
287
            @NonNull FOLD fold);
288
289
    /**
290
     * Expand or collapse a fold.
291
     *
292
     * <p>
293
     * If this feature is not supported
294
     * ({@link #startFold(Object, PrintWriter, boolean)} returns null), this
295
     * method should do nothing, it will be never called.
296
     * </p>
297
     *
298
     * @param io The I/O instance.
299
     * @param writer Output or error writer. If the streams are merged, the
300
     * value can be ignored.
301
     * @param fold The fold to finish.
302
     * @param expanded True to expand the fold, false to collapse the fold.
303
     */
304
    void setFoldExpanded(@NonNull IO io, @NonNull WRITER writer,
305
            FOLD fold, boolean expanded);
306
307
308
    /**
309
     * Get description of an I/O instance. It can be used e.g. as tooltip text
310
     * for the output tab.
311
     *
312
     * @param io The I/O instance.
313
     *
314
     * @return The description, or null if not set.
315
     */
316
    @CheckForNull String getIODescription(@NonNull IO io);
317
318
    /**
319
     * Set description of an I/O instance.
320
     *
321
     * <p>
322
     * If this feature is not supported, this method should do nothing.
323
     * </p>
324
     *
325
     * @param io The I/O instance.
326
     * @param description The description, can be null.
327
     *
328
     * @see #getIODescription(java.lang.Object)
329
     */
330
    void setIODescription(@NonNull IO io, @NullAllowed String description);
331
}
(-)a/api.io/src/org/netbeans/spi/io/OutputColorType.java (+54 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.spi.io;
43
44
/**
45
 * Type of the color - static (rgb) or dynamic.
46
 * <p>
47
 * Note: New items may be added in the future.
48
 * </p>
49
 *
50
 * @author jhavlin
51
 */
52
public enum OutputColorType {
53
    WARNING, FAILURE, DEBUG, SUCCESS, RGB
54
}
(-)a/api.io/src/org/netbeans/spi/io/OutputColors.java (+83 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.spi.io;
43
44
import org.netbeans.api.annotations.common.NonNull;
45
import org.netbeans.api.io.OutputColor;
46
import org.netbeans.modules.io.OutputColorAccessor;
47
48
/**
49
 * Helper class for accessing information from {@link OutputColor} objects.
50
 *
51
 * @author jhavlin
52
 */
53
public final class OutputColors {
54
55
    private OutputColors() {
56
    }
57
58
    /**
59
     * Get type of a color.
60
     *
61
     * @param color The color to get type of.
62
     * @return Type of color.
63
     */
64
    @NonNull
65
    public static OutputColorType getType(@NonNull OutputColor color) {
66
        return OutputColorAccessor.getDefault().getType(color);
67
    }
68
69
    /**
70
     * Get RGB value for an {@link OutputColor} specified for a constant RGB
71
     * color (type {@link OutputColorType#RGB}).
72
     *
73
     * @param color The color to get RGB value for.
74
     *
75
     * @return RGB value of the color.
76
     * @throws IllegalArgumentException if the color is not of type
77
     * {@link OutputColorType#RGB}.
78
     */
79
    public static int getRGB(OutputColor color) {
80
        return OutputColorAccessor.getDefault().getRgb(color);
81
    }
82
83
}
(-)a/api.io/src/org/netbeans/spi/io/Utilities.java (+73 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.spi.io;
43
44
import org.netbeans.spi.io.hyperlink.OpenUriHandler;
45
import java.net.URI;
46
import org.openide.util.Lookup;
47
48
/**
49
 * Utility methods for implementations of output window.
50
 *
51
 * @author jhavlin
52
 */
53
public final class Utilities {
54
55
    private Utilities() {
56
    }
57
58
    /**
59
     * Handle the URI when a URI hyperlink is clicked in the output window.
60
     *
61
     * @param uri The URI to handle.
62
     */
63
    public static void handleUri(URI uri) {
64
65
        for (OpenUriHandler handler
66
                : Lookup.getDefault().lookupAll(OpenUriHandler.class)) {
67
68
            if (handler.handle(uri)) {
69
                return;
70
            }
71
        }
72
    }
73
}
(-)a/api.io/src/org/netbeans/spi/io/hyperlink/OpenUriHandler.java (+68 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.spi.io.hyperlink;
43
44
import java.net.URI;
45
46
/**
47
 * SPI for handlers that can process URI hyperlinks that were clicked in the
48
 * Output Window.
49
 *
50
 * If the front-end and back-end of the application is separated, clicked URI
51
 * hyperlinks can be handled on the front-end, possibly without any
52
 * communication with the back-end.
53
 *
54
 * @author jhavlin
55
 */
56
public interface OpenUriHandler {
57
58
    /**
59
     * Handle the passed URI, if it is supported by this handler.
60
     *
61
     * @param uri The URI to handle.
62
     *
63
     * @return True if the URI has been handled succesfully, false if this
64
     * handler doesn't support it and thus it should be passed to next available
65
     * handler.
66
     */
67
    boolean handle(URI uri);
68
}
(-)a/api.io/test/unit/src/org/netbeans/api/io/HyperlinkTest.java (+99 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.api.io;
43
44
import java.net.URI;
45
import java.net.URISyntaxException;
46
import static org.junit.Assert.*;
47
import org.junit.Test;
48
import org.netbeans.spi.io.HyperlinkType;
49
import org.netbeans.spi.io.Hyperlinks;
50
51
/**
52
 *
53
 * @author jhavlin
54
 */
55
public class HyperlinkTest {
56
57
    @Test
58
    public void testUriLink() throws URISyntaxException {
59
        Hyperlink h = Hyperlink.forURI(new URI("file://x"));
60
        assertTrue(Hyperlinks.getType(h) == HyperlinkType.FOR_URI);
61
        assertFalse(h.isImportant());
62
        assertNotNull(Hyperlinks.getURI(h));
63
        assertEquals("file://x", Hyperlinks.getURI(h).toString());
64
    }
65
66
    @Test
67
    public void testUriLinkImportant() throws URISyntaxException {
68
        Hyperlink h = Hyperlink.forURI(new URI("file://x"), true);
69
        assertTrue(h.isImportant());
70
    }
71
72
    @Test
73
    public void testOnClickLink() {
74
75
        final boolean[] invoked = new boolean[1];
76
        Hyperlink h = Hyperlink.onClick(new Runnable() {
77
78
            @Override
79
            public void run() {
80
                invoked[0] = true;
81
            }
82
        });
83
        assertTrue(Hyperlinks.getType(h) == HyperlinkType.ON_CLICK);
84
        assertFalse(h.isImportant());
85
        assertNotNull(Hyperlinks.getRunnable(h));
86
        Hyperlinks.getRunnable(h).run();
87
        assertTrue("The passed code should be invoked", invoked[0]);
88
    }
89
90
    @Test
91
    public void testOnClickLinkImportant() {
92
        Hyperlink h = Hyperlink.onClick(new Runnable() {
93
            @Override
94
            public void run() {
95
            }
96
        }, true);
97
        assertTrue(h.isImportant());
98
    }
99
}
(-)a/api.io/test/unit/src/org/netbeans/api/io/IOProviderTest.java (+283 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.api.io;
43
44
import java.io.PrintWriter;
45
import java.io.Reader;
46
import java.io.StringReader;
47
import java.io.StringWriter;
48
import java.net.URI;
49
import java.net.URISyntaxException;
50
import java.util.ArrayList;
51
import java.util.Set;
52
import org.junit.Test;
53
import static org.junit.Assert.*;
54
import org.netbeans.junit.MockServices;
55
import org.netbeans.spi.io.InputOutputProvider;
56
import org.openide.util.Lookup;
57
import org.openide.util.lookup.Lookups;
58
59
/**
60
 *
61
 * @author jhavlin
62
 */
63
public class IOProviderTest {
64
65
    public IOProviderTest() {
66
    }
67
68
    @Test
69
    public void useCase1() {
70
        InputOutput io = IOProvider.getDefault().getIO("UseCase1", true);
71
        io.getOut().println("This is a simple output");
72
        io.getOut().close();
73
    }
74
75
    @Test
76
    public void useCase2() throws URISyntaxException {
77
        InputOutput io = IOProvider.getDefault().getIO("UseCase2", false);
78
        io.getOut().print("A line containing a ");
79
        io.getOut().print("hyperlink", Hyperlink.forURI(new URI(
80
                "file://n:/test/Test.java?line=4&col=2")));
81
        io.getOut().println(" for a URI.");
82
        io.getOut().close();
83
    }
84
85
    @Test
86
    public void useCase3() {
87
        InputOutput io = IOProvider.getDefault().getIO("UseCase3", true);
88
        io.getOut().print("A line containing a ");
89
        io.getOut().print("hyperlink", Hyperlink.onClick(new Runnable() {
90
            @Override
91
            public void run() {
92
                System.gc();
93
            }
94
        }));
95
        io.getOut().println(" for invokation of custom code.");
96
        io.getOut().close();
97
    }
98
99
    @Test
100
    public void useCase4() {
101
        InputOutput io = IOProvider.getDefault().getIO("UseCase4", true);
102
        io.getOut().println("Let's print some info", OutputColor.debug());
103
        io.getOut().println("or warning with appropriate color",
104
                OutputColor.warning());
105
        io.getOut().println("Maybe also text with custom reddish color",
106
                OutputColor.rgb(255, 16, 16));
107
        io.getOut().close();
108
    }
109
110
    @Test
111
    public void useCase5() {
112
        InputOutput io = IOProvider.getDefault().getIO("UseCase5", true);
113
        io.getOut().println("Let's print some text");
114
        io.getErr().println("and reset the pane immediately.");
115
        io.reset();
116
        io.getOut().println("The pane is now empty and we can reuse it simply");
117
        io.getOut().close();
118
    }
119
120
    @Test
121
    public void testTrivialImplementationAlwaysAvailable() {
122
        assertEquals("Trivial", IOProvider.getDefault().getName());
123
        assertEquals("Trivial", IOProvider.get("Trivial").getName());
124
        assertEquals("Trivial", IOProvider.get("Another").getName());
125
    }
126
127
    @Test
128
    public void testGetFromLookup() {
129
        MockServices.setServices(MockInputOutputProvider.class);
130
        try {
131
            assertEquals("mock", IOProvider.getDefault().getName());
132
            assertEquals("mock", IOProvider.get("mock").getName());
133
            assertEquals("mock", IOProvider.get("wrong").getName());
134
        } finally {
135
            MockServices.setServices();
136
        }
137
    }
138
139
    @Test
140
    public void testAllMethodsAreDelegatedToSPI() {
141
        MockServices.setServices(MockInputOutputProvider.class);
142
        try {
143
            IOProvider.getDefault().getIO("test1", true);
144
            Lookup lkp = IOProvider.getDefault()
145
                    .getIO("test1", false, Lookup.EMPTY).getLookup();
146
            CalledMethodList list = lkp.lookup(CalledMethodList.class);
147
            assertEquals("getIO", list.get(0));
148
            assertEquals("getIO", list.get(1));
149
            assertEquals("getIOLookup", list.get(2));
150
            assertEquals(3, list.size());
151
        } finally {
152
            MockServices.setServices();
153
        }
154
    }
155
156
    @SuppressWarnings("PackageVisibleInnerClass")
157
    static class CalledMethodList extends ArrayList<String> {
158
    }
159
160
    @SuppressWarnings("PublicInnerClass")
161
    public static class MockInputOutputProvider implements
162
            InputOutputProvider<Object, PrintWriter, Object, Object> {
163
164
        private final CalledMethodList calledMethods = new CalledMethodList();
165
        private final StringWriter stringWriter = new StringWriter();
166
        private final Lookup lookup = Lookups.fixed(calledMethods, stringWriter);
167
168
        @Override
169
        public String getName() {
170
            return "mock";
171
        }
172
173
        @Override
174
        public Object getIO(String name, boolean newIO, Lookup lookup) {
175
            calledMethods.add("getIO");
176
            return new Object();
177
        }
178
179
        @Override
180
        public Reader getIn(Object io) {
181
            calledMethods.add("getIn");
182
            return new StringReader("");
183
        }
184
185
        @Override
186
        public PrintWriter getOut(Object io) {
187
            calledMethods.add("getOut");
188
            return new PrintWriter(stringWriter);
189
        }
190
191
        @Override
192
        public PrintWriter getErr(Object io) {
193
            calledMethods.add("getErr");
194
            return new PrintWriter(stringWriter);
195
        }
196
197
        @Override
198
        public void print(Object io, PrintWriter writer, String text,
199
                Hyperlink link, OutputColor color, boolean printLineEnd) {
200
            if (link != null || color != null) {
201
                stringWriter.append("<ext");
202
                stringWriter.append(color != null ? " color" : "");
203
                stringWriter.append(link != null ? " link" : "");
204
                stringWriter.append(">");
205
            }
206
            stringWriter.append(text);
207
            if (link != null || color != null) {
208
                stringWriter.append("</ext>");
209
            }
210
            calledMethods.add("print");
211
            if (printLineEnd) {
212
                stringWriter.append(System.getProperty("line.separator"));
213
            }
214
        }
215
216
        @Override
217
        public Lookup getIOLookup(Object io) {
218
            calledMethods.add("getIOLookup");
219
            return lookup;
220
        }
221
222
        @Override
223
        public void resetIO(Object io) {
224
            calledMethods.add("resetIO");
225
        }
226
227
        @Override
228
        public void showIO(Object io, PrintWriter writer,
229
                Set<ShowOperation> operations) {
230
            calledMethods.add("showIO");
231
        }
232
233
        @Override
234
        public void closeIO(Object io) {
235
            calledMethods.add("closeIO");
236
        }
237
238
        @Override
239
        public boolean isIOClosed(Object io) {
240
            calledMethods.add("isIOClosed");
241
            return false;
242
        }
243
244
        @Override
245
        public Object getCurrentPosition(Object io, PrintWriter writer) {
246
            calledMethods.add("getCurrentPosition");
247
            return new Object();
248
        }
249
250
        @Override
251
        public void scrollTo(Object io, PrintWriter writer, Object position) {
252
            calledMethods.add("scrollTo");
253
        }
254
255
        @Override
256
        public Object startFold(Object io, PrintWriter writer, boolean expanded) {
257
            calledMethods.add("startFold");
258
            return new Object();
259
        }
260
261
        @Override
262
        public void endFold(Object io, PrintWriter writer, Object foldNumber) {
263
            calledMethods.add("endFold");
264
        }
265
266
        @Override
267
        public void setFoldExpanded(Object io, PrintWriter writer,
268
                Object foldNumber, boolean expanded) {
269
            calledMethods.add("setFoldExpanded");
270
        }
271
272
        @Override
273
        public String getIODescription(Object io) {
274
            calledMethods.add("getIODescription");
275
            return null;
276
        }
277
278
        @Override
279
        public void setIODescription(Object io, String description) {
280
            calledMethods.add("setIODescription");
281
        }
282
    }
283
}
(-)a/api.io/test/unit/src/org/netbeans/api/io/InputOutputTest.java (+91 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.api.io;
43
44
import org.junit.Test;
45
import static org.junit.Assert.*;
46
import org.netbeans.junit.MockServices;
47
import org.openide.util.Lookup;
48
49
/**
50
 *
51
 * @author jhavlin
52
 */
53
public class InputOutputTest {
54
55
    public InputOutputTest() {
56
    }
57
58
    @Test
59
    @SuppressWarnings("ValueOfIncrementOrDecrementUsed")
60
    public void testAllMethodsAreDelegatedToSPI() {
61
        MockServices.setServices(IOProviderTest.MockInputOutputProvider.class);
62
        try {
63
            InputOutput io = IOProvider.getDefault().getIO("test1", true);
64
            io.getIn();
65
            io.getOut();
66
            io.getErr();
67
            io.reset();
68
            io.isClosed();
69
            io.closeInputOutput();
70
            io.getDescription();
71
            io.setDescription(null);
72
            Lookup lkp = io.getLookup();
73
            IOProviderTest.CalledMethodList list
74
                    = lkp.lookup(IOProviderTest.CalledMethodList.class);
75
76
            int order = 0;
77
            assertEquals("getIO", list.get(order++));
78
            assertEquals("getIn", list.get(order++));
79
            assertEquals("getOut", list.get(order++));
80
            assertEquals("getErr", list.get(order++));
81
            assertEquals("resetIO", list.get(order++));
82
            assertEquals("isIOClosed", list.get(order++));
83
            assertEquals("closeIO", list.get(order++));
84
            assertEquals("getIODescription", list.get(order++));
85
            assertEquals("setIODescription", list.get(order++));
86
            assertEquals("getIOLookup", list.get(order++));
87
        } finally {
88
            MockServices.setServices();
89
        }
90
    }
91
}
(-)a/api.io/test/unit/src/org/netbeans/api/io/OutputColorTest.java (+91 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.api.io;
43
44
import org.netbeans.spi.io.OutputColorType;
45
import org.junit.Test;
46
import static org.junit.Assert.*;
47
import org.netbeans.spi.io.OutputColors;
48
49
/**
50
 *
51
 * @author jhavlin
52
 */
53
public class OutputColorTest {
54
55
    @Test
56
    public void testRgbColor() {
57
        OutputColor c = OutputColor.rgb(127, 255, 1);
58
        assertEquals(OutputColorType.RGB, OutputColors.getType(c));
59
        int value = OutputColors.getRGB(c);
60
        int r = value >> 16;
61
        int g = value >> 8 & 0xFF;
62
        int b = value & 0xFF;
63
        assertEquals(127, r);
64
        assertEquals(255, g);
65
        assertEquals(1, b);
66
    }
67
68
    @Test
69
    public void testWarningColor() {
70
        OutputColor c = OutputColor.warning();
71
        assertEquals(OutputColorType.WARNING, c.getType());
72
    }
73
74
    @Test
75
    public void testFailureColor() {
76
        OutputColor c = OutputColor.failure();
77
        assertEquals(OutputColorType.FAILURE, c.getType());
78
    }
79
80
    @Test
81
    public void testDebugColor() {
82
        OutputColor c = OutputColor.debug();
83
        assertEquals(OutputColorType.DEBUG, c.getType());
84
    }
85
86
    @Test
87
    public void testSuccessColor() {
88
        OutputColor c = OutputColor.success();
89
        assertEquals(OutputColorType.SUCCESS, c.getType());
90
    }
91
}
(-)a/api.io/test/unit/src/org/netbeans/api/io/OutputWriterTest.java (+129 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.api.io;
43
44
import java.io.StringWriter;
45
import java.net.URI;
46
import java.net.URISyntaxException;
47
import org.junit.Test;
48
import static org.junit.Assert.*;
49
import org.netbeans.junit.MockServices;
50
import org.openide.util.Lookup;
51
52
/**
53
 *
54
 * @author jhavlin
55
 */
56
public class OutputWriterTest {
57
58
    public OutputWriterTest() {
59
    }
60
61
    @Test
62
    @SuppressWarnings("ValueOfIncrementOrDecrementUsed")
63
    public void testAllMethodsAreDelegatedToSPI() throws URISyntaxException {
64
        MockServices.setServices(IOProviderTest.MockInputOutputProvider.class);
65
        try {
66
67
            InputOutput io = IOProvider.getDefault().getIO("test1", true);
68
            OutputWriter ow = io.getOut();
69
            Lookup lkp = io.getLookup();
70
71
            IOProviderTest.CalledMethodList list
72
                    = lkp.lookup(IOProviderTest.CalledMethodList.class);
73
74
            ow.show();
75
            Position p = ow.getCurrentPosition();
76
            p.scrollTo();
77
            Fold f = ow.startFold(true);
78
            f.expand();
79
            f.collapse();
80
            ow.endFold(f);
81
82
            int order = 0;
83
            assertEquals("getIO", list.get(order++));
84
            assertEquals("getOut", list.get(order++));
85
            assertEquals("getIOLookup", list.get(order++));
86
            assertEquals("showIO", list.get(order++));
87
            assertEquals("getCurrentPosition", list.get(order++));
88
            assertEquals("scrollTo", list.get(order++));
89
            assertEquals("startFold", list.get(order++));
90
            assertEquals("setFoldExpanded", list.get(order++));
91
            assertEquals("setFoldExpanded", list.get(order++));
92
            assertEquals("endFold", list.get(order++));
93
94
            ow.print("Line");
95
            ow.print(" 1");
96
            ow.println();
97
98
            ow.print("Hyperlink ", Hyperlink.forURI(new URI("file://x")));
99
            ow.print(" ");
100
            ow.print("Color", OutputColor.debug());
101
            ow.print(" ");
102
            ow.print("Color link", Hyperlink.forURI(new URI("file://y")),
103
                    OutputColor.debug());
104
            ow.println();
105
106
            ow.println("Line with link", Hyperlink.forURI(new URI("file://z")));
107
            ow.println("Color line", OutputColor.debug());
108
            ow.println("Color line with link",
109
                    Hyperlink.forURI(new URI("file://a")), OutputColor.debug());
110
111
            StringWriter sw = lkp.lookup(StringWriter.class);
112
            sw.toString();
113
114
            String[] lines = sw.toString().split(
115
                    System.getProperty("line.separator"));
116
117
            assertEquals("Line 1", lines[0]);
118
            assertEquals("<ext link>Hyperlink </ext> <ext color>Color</ext> "
119
                    + "<ext color link>Color link</ext>", lines[1]);
120
            assertEquals("<ext link>Line with link</ext>", lines[2]);
121
            assertEquals("<ext color>Color line</ext>", lines[3]);
122
            assertEquals("<ext color link>Color line with link</ext>", lines[4]);
123
124
        } finally {
125
            MockServices.setServices();
126
        }
127
    }
128
129
}
(-)a/core.output2/manifest.mf (-1 / +1 lines)
Lines 2-8 Link Here
2
OpenIDE-Module: org.netbeans.core.output2/1
2
OpenIDE-Module: org.netbeans.core.output2/1
3
OpenIDE-Module-Layer: org/netbeans/core/output2/layer.xml
3
OpenIDE-Module-Layer: org/netbeans/core/output2/layer.xml
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/core/output2/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/netbeans/core/output2/Bundle.properties
5
OpenIDE-Module-Provides: org.openide.windows.IOProvider
5
OpenIDE-Module-Provides: org.openide.windows.IOProvider org.netbeans.spi.io.InputOutputProvider
6
AutoUpdate-Essential-Module: true
6
AutoUpdate-Essential-Module: true
7
OpenIDE-Module-Specification-Version: 1.38
7
OpenIDE-Module-Specification-Version: 1.38
8
8
(-)a/core.output2/nbproject/project.xml (-1 / +9 lines)
Lines 50-55 Link Here
50
            <code-name-base>org.netbeans.core.output2</code-name-base>
50
            <code-name-base>org.netbeans.core.output2</code-name-base>
51
            <module-dependencies>
51
            <module-dependencies>
52
                <dependency>
52
                <dependency>
53
                    <code-name-base>org.netbeans.api.io</code-name-base>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
56
                    <run-dependency>
57
                        <specification-version>1.0</specification-version>
58
                    </run-dependency>
59
                </dependency>
60
                <dependency>
53
                    <code-name-base>org.netbeans.modules.options.api</code-name-base>
61
                    <code-name-base>org.netbeans.modules.options.api</code-name-base>
54
                    <build-prerequisite/>
62
                    <build-prerequisite/>
55
                    <compile-dependency/>
63
                    <compile-dependency/>
Lines 111-117 Link Here
111
                    <build-prerequisite/>
119
                    <build-prerequisite/>
112
                    <compile-dependency/>
120
                    <compile-dependency/>
113
                    <run-dependency>
121
                    <run-dependency>
114
                        <specification-version>1.40</specification-version>
122
                        <specification-version>1.47</specification-version>
115
                    </run-dependency>
123
                    </run-dependency>
116
                </dependency>
124
                </dependency>
117
                <dependency>
125
                <dependency>
(-)a/core.output2/src/org/netbeans/core/output2/NbIOProvider.java (-2 / +10 lines)
Lines 47-54 Link Here
47
import java.io.IOException;
47
import java.io.IOException;
48
import java.util.WeakHashMap;
48
import java.util.WeakHashMap;
49
import javax.swing.Action;
49
import javax.swing.Action;
50
import org.netbeans.spi.io.InputOutputProvider;
50
import org.openide.util.Exceptions;
51
import org.openide.util.Exceptions;
51
import org.openide.util.NbBundle;
52
import org.openide.util.NbBundle;
53
import org.openide.util.lookup.ServiceProvider;
54
import org.openide.util.lookup.ServiceProviders;
55
import org.openide.windows.BridgingIOProvider;
52
import org.openide.windows.IOContainer;
56
import org.openide.windows.IOContainer;
53
import org.openide.windows.IOProvider;
57
import org.openide.windows.IOProvider;
54
import org.openide.windows.InputOutput;
58
import org.openide.windows.InputOutput;
Lines 58-65 Link Here
58
 * Supplies Output Window implementation through Lookup.
62
 * Supplies Output Window implementation through Lookup.
59
 * @author Jesse Glick, Tim Boudreau
63
 * @author Jesse Glick, Tim Boudreau
60
 */
64
 */
61
@org.openide.util.lookup.ServiceProvider(service=org.openide.windows.IOProvider.class, position=100)
65
@ServiceProviders({
62
public final class NbIOProvider extends IOProvider {
66
    @ServiceProvider(service=IOProvider.class, position=100),
67
    @ServiceProvider(service=InputOutputProvider.class, position=100)
68
})
69
public final class NbIOProvider extends BridgingIOProvider {
70
63
    private static final WeakHashMap<IOContainer, PairMap> containerPairMaps =
71
    private static final WeakHashMap<IOContainer, PairMap> containerPairMaps =
64
            new WeakHashMap<IOContainer, PairMap>();
72
            new WeakHashMap<IOContainer, PairMap>();
65
73
(-)a/nbbuild/build.properties (+1 lines)
Lines 100-105 Link Here
100
config.javadoc.stable=\
100
config.javadoc.stable=\
101
    api.annotations.common,\
101
    api.annotations.common,\
102
    api.html4j,\
102
    api.html4j,\
103
    api.io,\
103
    api.maven,\
104
    api.maven,\
104
    autoupdate.services,\
105
    autoupdate.services,\
105
    autoupdate.ui,\
106
    autoupdate.ui,\
(-)a/nbbuild/cluster.properties (+1 lines)
Lines 195-200 Link Here
195
nb.cluster.platform=\
195
nb.cluster.platform=\
196
        api.annotations.common,\
196
        api.annotations.common,\
197
        api.html4j,\
197
        api.html4j,\
198
        api.io,\
198
        api.progress,\
199
        api.progress,\
199
        api.progress.compat8,\
200
        api.progress.compat8,\
200
        api.progress.nb,\
201
        api.progress.nb,\
(-)a/nbbuild/javadoctools/links.xml (+1 lines)
Lines 234-236 Link Here
234
<link href="${javadoc.docs.org-netbeans-modules-project-ant-ui}" offline="true" packagelistloc="${netbeans.javadoc.dir}/org-netbeans-modules-project-ant-ui"/>
234
<link href="${javadoc.docs.org-netbeans-modules-project-ant-ui}" offline="true" packagelistloc="${netbeans.javadoc.dir}/org-netbeans-modules-project-ant-ui"/>
235
<link href="${javadoc.docs.org-netbeans-modules-java-project-ui}" offline="true" packagelistloc="${netbeans.javadoc.dir}/org-netbeans-modules-java-project-ui"/>
235
<link href="${javadoc.docs.org-netbeans-modules-java-project-ui}" offline="true" packagelistloc="${netbeans.javadoc.dir}/org-netbeans-modules-java-project-ui"/>
236
<link href="${javadoc.docs.org-netbeans-modules-xml-catalog-ui}" offline="true" packagelistloc="${netbeans.javadoc.dir}/org-netbeans-modules-xml-catalog-ui"/>
236
<link href="${javadoc.docs.org-netbeans-modules-xml-catalog-ui}" offline="true" packagelistloc="${netbeans.javadoc.dir}/org-netbeans-modules-xml-catalog-ui"/>
237
<link href="${javadoc.docs.org-netbeans-api-io}" offline="true" packagelistloc="${netbeans.javadoc.dir}\org-netbeans-api-io"/>
(-)a/nbbuild/javadoctools/properties.xml (+1 lines)
Lines 233-235 Link Here
233
<property name="javadoc.docs.org-netbeans-modules-project-ant-ui" value="${javadoc.web.root}/org-netbeans-modules-project-ant-ui"/>
233
<property name="javadoc.docs.org-netbeans-modules-project-ant-ui" value="${javadoc.web.root}/org-netbeans-modules-project-ant-ui"/>
234
<property name="javadoc.docs.org-netbeans-modules-java-project-ui" value="${javadoc.web.root}/org-netbeans-modules-java-project-ui"/>
234
<property name="javadoc.docs.org-netbeans-modules-java-project-ui" value="${javadoc.web.root}/org-netbeans-modules-java-project-ui"/>
235
<property name="javadoc.docs.org-netbeans-modules-xml-catalog-ui" value="${javadoc.web.root}/org-netbeans-modules-xml-catalog-ui"/>
235
<property name="javadoc.docs.org-netbeans-modules-xml-catalog-ui" value="${javadoc.web.root}/org-netbeans-modules-xml-catalog-ui"/>
236
<property name="javadoc.docs.org-netbeans-api-io" value="${javadoc.web.root}/org-netbeans-api-io"/>
(-)a/nbbuild/javadoctools/replaces.xml (+1 lines)
Lines 233-235 Link Here
233
<replacefilter token="@org-netbeans-modules-project-ant-ui@" value="${javadoc.docs.org-netbeans-modules-project-ant-ui}"/>
233
<replacefilter token="@org-netbeans-modules-project-ant-ui@" value="${javadoc.docs.org-netbeans-modules-project-ant-ui}"/>
234
<replacefilter token="@org-netbeans-modules-java-project-ui@" value="${javadoc.docs.org-netbeans-modules-java-project-ui}"/>
234
<replacefilter token="@org-netbeans-modules-java-project-ui@" value="${javadoc.docs.org-netbeans-modules-java-project-ui}"/>
235
<replacefilter token="@org-netbeans-modules-xml-catalog-ui@" value="${javadoc.docs.org-netbeans-modules-xml-catalog-ui}"/>
235
<replacefilter token="@org-netbeans-modules-xml-catalog-ui@" value="${javadoc.docs.org-netbeans-modules-xml-catalog-ui}"/>
236
<replacefilter token="@org-netbeans-api-io@" value="${javadoc.docs.org-netbeans-api-io}"/>
(-)a/openide.io/apichanges.xml (+18 lines)
Lines 107-112 Link Here
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
108
109
<changes>
109
<changes>
110
    <change id="BridgingIOProvider">
111
      <api name="io"/>
112
      <summary>Create a provider abstract class that implements new I/O SPI</summary>
113
      <version major="1" minor="47"/>
114
      <date day="22" month="10" year="2014"/>
115
      <author login="jhavlin"/>
116
      <compatibility addition="yes" binary="compatible" semantic="compatible" />
117
      <description>
118
          <p>
119
              As new API and SPI for output windows has been introduced, it is
120
              useful to have a convenient way for implementators of the original
121
              API to support the new API as well. The BridgingIOProvider class
122
              implements both SPIs, and its JavaDoc explains how to use it.
123
          </p>
124
      </description>
125
      <class package="org.openide.windows" name="BridgingIOProvider"/>
126
      <issue number="247404" />
127
    </change>
110
    <change id="enhancedFoldHandleApi">
128
    <change id="enhancedFoldHandleApi">
111
      <api name="io"/>
129
      <api name="io"/>
112
      <summary>Created new user-friendly methods for working with FoldHandle instances.</summary>
130
      <summary>Created new user-friendly methods for working with FoldHandle instances.</summary>
(-)a/openide.io/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.io
2
OpenIDE-Module: org.openide.io
3
OpenIDE-Module-Specification-Version: 1.46
3
OpenIDE-Module-Specification-Version: 1.47
4
OpenIDE-Module-Localizing-Bundle: org/openide/io/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/openide/io/Bundle.properties
5
OpenIDE-Module-Recommends: org.openide.windows.IOProvider, org.openide.windows.IOContainer$Provider
5
OpenIDE-Module-Recommends: org.openide.windows.IOProvider, org.openide.windows.IOContainer$Provider
6
AutoUpdate-Essential-Module: true
6
AutoUpdate-Essential-Module: true
(-)a/openide.io/nbproject/org-openide-io.sig (-1 / +1 lines)
Lines 1-5 Link Here
1
#Signature file v4.1
1
#Signature file v4.1
2
#Version 1.45
2
#Version 1.44.1
3
3
4
CLSS public abstract interface java.io.Closeable
4
CLSS public abstract interface java.io.Closeable
5
intf java.lang.AutoCloseable
5
intf java.lang.AutoCloseable
(-)a/openide.io/nbproject/project.xml (-3 / +3 lines)
Lines 59-69 Link Here
59
                    </run-dependency>
59
                    </run-dependency>
60
                </dependency>
60
                </dependency>
61
                <dependency>
61
                <dependency>
62
                    <code-name-base>org.openide.util</code-name-base>
62
                    <code-name-base>org.netbeans.api.io</code-name-base>
63
                    <build-prerequisite/>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
64
                    <compile-dependency/>
65
                    <run-dependency>
65
                    <run-dependency>
66
                        <specification-version>9.0</specification-version>
66
                        <specification-version>1.0</specification-version>
67
                    </run-dependency>
67
                    </run-dependency>
68
                </dependency>
68
                </dependency>
69
                <dependency>
69
                <dependency>
Lines 71-77 Link Here
71
                    <build-prerequisite/>
71
                    <build-prerequisite/>
72
                    <compile-dependency/>
72
                    <compile-dependency/>
73
                    <run-dependency>
73
                    <run-dependency>
74
                        <specification-version>9.0</specification-version>
74
                        <specification-version>9.1</specification-version>
75
                    </run-dependency>
75
                    </run-dependency>
76
                </dependency>
76
                </dependency>
77
                <dependency>
77
                <dependency>
(-)a/openide.io/src/org/openide/windows/BridgingIOProvider.java (+381 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.windows;
43
44
import java.awt.Color;
45
import java.io.IOException;
46
import java.io.Reader;
47
import java.util.ArrayDeque;
48
import java.util.Deque;
49
import java.util.EnumSet;
50
import java.util.Set;
51
import java.util.logging.Level;
52
import java.util.logging.Logger;
53
import javax.swing.Action;
54
import org.netbeans.api.io.Hyperlink;
55
import org.netbeans.api.io.OutputColor;
56
import org.netbeans.api.io.ShowOperation;
57
import org.netbeans.spi.io.Hyperlinks;
58
import org.netbeans.spi.io.InputOutputProvider;
59
import org.netbeans.spi.io.OutputColorType;
60
import org.netbeans.spi.io.OutputColors;
61
import org.netbeans.spi.io.Utilities;
62
import org.openide.util.Lookup;
63
import org.openide.util.lookup.ServiceProvider;
64
import org.openide.util.lookup.ServiceProviders;
65
import org.openide.windows.IOColors.OutputType;
66
import org.openide.windows.IOPosition.Position;
67
68
/**
69
 * Abstract class for easy support of {@link InputOutputProvider}, the SPI for
70
 * the new I/O API.
71
 * <p>
72
 * This class is useful if you have a custom implementation of Output Window,
73
 * which uses SPI contained in this module ({@link IOProvider} and related
74
 * interfaces), and want to your implementation also accessible via the new I/O
75
 * API in module api.io.
76
 * </p>
77
 * <p>
78
 * To start supporting the new API:
79
 * </p>
80
 * <ol>
81
 * <li>Add dependency on module api.io (I/O API ans SPI,
82
 * org.netbeans.api.io)</li>
83
 * <li>Make your I/O provider extend {@link BridgingIOProvider} instead of
84
 * {@link IOProvider}</li>
85
 * <li>Add {@link ServiceProvider} annotation for {@link InputOutputProvider},
86
 *   {@link ServiceProviders} will be needed to allow multiple services:
87
 * <pre>
88
 *
89
 *  &#64;ServiceProviders({
90
 *    &#64;ServiceProvider(service=IOProvider.class, position=900),
91
 *    &#64;ServiceProvider(service=InputOutputProvider.class, position=900)
92
 *  })
93
 * public final class MyIOProvider extends BridgingIOProvider { ... }
94
 * </pre>
95
 * </li>
96
 * <li>If needed, override some of the method to improve performance.</li>
97
 * </ol>
98
 *
99
 * @author jhavlin
100
 */
101
public abstract class BridgingIOProvider extends IOProvider
102
        implements InputOutputProvider<InputOutput, OutputWriter, Position, FoldHandle> {
103
104
    private static final Logger LOG
105
            = Logger.getLogger(BridgingIOProvider.class.getName());
106
107
    private final Deque<FoldHandle> foldStack = new ArrayDeque<FoldHandle>();
108
109
    @Override
110
    public InputOutput getIO(String name, boolean newIO, Lookup lookup) {
111
        Action[] actions = lookup.lookup(Action[].class);
112
        IOContainer container = lookup.lookup(IOContainer.class);
113
        if (container == null && actions == null) {
114
            return getIO(name, newIO);
115
        } else if (newIO) {
116
            if (container != null && actions != null) {
117
                return getIO(name, actions, container);
118
            } else if (actions != null) {
119
                return getIO(name, actions);
120
            } else {
121
                return getIO(name, new Action[0], container);
122
            }
123
        } else {
124
            return getIO(name, newIO, actions == null ? new Action[0] : actions,
125
                    container);
126
        }
127
    }
128
129
    @Override
130
    public Reader getIn(InputOutput io) {
131
        return io.getIn();
132
    }
133
134
    @Override
135
    public OutputWriter getOut(InputOutput io) {
136
        return io.getOut();
137
    }
138
139
    @Override
140
    public OutputWriter getErr(InputOutput io) {
141
        return io.getErr();
142
    }
143
144
    @Override
145
    public void print(InputOutput io, OutputWriter writer, String text,
146
            Hyperlink link, OutputColor outputColor, boolean printLineEnd) {
147
148
        Color awtColor = outputColorToAwtColor(io, outputColor);
149
        OutputListener listener = hyperlinkToOutputListener(link);
150
        boolean listenerImportant = link != null && Hyperlinks.isImportant(link);
151
        try {
152
            if (printLineEnd && outputColor == null) {
153
                writer.println(text, listener, listenerImportant);
154
            } else if (printLineEnd && IOColorLines.isSupported(io)) {
155
                IOColorLines.println(io, text, listener, listenerImportant,
156
                        awtColor);
157
            } else if (IOColorPrint.isSupported(io)) {
158
                IOColorPrint.print(io, text, listener, listenerImportant,
159
                        awtColor);
160
                if (printLineEnd) {
161
                    writer.println();
162
                }
163
            } else if (printLineEnd) {
164
                writer.println(text);
165
            } else {
166
                writer.print(text);
167
            }
168
        } catch (IOException ex) {
169
            LOG.log(Level.FINE, "Cannot print color or hyperlink", ex); //NOI18N
170
        }
171
    }
172
173
    @Override
174
    public Lookup getIOLookup(InputOutput io) {
175
        if (io instanceof Lookup.Provider) {
176
            return ((Lookup.Provider) io).getLookup();
177
        } else {
178
            return Lookup.EMPTY;
179
        }
180
    }
181
182
    @Override
183
    public void resetIO(InputOutput io) {
184
        try {
185
            io.getOut().reset();
186
        } catch (IOException ex) {
187
            LOG.log(Level.FINE, "Cannot reset InputOutput.", ex);       //NOI18N
188
        }
189
    }
190
191
    @Override
192
    public void showIO(InputOutput io, OutputWriter writer,
193
            Set<ShowOperation> operations) {
194
        if (operations.contains(ShowOperation.OPEN)
195
                && operations.contains(ShowOperation.MAKE_VISIBLE)
196
                && operations.size() == 2) {
197
            io.select();
198
        } else {
199
            IOSelect.select(io, showOperationsToIoSelect(operations));
200
        }
201
    }
202
203
    /**
204
     * Translate set of {@link ShowOperation}s to set of
205
     * {@link IOSelect.AdditionalOperation}s.
206
     */
207
    private Set<IOSelect.AdditionalOperation> showOperationsToIoSelect(
208
            Set<ShowOperation> operations) {
209
        Set<IOSelect.AdditionalOperation> res
210
                = EnumSet.noneOf(IOSelect.AdditionalOperation.class);
211
        for (ShowOperation so : operations) {
212
            switch (so) {
213
                case OPEN:
214
                    res.add(IOSelect.AdditionalOperation.OPEN);
215
                    break;
216
                case MAKE_VISIBLE:
217
                    res.add(IOSelect.AdditionalOperation.REQUEST_VISIBLE);
218
                    break;
219
                case ACTIVATE:
220
                    res.add(IOSelect.AdditionalOperation.REQUEST_ACTIVE);
221
                    break;
222
            }
223
        }
224
        return res;
225
    }
226
227
    @Override
228
    public void closeIO(InputOutput io) {
229
        io.closeInputOutput();
230
    }
231
232
    @Override
233
    public boolean isIOClosed(InputOutput io) {
234
        return io.isClosed();
235
    }
236
237
    @Override
238
    public Position getCurrentPosition(InputOutput io, OutputWriter writer) {
239
        if (IOPosition.isSupported(io)) {
240
            return IOPosition.currentPosition(io);
241
        } else {
242
            return null;
243
        }
244
    }
245
246
    @Override
247
    public void scrollTo(InputOutput io, OutputWriter writer, Position position) {
248
        position.scrollTo();
249
    }
250
251
    @Override
252
    public FoldHandle startFold(InputOutput io, OutputWriter writer,
253
            boolean expanded) {
254
255
        if (IOFolding.isSupported(io)) {
256
            synchronized (foldStack) {
257
                if (foldStack.isEmpty()) {
258
                    foldStack.addLast(IOFolding.startFold(io, expanded));
259
                } else {
260
                    foldStack.addLast(foldStack.getLast().startFold(expanded));
261
                }
262
                return foldStack.getLast();
263
            }
264
        } else {
265
            return null;
266
        }
267
    }
268
269
    @Override
270
    public void endFold(InputOutput io, OutputWriter writer, FoldHandle fold) {
271
        synchronized (foldStack) {
272
            while (!foldStack.isEmpty()) {
273
                if (foldStack.removeLast() == fold) {
274
                    break;
275
                }
276
            }
277
            fold.silentFinish();
278
        }
279
    }
280
281
    @Override
282
    public void setFoldExpanded(InputOutput io, OutputWriter writer,
283
            FoldHandle fold, boolean expanded) {
284
        fold.setExpanded(expanded);
285
    }
286
287
    @Override
288
    public String getIODescription(InputOutput io) {
289
        if (IOTab.isSupported(io)) {
290
            return IOTab.getToolTipText(io);
291
        } else {
292
            return null;
293
        }
294
    }
295
296
    @Override
297
    public void setIODescription(InputOutput io, String description) {
298
        if (IOTab.isSupported(io)) {
299
            IOTab.setToolTipText(io, description);
300
        }
301
    }
302
303
    /**
304
     * Convert a hyperlink to an output listener.
305
     *
306
     * @param link The hyperlink.
307
     * @return The wrapping output listener.
308
     */
309
    private static OutputListener hyperlinkToOutputListener(
310
            final Hyperlink link) {
311
312
        if (link == null) {
313
            return null;
314
        }
315
        switch (Hyperlinks.getType(link)) {
316
            case FOR_URI:
317
                return new OutputListenerAdapter() {
318
                    @Override
319
                    public void outputLineAction(OutputEvent ev) {
320
                        Hyperlinks.getRunnable(link).run();
321
                    }
322
                };
323
            case ON_CLICK:
324
                return new OutputListenerAdapter() {
325
                    @Override
326
                    public void outputLineAction(OutputEvent ev) {
327
                        Utilities.handleUri(Hyperlinks.getURI(link));
328
                    }
329
                };
330
            default:
331
                return null;
332
        }
333
    }
334
335
    /**
336
     * Convert AWT-independent {@link OutputColor} to {@link java.awt.Color}.
337
     *
338
     * @return Appropriate color, or null if default color should be used.
339
     */
340
    private static Color outputColorToAwtColor(InputOutput io,
341
            OutputColor color) {
342
343
        if (color == null) {
344
            return null;
345
        }
346
        OutputColorType type = OutputColors.getType(color);
347
        if (type == OutputColorType.RGB) {
348
            return new Color(OutputColors.getRGB(color));
349
        } else if (IOColors.isSupported(io)) {
350
            switch (type) {
351
                case DEBUG:
352
                    return IOColors.getColor(io, OutputType.LOG_DEBUG);
353
                case FAILURE:
354
                    return IOColors.getColor(io, OutputType.LOG_FAILURE);
355
                case WARNING:
356
                    return IOColors.getColor(io, OutputType.LOG_WARNING);
357
                case SUCCESS:
358
                    return IOColors.getColor(io, OutputType.LOG_SUCCESS);
359
                default:
360
                    return null;
361
            }
362
        } else {
363
            return null;
364
        }
365
    }
366
367
    private static class OutputListenerAdapter implements OutputListener {
368
369
        @Override
370
        public void outputLineSelected(OutputEvent ev) {
371
        }
372
373
        @Override
374
        public void outputLineAction(OutputEvent ev) {
375
        }
376
377
        @Override
378
        public void outputLineCleared(OutputEvent ev) {
379
        }
380
    }
381
}
(-)a/utilities/nbproject/project.xml (+8 lines)
Lines 50-55 Link Here
50
            <code-name-base>org.netbeans.modules.utilities</code-name-base>
50
            <code-name-base>org.netbeans.modules.utilities</code-name-base>
51
            <module-dependencies>
51
            <module-dependencies>
52
                <dependency>
52
                <dependency>
53
                    <code-name-base>org.netbeans.api.io</code-name-base>
54
                    <build-prerequisite/>
55
                    <compile-dependency/>
56
                    <run-dependency>
57
                        <specification-version>1.0</specification-version>
58
                    </run-dependency>
59
                </dependency>
60
                <dependency>
53
                    <code-name-base>org.netbeans.modules.queries</code-name-base>
61
                    <code-name-base>org.netbeans.modules.queries</code-name-base>
54
                    <build-prerequisite/>
62
                    <build-prerequisite/>
55
                    <compile-dependency/>
63
                    <compile-dependency/>
(-)a/utilities/src/org/netbeans/modules/openfile/OutputWindowFileUriHandler.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.modules.openfile;
43
44
import java.net.MalformedURLException;
45
import java.net.URI;
46
import java.util.regex.Matcher;
47
import java.util.regex.Pattern;
48
import org.netbeans.spi.io.hyperlink.OpenUriHandler;
49
import org.openide.filesystems.FileObject;
50
import org.openide.filesystems.URLMapper;
51
import org.openide.util.lookup.ServiceProvider;
52
53
/**
54
 * Handler for file URIs clicked in the Output Windows.
55
 *
56
 * @author jhavlin
57
 */
58
@ServiceProvider(service = OpenUriHandler.class, position = 100)
59
public class OutputWindowFileUriHandler implements OpenUriHandler {
60
61
    private static final Pattern LINE_NUM_PAT
62
            = Pattern.compile("line=(\\d+)");                           //NOI18N
63
64
    @Override
65
    public boolean handle(URI uri) {
66
        if ("file".equals(uri.getScheme())) {                           //NOI18N
67
            int line = getLineNumber(uri);
68
            try {
69
                FileObject fo = URLMapper.findFileObject(uri.toURL());
70
                if (fo != null && fo.isData()) {
71
                    OpenFile.open(fo, line);
72
                    return true;
73
                } else {
74
                    return false;
75
                }
76
            } catch (MalformedURLException ex) {
77
                return false;
78
            }
79
        } else {
80
            return false;
81
        }
82
    }
83
84
    static int getLineNumber(URI uri) {
85
        String str = uri.getQuery();
86
        if (str == null) {
87
            return -1;
88
        }
89
        String[] params = str.split("&");                               //NOI18N
90
        for (String param : params) {
91
            Matcher m = LINE_NUM_PAT.matcher(param);
92
            if (m.matches()) {
93
                String lineStr = m.group(1);
94
                try {
95
                    return Integer.parseInt(lineStr);
96
                } catch (NumberFormatException ex) {
97
                    // keep trying
98
                }
99
            }
100
        }
101
        return -1;
102
    }
103
}
(-)a/utilities/test/unit/src/org/netbeans/modules/openfile/OutputWindowFileUriHandlerTest.java (+65 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.modules.openfile;
43
44
import java.net.URI;
45
import java.net.URISyntaxException;
46
import static junit.framework.Assert.assertEquals;
47
import org.junit.Test;
48
49
import static org.netbeans.modules.openfile.OutputWindowFileUriHandler.getLineNumber;
50
51
/**
52
 *
53
 * @author jhavlin
54
 */
55
public class OutputWindowFileUriHandlerTest {
56
57
    @Test
58
    public void testGetLineNumber() throws URISyntaxException {
59
        assertEquals(10, getLineNumber(new URI("file://x?line=10")));
60
        assertEquals(20, getLineNumber(new URI("file://x?a=b&line=20&r=1")));
61
        assertEquals(-1, getLineNumber(new URI("file://x?Xline=20")));
62
        assertEquals(-1, getLineNumber(new URI("file://x?line=a")));
63
        assertEquals(-1, getLineNumber(new URI("file://x")));
64
    }
65
}

Return to bug 247404