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 (+1180 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
            You will very likely also want to declare
440
        </p>
441
        <pre>OpenIDE-Module-Requires: org.netbeans.api.io.IOProvider</pre>
442
        <p>to ensure that an Output Window implementation is in fact enabled.</p>
443
    </answer>
444
445
446
447
    <!--
448
        <question id="deploy-jar" when="impl">
449
            Do you deploy just module JAR file(s) or other files as well?
450
            <hint>
451
            Usually a module consist of one JAR file (perhaps with Class-Path
452
            extensions) and also a configuration file that enables it. If you
453
            have any other files, use
454
            &lt;api group="java.io.File" name="yourname" type="export" category="friend"&gt;...&lt;/api&gt;
455
            to define the location, name and stability of your files (of course
456
            changing "yourname" and "friend" to suit your needs).
457
458
                If it uses more than one JAR, describe where they are located, how
459
                they refer to each other.
460
                If it consist of module JAR(s) and other files, please describe
461
                what is their purpose, why other files are necessary. Please
462
                make sure that installation/uninstallation leaves the system
463
                in state as it was before installation.
464
                </hint>
465
            </question>
466
    -->
467
    <answer id="deploy-jar">
468
        <p>
469
            Just the module JAR.
470
        </p>
471
    </answer>
472
473
474
475
    <!--
476
            <question id="deploy-nbm" when="impl">
477
                Can you deploy an NBM via the Update Center?
478
                <hint>
479
                If not why?
480
                </hint>
481
            </question>
482
    -->
483
    <answer id="deploy-nbm">
484
        <p>
485
            Yes.
486
        </p>
487
    </answer>
488
489
490
491
    <!--
492
        <question id="deploy-packages" when="init">
493
            Are packages of your module made inaccessible by not declaring them
494
            public?
495
496
                <hint>
497
                By default NetBeans build harness treats all packages are private.
498
                If you export some of them - either as public or friend packages,
499
                you should have a reason. If the reason is described elsewhere
500
                in this document, you can ignore this question.
501
                </hint>
502
            </question>
503
    -->
504
    <answer id="deploy-packages">
505
        <p>
506
            No; only API classes are public.
507
        </p>
508
    </answer>
509
510
511
512
    <!--
513
            <question id="deploy-shared" when="final">
514
                Do you need to be installed in the shared location only, or in the user directory only,
515
                or can your module be installed anywhere?
516
                <hint>
517
                Installation location shall not matter, if it does explain why.
518
                Consider also whether <code>InstalledFileLocator</code> can help.
519
                </hint>
520
            </question>
521
    -->
522
    <answer id="deploy-shared">
523
        <p>
524
            Anywhere.
525
        </p>
526
    </answer>
527
528
529
530
    <!--
531
        <question id="exec-ant-tasks" when="impl">
532
            Do you define or register any ant tasks that other can use?
533
534
                <hint>
535
                If you provide an ant task that users can use, you need to be very
536
                careful about its syntax and behaviour, as it most likely forms an
537
                      API for end users and as there is a lot of end users, their reaction
538
                when such API gets broken can be pretty strong.
539
                </hint>
540
            </question>
541
    -->
542
    <answer id="exec-ant-tasks">
543
        <p>
544
            No.
545
        </p>
546
    </answer>
547
548
549
550
    <!--
551
            <question id="exec-classloader" when="impl">
552
                Does your code create its own class loader(s)?
553
                <hint>
554
                A bit unusual. Please explain why and what for.
555
                </hint>
556
            </question>
557
    -->
558
    <answer id="exec-classloader">
559
        <p>
560
            No.
561
        </p>
562
    </answer>
563
564
565
566
    <!--
567
        <question id="exec-component" when="impl">
568
            Is execution of your code influenced by any (string) property
569
            of any of your components?
570
571
                <hint>
572
                Often <code>JComponent.getClientProperty</code>, <code>Action.getValue</code>
573
                or <code>PropertyDescriptor.getValue</code>, etc. are used to influence
574
                a behavior of some code. This of course forms an interface that should
575
                be documented. Also if one depends on some interface that an object
576
                implements (<code>component instanceof Runnable</code>) that forms an
577
                API as well.
578
                </hint>
579
            </question>
580
    -->
581
    <answer id="exec-component">
582
        <p>
583
            No.
584
        </p>
585
    </answer>
586
587
588
589
    <!--
590
            <question id="exec-introspection" when="impl">
591
                Does your module use any kind of runtime type information (<code>instanceof</code>,
592
                work with <code>java.lang.Class</code>, etc.)?
593
                <hint>
594
                Check for cases when you have an object of type A and you also
595
                expect it to (possibly) be of type B and do some special action. That
596
                should be documented. The same applies on operations in meta-level
597
                (Class.isInstance(...), Class.isAssignableFrom(...), etc.).
598
                </hint>
599
            </question>
600
    -->
601
    <answer id="exec-introspection">
602
        <p>
603
            No.
604
        </p>
605
    </answer>
606
607
608
609
    <!--
610
            <question id="exec-privateaccess" when="final">
611
                Are you aware of any other parts of the system calling some of 
612
                your methods by reflection?
613
                <hint>
614
                If so, describe the "contract" as an API. Likely private or friend one, but
615
                still API and consider rewrite of it.
616
                </hint>
617
            </question>
618
    -->
619
    <answer id="exec-privateaccess">
620
        <p>
621
            No.
622
        </p>
623
    </answer>
624
625
626
627
    <!--
628
            <question id="exec-process" when="impl">
629
                Do you execute an external process from your module? How do you ensure
630
                that the result is the same on different platforms? Do you parse output?
631
                Do you depend on result code?
632
                <hint>
633
                If you feed an input, parse the output please declare that as an API.
634
                </hint>
635
            </question>
636
    -->
637
    <answer id="exec-process">
638
        <p>
639
            No.
640
        </p>
641
    </answer>
642
643
644
645
    <!--
646
            <question id="exec-property" when="impl">
647
                Is execution of your code influenced by any environment or
648
                Java system (<code>System.getProperty</code>) property?
649
                On a similar note, is there something interesting that you
650
                pass to <code>java.util.logging.Logger</code>? Or do you observe
651
                what others log?
652
                <hint>
653
                If there is a property that can change the behavior of your 
654
                code, somebody will likely use it. You should describe what it does 
655
                and the <a href="http://wiki.netbeans.org/API_Stability">stability category</a>
656
                of this API. You may use
657
                <pre>
658
                    &lt;api type="export" group="property" name="id" category="private" url="http://..."&gt;
659
                        description of the property, where it is used, what it influence, etc.
660
                    &lt;/api&gt;
661
                </pre>
662
                </hint>
663
            </question>
664
    -->
665
    <answer id="exec-property">
666
        <p>
667
            No.
668
        </p>
669
    </answer>
670
671
672
673
    <!--
674
            <question id="exec-reflection" when="impl">
675
                Does your code use Java Reflection to execute other code?
676
                <hint>
677
                This usually indicates a missing or insufficient API in the other
678
                part of the system. If the other side is not aware of your dependency
679
                this contract can be easily broken.
680
                </hint>
681
            </question>
682
    -->
683
    <answer id="exec-reflection">
684
        <p>
685
            No.
686
        </p>
687
    </answer>
688
689
690
691
    <!--
692
            <question id="exec-threading" when="init">
693
                What threading models, if any, does your module adhere to? How the
694
                project behaves with respect to threading?
695
                <hint>
696
                    Is your API threadsafe? Can it be accessed from any threads or
697
                    just from some dedicated ones? Any special relation to AWT and
698
                    its Event Dispatch thread? Also
699
                    if your module calls foreign APIs which have a specific threading model,
700
                    indicate how you comply with the requirements for multithreaded access
701
                    (synchronization, mutexes, etc.) applicable to those APIs.
702
                    If your module defines any APIs, or has complex internal structures
703
                    that might be used from multiple threads, declare how you protect
704
                    data against concurrent access, race conditions, deadlocks, etc.,
705
                    and whether such rules are enforced by runtime warnings, errors, assertions, etc.
706
                    Examples: a class might be non-thread-safe (like Java Collections); might
707
                    be fully thread-safe (internal locking); might require access through a mutex
708
                    (and may or may not automatically acquire that mutex on behalf of a client method);
709
                    might be able to run only in the event queue; etc.
710
                    Also describe when any events are fired: synchronously, asynchronously, etc.
711
                    Ideas: <a href="http://core.netbeans.org/proposals/threading/index.html#recommendations">Threading Recommendations</a> (in progress)
712
                </hint>
713
            </question>
714
    -->
715
    <answer id="exec-threading">
716
        <p>
717
            Should be thread safe.
718
        </p>
719
    </answer>
720
721
722
723
<!--
724
        <question id="format-clipboard" when="impl">
725
            Which data flavors (if any) does your code read from or insert to
726
            the clipboard (by access to clipboard on means calling methods on <code>java.awt.datatransfer.Transferable</code>?
727
728
                <hint>
729
                Often Node's deal with clipboard by usage of <code>Node.clipboardCopy, Node.clipboardCut and Node.pasteTypes</code>.
730
                Check your code for overriding these methods.
731
                </hint>
732
            </question>
733
    -->
734
    <answer id="format-clipboard">
735
        <p>
736
            Plain Unicode text only.
737
        </p>
738
    </answer>
739
740
741
742
    <!--
743
            <question id="format-dnd" when="impl">
744
                Which protocols (if any) does your code understand during Drag &amp; Drop?
745
                <hint>
746
                Often Node's deal with clipboard by usage of <code>Node.drag, Node.getDropType</code>. 
747
                Check your code for overriding these methods. Btw. if they are not overridden, they
748
                by default delegate to <code>Node.clipboardCopy, Node.clipboardCut and Node.pasteTypes</code>.
749
                </hint>
750
            </question>
751
    -->
752
    <answer id="format-dnd">
753
        <p>
754
            N/A
755
        </p>
756
    </answer>
757
758
759
760
    <!--
761
        <question id="format-types" when="impl">
762
            Which protocols and file formats (if any) does your module read or write on disk,
763
            or transmit or receive over the network? Do you generate an ant build script?
764
            Can it be edited and modified?
765
766
            <hint>
767
                <p>
768
                Files can be read and written by other programs, modules and users. If they influence
769
                your behaviour, make sure you either document the format or claim that it is a private
770
                api (using the &lt;api&gt; tag).
771
                </p>
772
                <p>
773
                If you generate an ant build file, this is very likely going to be seen by end users and
774
                they will be attempted to edit it. You should be ready for that and provide here a link
775
                to documentation that you have for such purposes and also describe how you are going to
776
                understand such files during next release, when you (very likely) slightly change the 
777
                format.
778
                </p>
779
            </hint>
780
        </question>
781
    -->
782
    <answer id="format-types">
783
        <p>
784
            None.
785
        </p>
786
    </answer>
787
788
789
790
    <!--
791
        <question id="lookup-lookup" when="init">
792
            Does your module use <code>org.openide.util.Lookup</code>
793
            or any similar technology to find any components to communicate with? Which ones?
794
795
                <hint>
796
                NetBeans is build around a generic registry of services called
797
                lookup. It is preferable to use it for registration and discovery
798
                if possible. See
799
                <a href="http://www.netbeans.org/download/dev/javadoc/org-openide-util/org/openide/util/lookup/doc-files/index.html">
800
                The Solution to Comunication Between Components
801
                </a>. If you do not plan to use lookup and insist usage
802
                of other solution, then please describe why it is not working for
803
                you.
804
                <br/>
805
                When filling the final version of your arch document, please
806
                describe the interfaces you are searching for, where 
807
                are defined, whether you are searching for just one or more of them,
808
                if the order is important, etc. Also classify the stability of such
809
                API contract. Use &lt;api group=&amp;lookup&amp; /&gt; tag, so
810
                your information gets listed in the summary page of your javadoc.
811
                </hint>
812
            </question>
813
    -->
814
    <answer id="lookup-lookup">
815
        <p>
816
            <code>IOProvider.getDefault()</code> asks lookup for the first instance
817
            of <code>InputOutputProvider</code>. This is normally provided by
818
            <code>org.netbeans.core.output2</code>.
819
        </p>
820
    </answer>
821
822
823
824
    <!--
825
            <question id="lookup-register" when="final">
826
                Do you register anything into lookup for other code to find?
827
                <hint>
828
                Do you register using layer file or using a declarative annotation such as <code>@ServiceProvider</code>?
829
                Who is supposed to find your component?
830
                </hint>
831
            </question>
832
    -->
833
    <answer id="lookup-register">
834
        <p>
835
            No.
836
        </p>
837
    </answer>
838
839
840
841
    <!--
842
            <question id="lookup-remove" when="final">
843
                Do you remove entries of other modules from lookup?
844
                <hint>
845
                Why? Of course, that is possible, but it can be dangerous. Is the module
846
                your are masking resource from aware of what you are doing?
847
                </hint>
848
            </question>
849
    -->
850
    <answer id="lookup-remove">
851
        <p>
852
            No.
853
        </p>
854
    </answer>
855
856
857
858
    <!--
859
            <question id="perf-exit" when="final">
860
                Does your module run any code on exit?
861
            </question>
862
    -->
863
    <answer id="perf-exit">
864
        <p>
865
            No.
866
        </p>
867
    </answer>
868
869
870
871
    <!--
872
            <question id="perf-huge_dialogs" when="final">
873
                Does your module contain any dialogs or wizards with a large number of
874
                GUI controls such as combo boxes, lists, trees, or text areas?
875
            </question>
876
    -->
877
    <answer id="perf-huge_dialogs">
878
        <p>
879
            No.
880
        </p>
881
    </answer>
882
883
884
885
    <!--
886
            <question id="perf-limit" when="init">
887
                Are there any hard-coded or practical limits in the number or size of
888
                elements your code can handle?
889
                <hint>
890
                    Most of algorithms have increasing memory and speed complexity
891
                    with respect to size of data they operate on. What is the critical
892
                    part of your project that can be seen as a bottleneck with
893
                    respect to speed or required memory? What are the practical
894
                    sizes of data you tested your project with? What is your estimate
895
                    of potential size of data that would cause visible performance
896
                    problems? Is there some kind of check to detect such situation
897
                    and prevent "hard" crashes - for example the CloneableEditorSupport
898
                    checks for size of a file to be opened in editor
899
                    and if it is larger than 1Mb it shows a dialog giving the
900
                    user the right to decide - e.g. to cancel or commit suicide.
901
                </hint>
902
            </question>
903
    -->
904
    <answer id="perf-limit">
905
        <p>
906
            No.
907
        </p>
908
    </answer>
909
910
911
912
    <!--
913
            <question id="perf-mem" when="final">
914
                How much memory does your component consume? Estimate
915
                with a relation to the number of windows, etc.
916
            </question>
917
    -->
918
    <answer id="perf-mem">
919
        <p>
920
            N/A
921
        </p>
922
    </answer>
923
924
925
926
    <!--
927
            <question id="perf-menus" when="final">
928
                Does your module use dynamically updated context menus, or
929
                context-sensitive actions with complicated and slow enablement logic?
930
                <hint>
931
                    If you do a lot of tricks when adding actions to regular or context menus, you can significantly
932
                    slow down display of the menu, even when the user is not using your action. Pay attention to
933
                    actions you add to the main menu bar, and to context menus of foreign nodes or components. If
934
                    the action is conditionally enabled, or changes its display dynamically, you need to check the
935
                    impact on performance. In some cases it may be more appropriate to make a simple action that is
936
                    always enabled but does more detailed checks in a dialog if it is actually run.
937
                </hint>
938
            </question>
939
    -->
940
    <answer id="perf-menus">
941
        <p>
942
            No.
943
        </p>
944
    </answer>
945
946
947
948
    <!--
949
        <question id="perf-progress" when="final">
950
            Does your module execute any long-running tasks?
951
952
                <hint>Long running tasks should never block
953
                AWT thread as it badly hurts the UI
954
                <a href="http://performance.netbeans.org/responsiveness/issues.html">
955
                responsiveness</a>.
956
                Tasks like connecting over
957
                network, computing huge amount of data, compilation
958
                be done asynchronously (for example
959
                using <code>RequestProcessor</code>), definitively it should
960
                not block AWT thread.
961
                </hint>
962
            </question>
963
    -->
964
    <answer id="perf-progress">
965
        <p>
966
            No.
967
        </p>
968
    </answer>
969
970
971
972
    <!--
973
            <question id="perf-scale" when="init">
974
                Which external criteria influence the performance of your
975
                program (size of file in editor, number of files in menu,
976
                in source directory, etc.) and how well your code scales?
977
                <hint>
978
                Please include some estimates, there are other more detailed
979
                questions to answer in later phases of implementation.`
980
                </hint>
981
            </question>
982
    -->
983
    <answer id="perf-scale">
984
        <p>
985
            Scalability in GUI speed and memory consumption is probably limited
986
            only by the Output Window implementation.
987
        </p>
988
    </answer>
989
990
991
992
    <!--
993
            <question id="perf-spi" when="init">
994
                How the performance of the plugged in code will be enforced?
995
                <hint>
996
                If you allow foreign code to be plugged into your own module, how
997
                do you enforce that it will behave correctly and quickly and will not
998
                negatively influence the performance of your own module?
999
                </hint>
1000
            </question>
1001
    -->
1002
    <answer id="perf-spi">
1003
        <p>
1004
            No special behavior.
1005
        </p>
1006
    </answer>
1007
1008
1009
1010
    <!--
1011
            <question id="perf-startup" when="final">
1012
                Does your module run any code on startup?
1013
            </question>
1014
    -->
1015
    <answer id="perf-startup">
1016
        <p>
1017
            No.
1018
        </p>
1019
    </answer>
1020
1021
1022
1023
    <!--
1024
            <question id="perf-wakeup" when="final">
1025
                Does any piece of your code wake up periodically and do something
1026
                even when the system is otherwise idle (no user interaction)?
1027
            </question>
1028
    -->
1029
    <answer id="perf-wakeup">
1030
        <p>
1031
            No.
1032
        </p>
1033
    </answer>
1034
1035
1036
1037
    <!--
1038
        <question id="resources-file" when="final">
1039
            Does your module use <code>java.io.File</code> directly?
1040
1041
                <hint>
1042
                NetBeans provide a logical wrapper over plain files called
1043
                <code>org.openide.filesystems.FileObject</code> that
1044
                provides uniform access to such resources and is the preferred
1045
                way that should be used. But of course there can be situations when
1046
                this is not suitable.
1047
                </hint>
1048
            </question>
1049
    -->
1050
    <answer id="resources-file">
1051
        <p>
1052
            No, but the implementation may.
1053
        </p>
1054
    </answer>
1055
1056
1057
1058
    <!--
1059
        <question id="resources-layer" when="final">
1060
            Does your module provide own layer? Does it create any files or
1061
            folders in it? What it is trying to communicate by that and with which 
1062
            components?
1063
1064
                <hint>
1065
                NetBeans allows automatic and declarative installation of resources 
1066
                by module layers. Module register files into appropriate places
1067
                and other components use that information to perform their task
1068
                (build menu, toolbar, window layout, list of templates, set of
1069
                options, etc.).
1070
                </hint>
1071
            </question>
1072
    -->
1073
    <answer id="resources-layer">
1074
        <p>
1075
            No.
1076
        </p>
1077
    </answer>
1078
1079
1080
1081
    <!--
1082
        <question id="resources-mask" when="final">
1083
            Does your module mask/hide/override any resources provided by other modules in
1084
            their layers?
1085
1086
                <hint>
1087
                If you mask a file provided by another module, you probably depend
1088
                on that and do not want the other module to (for example) change
1089
                the file's name. That module shall thus make that file available as an API
1090
                of some stability category.
1091
                </hint>
1092
            </question>
1093
    -->
1094
    <answer id="resources-mask">
1095
        <p>
1096
            No.
1097
        </p>
1098
    </answer>
1099
1100
1101
1102
    <!--
1103
            <question id="resources-preferences" when="final">
1104
                Does your module uses preferences via Preferences API? Does your module use NbPreferences or
1105
                or regular JDK Preferences ? Does it read, write or both ?
1106
                Does it share preferences with other modules ? If so, then why ?
1107
                <hint>
1108
                    You may use
1109
                        &lt;api type="export" group="preferences"
1110
                        name="preference node name" category="private"&gt;
1111
                        description of individual keys, where it is used, what it
1112
                        influences, whether the module reads/write it, etc.
1113
                        &lt;/api&gt;
1114
                    Due to XML ID restrictions, rather than /org/netbeans/modules/foo give the "name" as org.netbeans.modules.foo.
1115
                    Note that if you use NbPreferences this name will then be the same as the code name base of the module.
1116
                </hint>
1117
            </question>
1118
    -->
1119
    <answer id="resources-preferences">
1120
        <p>
1121
            No.
1122
        </p>
1123
    </answer>
1124
1125
1126
1127
    <!--
1128
        <question id="resources-read" when="final">
1129
            Does your module read any resources from layers? For what purpose?
1130
1131
                <hint>
1132
                As this is some kind of intermodule dependency, it is a kind of API.
1133
                Please describe it and classify according to
1134
                <a href="http://wiki.netbeans.org/API_Design#What_is_an_API.3F">
1135
                common stability categories</a>.
1136
                </hint>
1137
            </question>
1138
    -->
1139
    <answer id="resources-read">
1140
        <p>
1141
            No.
1142
        </p>
1143
    </answer>
1144
1145
1146
1147
    <!--
1148
            <question id="security-grant" when="final">
1149
                Does your code grant additional rights to some other code?
1150
                <hint>Avoid using a class loader that adds extra
1151
                permissions to loaded code unless really necessary.
1152
                Also note that your API implementation
1153
                can also expose unneeded permissions to enemy code by
1154
                calling AccessController.doPrivileged().</hint>
1155
            </question>
1156
    -->
1157
    <answer id="security-grant">
1158
        <p>
1159
            No.
1160
        </p>
1161
    </answer>
1162
1163
1164
1165
    <!--
1166
            <question id="security-policy" when="final">
1167
                Does your functionality require modifications to the standard policy file?
1168
                <hint>Your code might pass control to third-party code not
1169
                coming from trusted domains. This could be code downloaded over the
1170
                network or code coming from libraries that are not bundled
1171
                with NetBeans. Which permissions need to be granted to which domains?</hint>
1172
            </question>
1173
    -->
1174
    <answer id="security-policy">
1175
        <p>
1176
            No.
1177
        </p>
1178
    </answer>
1179
1180
</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
(-)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 wrinting 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 (+128 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
 * @author jhavlin
51
 */
52
public abstract class Fold {
53
54
    static final Fold UNSUPPORTED = new Fold() {
55
56
        @Override
57
        public void setExpanded(boolean expanded) {
58
        }
59
60
        @Override
61
        int getFoldNumber() {
62
            return -1;
63
        }
64
    };
65
66
    private Fold() {
67
    }
68
69
    static <IO, OW extends PrintWriter> Fold create(
70
            InputOutputProvider<IO, OW> provider, IO io, OW writer,
71
            int foldNumber) {
72
        if (foldNumber < 0) {
73
            return UNSUPPORTED;
74
        } else {
75
            return new Impl<IO, OW>(provider, io, writer, foldNumber);
76
        }
77
    }
78
79
    /**
80
     * Set fold expansion state.
81
     *
82
     * @param expanded True to expand the fold, false to collapse it.
83
     */
84
    public abstract void setExpanded(boolean expanded);
85
86
    abstract int getFoldNumber();
87
88
    /**
89
     * Expand the fold.
90
     */
91
    public final void expad() {
92
        setExpanded(true);
93
    }
94
95
    /**
96
     * Collapse the fold.
97
     */
98
    public final void collapse() {
99
        setExpanded(false);
100
    }
101
102
    private static class Impl<IO, OW extends PrintWriter> extends Fold {
103
104
        private final InputOutputProvider<IO, OW> provider;
105
        private final IO io;
106
        private final OW writer;
107
        private final int foldNumber;
108
109
        public Impl(InputOutputProvider<IO, OW> provider, IO io, OW writer,
110
                int foldNumber) {
111
112
            this.provider = provider;
113
            this.io = io;
114
            this.writer = writer;
115
            this.foldNumber = foldNumber;
116
        }
117
118
        @Override
119
        public void setExpanded(boolean expanded) {
120
            provider.setFoldExpanded(io, writer, foldNumber, expanded);
121
        }
122
123
        @Override
124
        int getFoldNumber() {
125
            return foldNumber;
126
        }
127
    }
128
}
(-)a/api.io/src/org/netbeans/api/io/Hyperlink.java (+224 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.api.annotations.common.NullUnknown;
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
    /**
64
     * Check whether the hyperlink was created for a URI, and thus
65
     * {@link #getURI()} will return a non-null value.
66
     *
67
     * @return Value true if the hyperlink was created using
68
     * {@link #forURI(java.net.URI)} or {@link #forURI(java.net.URI, boolean)}
69
     * method, false otherwise.
70
     */
71
    public abstract boolean isForURI();
72
73
    /**
74
     * Check whether the hyperlink was created for a runnable, and thus
75
     * {@link #getRunnable() ()} will return a non-null value.
76
     *
77
     * @return Value true if the hyperlink was created using
78
     * {@link #onClick(java.lang.Runnable)} or
79
     * {@link #forURI(java.net.URI, boolean)} method, false otherwise.
80
     */
81
    public abstract boolean isOnClick();
82
83
    /**
84
     * Get the URI.
85
     *
86
     * @return A URI when the hyperlink was created for a URI, null otherwise.
87
     * @see #isForURI()
88
     */
89
    @NullUnknown
90
    public abstract URI getURI();
91
92
    /**
93
     * Get the runnable.
94
     *
95
     * @return A runnable when the hyperlink was created for a runnable, null
96
     * otherwise.
97
     * @see #isOnClick()
98
     */
99
    @NullUnknown
100
    public abstract Runnable getRunnable();
101
102
    /**
103
     * @return True if the hyperlink has been marked as important, false if it
104
     * is a standard link.
105
     */
106
    public boolean isImportant() {
107
        return important;
108
    }
109
110
    /**
111
     * Create a new hyperlink for specified URI.
112
     *
113
     * @param uri Hyperlink targed.
114
     *
115
     * @return The new hyperlink.
116
     */
117
    @NonNull
118
    public static Hyperlink forURI(@NonNull URI uri) {
119
        return forURI(uri, false);
120
    }
121
122
    /**
123
     * Create a new hyperlink for specified {@link Runnable}, which will be
124
     * invoked when the line is clicked.
125
     *
126
     * @param runnable The runnable to run on click.
127
     * @return The new hyperlink.
128
     */
129
    @NonNull
130
    public static Hyperlink onClick(@NonNull Runnable runnable) {
131
        return onClick(runnable, false);
132
    }
133
134
    /**
135
     * Create a new hyperlink for specified URI.
136
     *
137
     * @param uri Hyperlink targed.
138
     * @param important True if the hyperlink should be handled as an important
139
     * one, false if it is a standard one.
140
     *
141
     * @return The new hyperlink.
142
     */
143
    @NonNull
144
    public static Hyperlink forURI(@NonNull URI uri, boolean important) {
145
        Parameters.notNull("uri", uri);
146
        return new UriHyperlink(uri, important);
147
    }
148
149
    /**
150
     * Create a new hyperlink for specified {@link Runnable}, which will be
151
     * invoked when the line is clicked.
152
     *
153
     * @param runnable The runnable to run on click.
154
     * @param important True if the hyperlink should be handled as an important
155
     * one, false if it is a standard one.
156
     * @return The new hyperlink.
157
     */
158
    @NonNull
159
    public static Hyperlink onClick(@NonNull Runnable runnable,
160
            boolean important) {
161
        Parameters.notNull("runnable", runnable);
162
        return new OnClickHyperlink(runnable, important);
163
    }
164
165
    private static class OnClickHyperlink extends Hyperlink {
166
167
        private final Runnable runnable;
168
169
        public OnClickHyperlink(Runnable runnable, boolean important) {
170
            super(important);
171
            this.runnable = runnable;
172
        }
173
174
        @Override
175
        public boolean isForURI() {
176
            return false;
177
        }
178
179
        @Override
180
        public boolean isOnClick() {
181
            return true;
182
        }
183
184
        @Override
185
        public URI getURI() {
186
            return null;
187
        }
188
189
        @Override
190
        public Runnable getRunnable() {
191
            return this.runnable;
192
        }
193
    }
194
195
    private static class UriHyperlink extends Hyperlink {
196
197
        private final URI uri;
198
199
        public UriHyperlink(URI uri, boolean important) {
200
            super(important);
201
            this.uri = uri;
202
        }
203
204
        @Override
205
        public boolean isForURI() {
206
            return true;
207
        }
208
209
        @Override
210
        public boolean isOnClick() {
211
            return false;
212
        }
213
214
        @Override
215
        public URI getURI() {
216
            return this.uri;
217
        }
218
219
        @Override
220
        public Runnable getRunnable() {
221
            return null;
222
        }
223
    }
224
}
(-)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 org.netbeans.api.annotations.common.NonNull;
49
import org.netbeans.spi.io.InputOutputProvider;
50
import org.openide.util.Lookup;
51
import org.openide.util.Parameters;
52
53
/**
54
 * A factory for IO tabs shown in the output window. To create a new tab to
55
 * write to, call e.g.
56
 * <code>IOProvider.getDefault().getIO("MyTab", false)</code> (pass true if
57
 * there may be an existing tab with the same name and you want to write to a
58
 * new tab).
59
 *
60
 * @author Jesse Glick, Jaroslav Havlin
61
 */
62
public abstract class IOProvider {
63
64
    private IOProvider() {
65
    }
66
67
    /**
68
     * Get the default I/O provider.
69
     * <p>
70
     * Normally this is taken from {@link Lookup#getDefault} but if there is no
71
     * instance in lookup, a fallback instance is created which just uses the
72
     * standard system I/O streams. This is useful for unit tests and perhaps
73
     * for standalone usage of various libraries.
74
     * </p>
75
     *
76
     * @return The default instance (never null).
77
     */
78
    @NonNull
79
    public static IOProvider getDefault() {
80
        InputOutputProvider<?, ?> def
81
                = Lookup.getDefault().lookup(InputOutputProvider.class);
82
        if (def != null) {
83
            return wrapProvider(def);
84
        } else {
85
            return wrapProvider(new Trivial());
86
        }
87
    }
88
89
    private static <IO, OW extends PrintWriter, POS> IOProvider wrapProvider(
90
            InputOutputProvider<IO, OW> provider) {
91
92
        return new Impl<IO, OW>(provider);
93
    }
94
95
    /**
96
     * Gets IOProvider of selected name or delegates to getDefault() if none was
97
     * found.
98
     *
99
     * @param name ID of provider.
100
     * @return The instance corresponding to provided name or default instance
101
     * if not found.
102
     */
103
    @NonNull
104
    public static IOProvider get(@NonNull String name) {
105
        Parameters.notNull("name", name);
106
107
        @SuppressWarnings("rawtypes")
108
        Collection<? extends InputOutputProvider> providers
109
                = Lookup.getDefault().lookupAll(InputOutputProvider.class);
110
111
        for (InputOutputProvider<?, ?> p : providers) {
112
            if (p.getName().equals(name)) {
113
                return wrapProvider(p);
114
            }
115
        }
116
        return getDefault();
117
    }
118
119
    /**
120
     * Gets name (id) of provider.
121
     *
122
     * @return Name of this provider.
123
     */
124
    @NonNull
125
    public abstract String getName();
126
127
    /**
128
     * Get a named instance of InputOutput, which represents an output tab in
129
     * the output window. Streams for reading/writing can be accessed via
130
     * getters on the returned instance.
131
     *
132
     * @param name A localised display name for the tab.
133
     * @param newIO If <tt>true</tt>, a new <code>InputOutput</code> is
134
     * returned, else an existing <code>InputOutput</code> of the same name may
135
     * be returned.
136
     * @return An <code>InputOutput</code> instance for accessing the new tab.
137
     * @see InputOutput
138
     */
139
    @NonNull
140
    public abstract InputOutput getIO(@NonNull String name, boolean newIO);
141
142
    /**
143
     * Get a named instance of InputOutput, which represents an output tab in
144
     * the output window. Streams for reading/writing can be accessed via
145
     * getters on the returned instance.
146
     *
147
     * @param name A localised display name for the tab.
148
     * @param newIO If <tt>true</tt>, a new <code>InputOutput</code> is
149
     * returned, else an existing <code>InputOutput</code> of the same name may
150
     * be returned.
151
     * @param lookup Lookup which may contain additional information for various
152
     * implementations of output window.
153
     * @return An <code>InputOutput</code> instance for accessing the new tab.
154
     * @see InputOutput
155
     */
156
    @NonNull
157
    public abstract InputOutput getIO(@NonNull String name, boolean newIO,
158
            @NonNull Lookup lookup);
159
160
    /**
161
     * Implementation of IOProvider that uses {@link InputOutputProvider} SPI
162
     * internally.
163
     *
164
     * @param <IO>
165
     * @param <OW>
166
     * @param <POS>
167
     */
168
    private static class Impl<IO, OW extends PrintWriter> extends IOProvider {
169
170
        private final InputOutputProvider<IO, OW> impl;
171
172
        public Impl(InputOutputProvider<IO, OW> impl) {
173
            this.impl = impl;
174
        }
175
176
        @Override
177
        public String getName() {
178
            return impl.getName();
179
        }
180
181
        @Override
182
        public InputOutput getIO(String name, boolean newIO) {
183
            return getIO(name, newIO, Lookup.EMPTY);
184
        }
185
186
        @Override
187
        public InputOutput getIO(String name, boolean newIO, Lookup lookup) {
188
            Parameters.notNull("name", name);
189
            Parameters.notNull("lookup", lookup);
190
            return InputOutput.create(impl, impl.getIO(name, newIO, lookup));
191
        }
192
    }
193
194
    /**
195
     * Trivial implementation of {@link IOProvider} that uses system input,
196
     * output and error streams.
197
     */
198
    private static class Trivial implements InputOutputProvider<Object, PrintWriter> {
199
200
        @Override
201
        public String getName() {
202
            return "Trivial";
203
        }
204
205
        @Override
206
        public Object getIO(String name, boolean newIO, Lookup lookup) {
207
            return this;
208
        }
209
210
        @Override
211
        public Reader getIn(Object io) {
212
            return new InputStreamReader(System.in);
213
        }
214
215
        @Override
216
        public PrintWriter getOut(Object io) {
217
            return new PrintWriter(System.out);
218
        }
219
220
        @Override
221
        public PrintWriter getErr(Object io) {
222
            return new PrintWriter(System.err);
223
        }
224
225
        @Override
226
        public void print(Object io, PrintWriter writer, String text,
227
                Hyperlink link, OutputColor color, boolean printLineEnd) {
228
            writer.print(text);
229
            if (printLineEnd) {
230
                writer.println();
231
            }
232
        }
233
234
        @Override
235
        public Lookup getIOLookup(Object io) {
236
            return Lookup.EMPTY;
237
        }
238
239
        @Override
240
        public void resetIO(Object io) {
241
        }
242
243
        @Override
244
        public void selectIO(Object io, PrintWriter writer) {
245
        }
246
247
        @Override
248
        public void showIO(Object io, PrintWriter writer) {
249
        }
250
251
        @Override
252
        public void activateIO(Object io, PrintWriter writer) {
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 int getCurrentPosition(Object io, PrintWriter writer) {
266
            return -1;
267
        }
268
269
        @Override
270
        public void scrollTo(Object io, PrintWriter writer, int position) {
271
        }
272
273
        @Override
274
        public int startFold(Object io, PrintWriter writer, boolean expanded) {
275
            return -1;
276
        }
277
278
        @Override
279
        public void endFold(Object io, PrintWriter writer, int foldNumber) {
280
        }
281
282
        @Override
283
        public void setFoldExpanded(Object io, PrintWriter writer,
284
                int foldNumber, 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 (+270 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
 * @see OutputWriter
68
 * @author Ian Formanek, Jaroslav Tulach, Petr Hamernik, Ales Novak, Jan
69
 * Jancura, Jaroslav Havlin
70
 */
71
public abstract class InputOutput implements Lookup.Provider {
72
73
    private InputOutput() {
74
    }
75
76
    /**
77
     * Get a named instance of InputOutput from the default {@link IOProvider},
78
     * which represents an output tab in the output window. Streams for
79
     * reading/writing can be accessed via getters on the returned instance.
80
     *
81
     * <p>
82
     * This is a shorthand for {@code IOProvider.getDefault().getIO(...)}.
83
     * </p>
84
     *
85
     * @param name A localised display name for the tab.
86
     * @param newIO If <tt>true</tt>, a new <code>InputOutput</code> is
87
     * returned, else an existing <code>InputOutput</code> of the same name may
88
     * be returned.
89
     * @return An <code>InputOutput</code> instance for accessing the new tab.
90
     * @see IOProvider
91
     */
92
    @NonNull
93
    public static InputOutput get(@NonNull String name, boolean newIO) {
94
        return IOProvider.getDefault().getIO(name, newIO);
95
    }
96
97
     /**
98
     * Get a named instance of InputOutput from the default {@link IOProvider},
99
     * which represents an output tab in the output window. Streams for
100
     * reading/writing can be accessed via getters on the returned instance.
101
     *
102
     * <p>
103
     * This is a shorthand for {@code IOProvider.getDefault().getIO(...)}.
104
     * </p>
105
     *
106
     * @param name A localised display name for the tab.
107
     * @param newIO If <tt>true</tt>, a new <code>InputOutput</code> is
108
     * returned, else an existing <code>InputOutput</code> of the same name may
109
     * be returned.
110
     * @param lookup Lookup which may contain additional information for various
111
     * implementations of output window.
112
     * @return An <code>InputOutput</code> instance for accessing the new tab.
113
     * @see IOProvider
114
     */
115
    @NonNull
116
    public static InputOutput get(@NonNull String name, boolean newIO,
117
            @NonNull Lookup lookup) {
118
        return IOProvider.getDefault().getIO(name, newIO, lookup);
119
    }
120
121
    /**
122
     * Get a reader to read from the tab.
123
     *
124
     * @return The reader.
125
     */
126
    @NonNull
127
    public abstract Reader getIn();
128
129
    /**
130
     * Acquire an output writer to write to the tab.
131
     *
132
     * @return The writer.
133
     */
134
    @NonNull
135
    public abstract OutputWriter getOut();
136
137
    /**
138
     * Get an output writer to write to the tab in error mode. This might show
139
     * up in a different color than the regular output, e.g., or appear in a
140
     * separate pane.
141
     *
142
     * @return The writer.
143
     */
144
    @NonNull
145
    public abstract OutputWriter getErr();
146
147
    /**
148
     * Clear the output pane.
149
     */
150
    public abstract void reset();
151
152
    /**
153
     * Get lookup which may contain extensions provided by implementation of
154
     * output window.
155
     *
156
     * @return The lookup.
157
     */
158
    @NonNull
159
    @Override
160
    public abstract Lookup getLookup();
161
162
    /**
163
     * Closes this tab. The effect of calling any method on an instance of
164
     * InputOutput after calling <code>closeInputOutput()</code> on it is
165
     * undefined.
166
     */
167
    public abstract void closeInputOutput();
168
169
    /**
170
     * Test whether this tab has been closed, either by a call to
171
     * {@link #closeInputOutput()} or by the user closing the tab in the UI.
172
     *
173
     * @return Value <code>true</code> if it is closed.
174
     */
175
    public abstract boolean isClosed();
176
177
    /**
178
     * Get description of this I/O instance.
179
     *
180
     * @return The description, or null if not set.
181
     */
182
    @CheckForNull
183
    public abstract String getDescription();
184
185
    /**
186
     * Set description of this I/O instance. It can be used e.g. as tooltip for
187
     * output tab in the GUI.
188
     *
189
     * @param description The description, can be null.
190
     */
191
    public abstract void setDescription(@NullAllowed String description);
192
193
    static <IO, OW extends PrintWriter> InputOutput create(
194
            InputOutputProvider<IO, OW> provider, IO io) {
195
196
        return new Impl<IO, OW>(provider, io);
197
    }
198
199
    private static class Impl<IO, OW extends PrintWriter>
200
            extends InputOutput {
201
202
        private final Map<OW, OutputWriter> cache
203
                = Collections.synchronizedMap(
204
                        new WeakHashMap<OW, OutputWriter>());
205
206
        private final InputOutputProvider<IO, OW> provider;
207
        private final IO ioObject;
208
209
        public Impl(InputOutputProvider<IO, OW> provider, IO ioObject) {
210
211
            this.provider = provider;
212
            this.ioObject = ioObject;
213
        }
214
215
        @Override
216
        public Reader getIn() {
217
            return provider.getIn(ioObject);
218
        }
219
220
        @Override
221
        public OutputWriter getOut() {
222
            return createOrGetCachedWrapper(provider.getOut(ioObject));
223
        }
224
225
        @Override
226
        public OutputWriter getErr() {
227
            return createOrGetCachedWrapper(provider.getErr(ioObject));
228
        }
229
230
        @Override
231
        @NonNull
232
        public Lookup getLookup() {
233
            return provider.getIOLookup(ioObject);
234
        }
235
236
        @Override
237
        public void reset() {
238
            provider.resetIO(ioObject);
239
        }
240
241
        private OutputWriter createOrGetCachedWrapper(OW pw) {
242
            OutputWriter ow = cache.get(pw);
243
            if (ow == null) {
244
                ow = OutputWriter.create(provider, ioObject, pw);
245
                cache.put(pw, ow);
246
            }
247
            return ow;
248
        }
249
250
        @Override
251
        public void closeInputOutput() {
252
            provider.closeIO(ioObject);
253
        }
254
255
        @Override
256
        public boolean isClosed() {
257
            return provider.isIOClosed(ioObject);
258
        }
259
260
        @Override
261
        public String getDescription() {
262
            return provider.getIODescription(ioObject);
263
        }
264
265
        @Override
266
        public void setDescription(String description) {
267
            provider.setIODescription(ioObject, description);
268
        }
269
    }
270
}
(-)a/api.io/src/org/netbeans/api/io/OutputColor.java (+226 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.api.annotations.common.NonNull;
45
import org.netbeans.spi.io.InputOutputProvider;
46
47
/**
48
 * A color specified for part of text in output pane. It can be a predefined
49
 * color for some type of text (success, debug, warning, failure), or arbitrary
50
 * RGB color.
51
 * <p>
52
 * Although using wide range of custom RGB colors may be tempting, predefined
53
 * colors are recommended, as they can be configured to respect GUI theme in
54
 * use.
55
 * </p>
56
 *
57
 * @author jhavlin
58
 */
59
public abstract class OutputColor {
60
61
    /**
62
     * Type of the color - static (rgb) or dynamic. Visibility is public as it
63
     * may be convenient for the implementators of {@link InputOutputProvider}.
64
     * <p>
65
     * Note: New items may be added in the future.
66
     * </p>
67
     */
68
    @SuppressWarnings("PublicInnerClass")
69
    public enum Type {
70
        WARNING, FAILURE, DEBUG, SUCCESS, RGB
71
    }
72
73
    private final Type type;
74
    private static final OutputColor CLR_WARNING = new TypeColor(Type.WARNING);
75
    private static final OutputColor CLR_FAILURE = new TypeColor(Type.FAILURE);
76
    private static final OutputColor CLR_DEBUG = new TypeColor(Type.DEBUG);
77
    private static final OutputColor CLR_SUCCESS = new TypeColor(Type.SUCCESS);
78
79
    private OutputColor(Type type) {
80
        this.type = type;
81
    }
82
83
    /**
84
     * Get RGB value for an {@link OutputColor} specified for a constant RGB
85
     * color.
86
     *
87
     * @return RGB value of the color, or some undefined value if the
88
     * {@link OutputColor} was created for a predefined color, not for constant
89
     * RGB value.
90
     */
91
    public abstract int getRGB();
92
93
    /**
94
     * Get type of this color.
95
     *
96
     * @return Some of predefined text types, or {@link Type#RGB} for colors
97
     * created for constant RGB values.
98
     */
99
    @NonNull
100
    public Type getType() {
101
        return this.type;
102
    }
103
104
    /**
105
     * Warning text color.
106
     *
107
     * @return Predefined color for text of type "warning".
108
     */
109
    @NonNull
110
    public static OutputColor warning() {
111
        return CLR_WARNING;
112
    }
113
114
    /**
115
     * Failure text color.
116
     *
117
     * @return Predefined color for text of type "failure".
118
     */
119
    @NonNull
120
    public static OutputColor failure() {
121
        return CLR_FAILURE;
122
    }
123
124
    /**
125
     * Debug text color.
126
     *
127
     * @return Predefined color for text of type "debug".
128
     */
129
    @NonNull
130
    public static OutputColor debug() {
131
        return CLR_DEBUG;
132
    }
133
134
    /**
135
     * Success text color.
136
     *
137
     * @return Predefined color for text of type "success".
138
     */
139
    @NonNull
140
    public static OutputColor success() {
141
        return CLR_SUCCESS;
142
    }
143
144
    /**
145
     * Arbitrary constant RGB color.
146
     *
147
     * <p>
148
     * Please note that it is recommended to use colors for predefined text
149
     * types, which can respect color theme used by the GUI.
150
     * </p>
151
     *
152
     * @param r The red component, in the range (0 - 255).
153
     * @param g The green component, in the range (0 - 255).
154
     * @param b The blue component, in the range (0 - 255).
155
     *
156
     * @return Color specified for a constant RGB value.
157
     * @throws IllegalArgumentException If some of color components is out of
158
     * range.
159
     */
160
    @NonNull
161
    public static OutputColor rgb(int r, int g, int b) {
162
        checkColorComponentRange("r", r);
163
        checkColorComponentRange("g", g);
164
        checkColorComponentRange("b", b);
165
        int value = ((r & 0xFF) << 16)
166
                | ((g & 0xFF) << 8)
167
                | ((b & 0xFF));
168
        return rgb(value);
169
    }
170
171
    /**
172
     * Arbitrary constant RGB color. Creates an opaque sRGB color with the
173
     * specified combined RGB value consisting of the red component in bits
174
     * 16-23, the green component in bits 8-15, and the blue component in bits
175
     * 0-7.
176
     *
177
     * <p>
178
     * Please note that it is recommended to use colors for predefined text
179
     * types, which can respect color theme used by the GUI.
180
     * </p>
181
     *
182
     * @param rgbValue The combined RGB components.
183
     *
184
     * @return Color specified for a constant RGB value.
185
     */
186
    @NonNull
187
    public static OutputColor rgb(int rgbValue) {
188
        return new RgbColor(rgbValue);
189
    }
190
191
    private static void checkColorComponentRange(String name,
192
            int colorComponent) {
193
194
        if (colorComponent < 0 || colorComponent > 255) {
195
            throw new IllegalArgumentException("Color component " + name//NOI18N
196
                    + " is out of range (0 - 255): " + colorComponent); //NOI18N
197
        }
198
    }
199
200
    private static class TypeColor extends OutputColor {
201
202
        public TypeColor(Type type) {
203
            super(type);
204
        }
205
206
        @Override
207
        public int getRGB() {
208
            return 0;
209
        }
210
    }
211
212
    private static class RgbColor extends OutputColor {
213
214
        private final int value;
215
216
        public RgbColor(int value) {
217
            super(Type.RGB);
218
            this.value = value;
219
        }
220
221
        @Override
222
        public int getRGB() {
223
            return value;
224
        }
225
    }
226
}
(-)a/api.io/src/org/netbeans/api/io/OutputWriter.java (+397 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.Locale;
48
import org.netbeans.spi.io.InputOutputProvider;
49
50
/**
51
 *
52
 * @author jhavlin
53
 */
54
public abstract class OutputWriter extends PrintWriter {
55
56
    private OutputWriter() {
57
        super(new DummyWriter());
58
    }
59
60
    /**
61
     * Select this I/O stream, if possible (e.g. in tabbed pane). Do not open
62
     * the output window if it is currently closed.
63
     *
64
     * @see #show()
65
     * @see #activate()
66
     */
67
    public abstract void select();
68
69
    /**
70
     * Select and show this I/O stream, if possible (e.g. display minimized
71
     * panel). Please note that this can be quite disturbing for the users, so
72
     * please use with caution.
73
     *
74
     * @see #select()
75
     * @see #activate()
76
     */
77
    public abstract void show();
78
79
    /**
80
     * Select, show and activate (focus) this I/O stream, if possible. Please
81
     * note that this can be quite disturbing for the users, so please use with
82
     * caution.
83
     *
84
     * @see #select()
85
     * @see #show()
86
     */
87
    public abstract void activate();
88
89
    /**
90
     * Get current position in the output stream.
91
     *
92
     * @return The position.
93
     */
94
    public abstract Position getCurrentPosition();
95
96
    /**
97
     * Start a new fold. If a fold already exists, a nested fold will be
98
     * created.
99
     *
100
     * @param expanded True if the fold should be expanded by default, false if
101
     * it should be collapsed.
102
     *
103
     * @return The fold handle.
104
     */
105
    public abstract Fold startFold(boolean expanded);
106
107
    /**
108
     * Finish a fold. If it contains some unfinished nested folds, they will be
109
     * finished as well.
110
     *
111
     * @param fold The fold to finish.
112
     */
113
    public abstract void endFold(Fold fold);
114
115
    public abstract void print(String s, Hyperlink link, OutputColor color);
116
117
    public abstract void print(String s, Hyperlink link);
118
119
    public abstract void print(String s, OutputColor color);
120
121
    public abstract void println(String s, Hyperlink link, OutputColor color);
122
123
    public abstract void println(String s, Hyperlink link);
124
125
    public abstract void println(String s, OutputColor color);
126
127
    static <IO, OW extends PrintWriter, POS> OutputWriter create(
128
            InputOutputProvider<IO, OW> provider, IO io, OW writer) {
129
130
        return new Impl<IO, OW, POS>(provider, io, writer);
131
    }
132
133
    private static class Impl<IO, OW extends PrintWriter, POS>
134
            extends OutputWriter {
135
136
        private final InputOutputProvider<IO, OW> provider;
137
        private final IO io;
138
        private final OW writer;
139
140
        public Impl(InputOutputProvider<IO, OW> provider, IO io, OW writer) {
141
            this.provider = provider;
142
            this.io = io;
143
            this.writer = writer;
144
        }
145
146
        @Override
147
        public void select() {
148
            provider.selectIO(io, writer);
149
        }
150
151
        @Override
152
        public void show() {
153
            provider.showIO(io, writer);
154
        }
155
156
        @Override
157
        public void activate() {
158
            provider.activateIO(io, writer);
159
        }
160
161
        @Override
162
        public Position getCurrentPosition() {
163
            return Position.create(provider, io, writer,
164
                    provider.getCurrentPosition(io, writer));
165
        }
166
167
        @Override
168
        public void print(String s, Hyperlink link, OutputColor color) {
169
            provider.print(io, writer, s, link, color, false);
170
        }
171
172
        @Override
173
        public void print(String s, Hyperlink link) {
174
            provider.print(io, writer, s, link, null, false);
175
        }
176
177
        @Override
178
        public void print(String s, OutputColor color) {
179
            provider.print(io, writer, s, null, color, false);
180
        }
181
182
        @Override
183
        public void println(String s, Hyperlink link, OutputColor color) {
184
            provider.print(io, writer, s, link, color, true);
185
        }
186
187
        @Override
188
        public void println(String s, Hyperlink link) {
189
            provider.print(io, writer, s, link, null, true);
190
        }
191
192
        @Override
193
        public void println(String s, OutputColor color) {
194
            provider.print(io, writer, s, null, color, true);
195
        }
196
197
        @Override
198
        public void flush() {
199
            writer.flush();
200
        }
201
202
        @Override
203
        public void close() {
204
            writer.close();
205
        }
206
207
        @Override
208
        public boolean checkError() {
209
            return writer.checkError();
210
        }
211
212
        @Override
213
        public void write(int c) {
214
            writer.write(c);
215
        }
216
217
        @Override
218
        public void write(char[] buf, int off, int len) {
219
            writer.write(buf, off, len);
220
        }
221
222
        @Override
223
        public void write(char[] buf) {
224
            writer.write(buf);
225
        }
226
227
        @Override
228
        public void write(String s, int off, int len) {
229
            writer.write(s, off, len);
230
        }
231
232
        @Override
233
        public void write(String s) {
234
            writer.write(s);
235
        }
236
237
        @Override
238
        public void print(boolean b) {
239
            writer.print(b);
240
        }
241
242
        @Override
243
        public void print(char c) {
244
            writer.print(c);
245
        }
246
247
        @Override
248
        public void print(int i) {
249
            writer.print(i);
250
        }
251
252
        @Override
253
        public void print(long l) {
254
            writer.print(l);
255
        }
256
257
        @Override
258
        public void print(float f) {
259
            writer.print(f);
260
        }
261
262
        @Override
263
        public void print(double d) {
264
            writer.print(d);
265
        }
266
267
        @Override
268
        @SuppressWarnings("ImplicitArrayToString")
269
        public void print(char[] s) {
270
            writer.print(s);
271
        }
272
273
        @Override
274
        public void print(String s) {
275
            writer.print(s);
276
        }
277
278
        @Override
279
        public void print(Object obj) {
280
            writer.print(obj);
281
        }
282
283
        @Override
284
        public void println() {
285
            writer.println();
286
        }
287
288
        @Override
289
        public void println(boolean x) {
290
            writer.println(x);
291
        }
292
293
        @Override
294
        public void println(char x) {
295
            writer.println(x);
296
        }
297
298
        @Override
299
        public void println(int x) {
300
            writer.println(x);
301
        }
302
303
        @Override
304
        public void println(long x) {
305
            writer.println(x);
306
        }
307
308
        @Override
309
        public void println(float x) {
310
            writer.println(x);
311
        }
312
313
        @Override
314
        public void println(double x) {
315
            writer.println(x);
316
        }
317
318
        @Override
319
        @SuppressWarnings("ImplicitArrayToString")
320
        public void println(char[] x) {
321
            writer.println(x);
322
        }
323
324
        @Override
325
        public void println(String x) {
326
            writer.println(x);
327
        }
328
329
        @Override
330
        public void println(Object x) {
331
            writer.println(x);
332
        }
333
334
        @Override
335
        public PrintWriter printf(String format, Object... args) {
336
            return writer.printf(format, args);
337
        }
338
339
        @Override
340
        public PrintWriter printf(Locale l, String format, Object... args) {
341
            return writer.printf(l, format, args);
342
        }
343
344
        @Override
345
        public PrintWriter format(String format, Object... args) {
346
            return writer.format(format, args);
347
        }
348
349
        @Override
350
        public PrintWriter format(Locale l, String format, Object... args) {
351
            return writer.format(l, format, args);
352
        }
353
354
        @Override
355
        public PrintWriter append(CharSequence csq) {
356
            return writer.append(csq);
357
        }
358
359
        @Override
360
        public PrintWriter append(CharSequence csq, int start, int end) {
361
            return writer.append(csq, start, end);
362
        }
363
364
        @Override
365
        public PrintWriter append(char c) {
366
            return writer.append(c);
367
        }
368
369
        @Override
370
        public Fold startFold(boolean expanded) {
371
            int foldNumber = provider.startFold(io, writer, expanded);
372
            return Fold.create(provider, io, writer, foldNumber);
373
        }
374
375
        @Override
376
        public void endFold(Fold fold) {
377
            if (fold != Fold.UNSUPPORTED) {
378
                provider.endFold(io, writer, fold.getFoldNumber());
379
            }
380
        }
381
    }
382
383
    private static class DummyWriter extends Writer {
384
385
        @Override
386
        public void write(char[] cbuf, int off, int len) throws IOException {
387
        }
388
389
        @Override
390
        public void flush() throws IOException {
391
        }
392
393
        @Override
394
        public void close() throws IOException {
395
        }
396
    }
397
}
(-)a/api.io/src/org/netbeans/api/io/Position.java (+100 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2014 Sun Microsystems, Inc.
41
 */
42
package org.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
 * @author jhavlin
52
 */
53
public abstract class Position {
54
55
    static final Position UNSUPPORTED = new Position() {
56
57
        @Override
58
        public void scrollTo() {
59
        }
60
    };
61
62
    private Position() {
63
    }
64
65
    /**
66
     * Scroll to this position.
67
     */
68
    public abstract void scrollTo();
69
70
    static <IO, OW extends PrintWriter> Position create(
71
            InputOutputProvider<IO, OW> provider, IO io,
72
            OW writer, int position) {
73
74
        if (position < 0) {
75
            return UNSUPPORTED;
76
        } else {
77
            return new Impl<IO, OW>(provider, io, writer, position);
78
        }
79
    }
80
81
    private static class Impl<IO, OW extends PrintWriter> extends Position {
82
        private final InputOutputProvider<IO, OW> provider;
83
        private final IO io;
84
        private final OW ow;
85
        private final int position;
86
87
        public Impl(InputOutputProvider<IO, OW> provider, IO io, OW ow,
88
                int position) {
89
            this.provider = provider;
90
            this.io = io;
91
            this.ow = ow;
92
            this.position = position;
93
        }
94
95
        @Override
96
        public void scrollTo() {
97
            provider.scrollTo(io, ow, position);
98
        }
99
    }
100
}
(-)a/api.io/src/org/netbeans/spi/io/InputOutputProvider.java (+349 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 org.netbeans.api.annotations.common.CheckForNull;
47
import org.netbeans.api.annotations.common.NonNull;
48
import org.netbeans.api.annotations.common.NullAllowed;
49
import org.netbeans.api.io.Hyperlink;
50
import org.netbeans.api.io.InputOutput;
51
import org.netbeans.api.io.OutputColor;
52
import org.openide.util.Lookup;
53
import org.openide.util.lookup.ServiceProvider;
54
55
/**
56
 *
57
 * SPI for custom output window implementations.
58
 * <p>
59
 * Use {@link ServiceProvider} annotation for registration.
60
 * </p>
61
 *
62
 * @author jhavlin
63
 *
64
 * @param <IO> Type of objects that will represent I/O instances (e.g. tabs in
65
 * output window).
66
 * @param <WRITER> Type of writers for standard and error streams.
67
 */
68
public interface InputOutputProvider<IO, WRITER extends PrintWriter> {
69
70
    /**
71
     * Get name of this provider.
72
     *
73
     * @return Name of this provider, never null.
74
     */
75
    @NonNull
76
    String getName();
77
78
    /**
79
     * Get or create an object that encapsulates state of a single I/O instance
80
     * (e.g. tab in output window).
81
     *
82
     * @param name Display name of the output pane.
83
     * @param newIO True to always create new I/O, false to return already
84
     * existing instance if available.
85
     * @param lookup Lookup with additional information.
86
     *
87
     * @return A single I/O instance, a newly created or already existing.
88
     * @see InputOutput
89
     */
90
    @NonNull
91
    IO getIO(@NonNull String name, boolean newIO, @NonNull Lookup lookup);
92
93
    /**
94
     * Get input of the passed I/O.
95
     *
96
     * @param io I/O instance.
97
     *
98
     * @return {@link Reader} Reader for the input entered in the output pane.
99
     */
100
    @NonNull
101
    Reader getIn(@NonNull IO io);
102
103
    /**
104
     * Get output stream of the passed I/O.
105
     *
106
     * @param io I/O instance.
107
     *
108
     * @return {@link PrintWriter} for the output stream.
109
     */
110
    @NonNull
111
    WRITER getOut(@NonNull IO io);
112
113
    /**
114
     * Get error stream of the passed I/O.
115
     *
116
     * @param io The I/O instance.
117
     *
118
     * @return {@link PrintWriter} for the error stream.
119
     */
120
    @NonNull
121
    WRITER getErr(@NonNull IO io);
122
123
    /**
124
     * Print enhanced text. It can represent a clickable hyperlink, and can be
125
     * assigned some color.
126
     *
127
     * <p>
128
     * If the implementation doesn't support this feature, this method should
129
     * call something like
130
     * {@code writer.print(text); if (printLineEnd) {writer.println();}}.
131
     * </p>
132
     *
133
     * @param io The I/O instance.
134
     * @param writer The Stream to write into.
135
     * @param text Text to print.
136
     * @param link Link which should be represented by the text, can be null for
137
     * standard text.
138
     * @param color Color of the text, can be null for the default color of the
139
     * stream.
140
     * @param printLineEnd True if new-line should be appended after printing
141
     * {code text}.
142
     */
143
    void print(@NonNull IO io, @NonNull WRITER writer, @NullAllowed String text,
144
            @NullAllowed Hyperlink link, @NullAllowed OutputColor color,
145
            boolean printLineEnd);
146
147
    /**
148
     * Get lookup of an I/O instance, which can contain various extensions and
149
     * additional info.
150
     *
151
     * @param io The I/O instance.
152
     *
153
     * @return The lookup, which can be empty, but never null.
154
     */
155
    @NonNull
156
    Lookup getIOLookup(@NonNull IO io);
157
158
    /**
159
     * Reset the I/O. Clear previously written data and prepare it for new data.
160
     * <p>
161
     * If the implementation doesn't support this feature, this method should do
162
     * nothing.
163
     * </p>
164
     *
165
     * @param io The I/O instance.
166
     */
167
    void resetIO(@NonNull IO io);
168
169
    /**
170
     * Select the I/O instance, but do not show it if it is currently hidden.
171
     * This is useful if several output panes are inside a tabbed pane, and the
172
     * tab representing {@code io} should be selected.
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
     * @param writer Output or error writer. If the streams are merged, this
180
     * argument can be ignored.
181
     *
182
     * @see #showIO(java.lang.Object, java.io.PrintWriter)
183
     * @see #activateIO(java.lang.Object, java.io.PrintWriter)
184
     */
185
    void selectIO(@NonNull IO io, @NonNull WRITER writer);
186
187
    /**
188
     * Show output pane for the passed I/O instance.
189
     * <p>
190
     * If the implementation doesn't support this feature, this method should do
191
     * nothing.
192
     * </p>
193
     *
194
     * @param io The I/O instance.
195
     * @param writer Output or error writer. If the streams are merged, this
196
     * argument can be ignored.
197
     *
198
     * @see #selectIO(java.lang.Object, java.io.PrintWriter)
199
     * @see #showIO(java.lang.Object, java.io.PrintWriter)
200
     */
201
    void showIO(@NonNull IO io, @NonNull WRITER writer);
202
203
    /**
204
     * Activate (focus) output pane for the passed I/O instance.
205
     * <p>
206
     * If the implementation doesn't support this feature, this method can at
207
     * least show the output pane, or do nothing.
208
     * </p>
209
     *
210
     * @param io The I/O instance.
211
     * @param writer Output or error writer. If the streams are merged, this
212
     * argument can be ignored.
213
     *
214
     * @see #selectIO(java.lang.Object, java.io.PrintWriter)
215
     * @see #showIO(java.lang.Object, java.io.PrintWriter)
216
     */
217
    void activateIO(@NonNull IO io, @NonNull WRITER writer);
218
219
    /**
220
     * Close the I/O, its output pane and release resources.
221
     *
222
     * @param io The I/O instance.
223
     *
224
     * @see #isIOClosed(java.lang.Object)
225
     */
226
    void closeIO(@NonNull IO io);
227
228
    /**
229
     * Check whether the I/O is closed.
230
     *
231
     * @param io The I/O instance.
232
     *
233
     * @return True if the I/O was closed, false otherwise.
234
     *
235
     * @see #closeIO(java.lang.Object)
236
     */
237
    boolean isIOClosed(@NonNull IO io);
238
239
    /**
240
     * Get current position.
241
     *
242
     * @param io The I/O instance.
243
     * @param writer Output or error writer. If the streams are merged, the
244
     * value can be ignored.
245
     *
246
     * @return The current position in the output pane. If this feature is not
247
     * supported, return a negative value.
248
     */
249
    @CheckForNull
250
    int getCurrentPosition(@NonNull IO io, @NonNull WRITER writer);
251
252
    /**
253
     * Scroll to a position.
254
     * <p>
255
     * If this feature is not supported
256
     * ({@link #getCurrentPosition(Object, PrintWriter)} returns null), this
257
     * method should do nothing, it will be never called.
258
     * </p>
259
     *
260
     * @param io The I/O instance.
261
     * @param writer Output or error writer. If the streams are merged, the
262
     * value can be ignored.
263
     * @param position The position to scroll to.
264
     *
265
     * @see #getCurrentPosition(java.lang.Object, java.io.PrintWriter)
266
     */
267
    void scrollTo(@NonNull IO io, @NonNull WRITER writer,
268
            @NonNull int position);
269
270
    /**
271
     * Start fold at the current position. If a fold is already open, start a
272
     * new nested fold (but if a fold with the same start position already
273
     * exists, no nested fold will be created, and the same start position will
274
     * be returned).
275
     *
276
     * @param io The I/O instance.
277
     * @param writer Output or error writer. If the streams are merged, the
278
     * value can be ignored.
279
     * @param expanded True if the new fold should be expanded by default, false
280
     * if it should be collapsed.
281
     *
282
     * @return Number representing the fold. It will usually be number of the
283
     * current line. If the implementation doesn't support this feature, return
284
     * a negative value.
285
     */
286
    @CheckForNull
287
    int startFold(@NonNull IO io, @NonNull WRITER writer, boolean expanded);
288
289
    /**
290
     * Finish a fold specified by its start position. If some nested folds
291
     * exist, they will be finished as well if needed.
292
     *
293
     * <p>
294
     * If this feature is not supported
295
     * ({@link #startFold(Object, PrintWriter, boolean)} returns negative
296
     * value), this method should do nothing, it will be never called.
297
     * </p>
298
     *
299
     * @param io The I/O instance.
300
     * @param writer Output or error writer. If the streams are merged, the
301
     * value can be ignored.
302
     * @param foldNumber The fold to finish, specified by its number.
303
     */
304
    void endFold(@NonNull IO io, @NonNull WRITER writer,
305
            @NonNull int foldNumber);
306
307
    /**
308
     * Expand or collapse a fold.
309
     *
310
     * <p>
311
     * If this feature is not supported
312
     * ({@link #startFold(Object, PrintWriter, boolean)} returns negative
313
     * value), this method should do nothing, it will be never called.
314
     * </p>
315
     *
316
     * @param io The I/O instance.
317
     * @param writer Output or error writer. If the streams are merged, the
318
     * value can be ignored.
319
     * @param foldNumber The fold to finish, specified by its number.
320
     * @param expanded True to expand the fold, false to collapse the fold.
321
     */
322
    void setFoldExpanded(@NonNull IO io, @NonNull WRITER writer,
323
            int foldNumber, boolean expanded);
324
325
326
    /**
327
     * Get description of an I/O instance. It can be used e.g. as tooltip text
328
     * for the output tab.
329
     *
330
     * @param io The I/O instance.
331
     *
332
     * @return The description, or null if not set.
333
     */
334
    @CheckForNull String getIODescription(@NonNull IO io);
335
336
    /**
337
     * Set description of an I/O instance.
338
     *
339
     * <p>
340
     * If this feature is not supported, this method should do nothing.
341
     * </p>
342
     *
343
     * @param io The I/O instance.
344
     * @param description The description, can be null.
345
     *
346
     * @see #getIODescription(java.lang.Object)
347
     */
348
    void setIODescription(@NonNull IO io, @NullAllowed String description);
349
}
(-)a/api.io/src/org/netbeans/spi/io/Utilities.java (+70 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2014 Sun Microsystems, Inc.
41
 */
42
package org.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
    /**
56
     * Handle the URI when a URI hyperlink is clicked in the output window.
57
     *
58
     * @param uri The URI to handle.
59
     */
60
    public static void handleUri(URI uri) {
61
62
        for (OpenUriHandler handler
63
                : Lookup.getDefault().lookupAll(OpenUriHandler.class)) {
64
65
            if (handler.handle(uri)) {
66
                return;
67
            }
68
        }
69
    }
70
}
(-)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 (+101 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
49
/**
50
 *
51
 * @author jhavlin
52
 */
53
public class HyperlinkTest {
54
55
    @Test
56
    public void testUriLink() throws URISyntaxException {
57
        Hyperlink h = Hyperlink.forURI(new URI("file://x"));
58
        assertTrue(h.isForURI());
59
        assertFalse(h.isOnClick());
60
        assertFalse(h.isImportant());
61
        assertNotNull(h.getURI());
62
        assertNull(h.getRunnable());
63
        assertEquals("file://x", h.getURI().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
        assertFalse(h.isForURI());
84
        assertTrue(h.isOnClick());
85
        assertFalse(h.isImportant());
86
        assertNull(h.getURI());
87
        assertNotNull(h.getRunnable());
88
        h.getRunnable().run();
89
        assertTrue("The passed code should be invoked", invoked[0]);
90
    }
91
92
    @Test
93
    public void testOnClickLinkImportant() {
94
        Hyperlink h = Hyperlink.onClick(new Runnable() {
95
            @Override
96
            public void run() {
97
            }
98
        }, true);
99
        assertTrue(h.isImportant());
100
    }
101
}
(-)a/api.io/test/unit/src/org/netbeans/api/io/IOProviderTest.java (+291 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 org.junit.Test;
52
import static org.junit.Assert.*;
53
import org.netbeans.junit.MockServices;
54
import org.netbeans.spi.io.InputOutputProvider;
55
import org.openide.util.Lookup;
56
import org.openide.util.lookup.Lookups;
57
58
/**
59
 *
60
 * @author jhavlin
61
 */
62
public class IOProviderTest {
63
64
    public IOProviderTest() {
65
    }
66
67
    @Test
68
    public void useCase1() {
69
        InputOutput io = IOProvider.getDefault().getIO("UseCase1", true);
70
        io.getOut().println("This is a simple output");
71
        io.getOut().close();
72
    }
73
74
    @Test
75
    public void useCase2() throws URISyntaxException {
76
        InputOutput io = IOProvider.getDefault().getIO("UseCase2", false);
77
        io.getOut().print("A line containing a ");
78
        io.getOut().print("hyperlink", Hyperlink.forURI(new URI(
79
                "file://n:/test/Test.java?line=4&col=2")));
80
        io.getOut().println(" for a URI.");
81
        io.getOut().close();
82
    }
83
84
    @Test
85
    public void useCase3() {
86
        InputOutput io = IOProvider.getDefault().getIO("UseCase3", true);
87
        io.getOut().print("A line containing a ");
88
        io.getOut().print("hyperlink", Hyperlink.onClick(new Runnable() {
89
            @Override
90
            public void run() {
91
                System.gc();
92
            }
93
        }));
94
        io.getOut().println(" for invokation of custom code.");
95
        io.getOut().close();
96
    }
97
98
    @Test
99
    public void useCase4() {
100
        InputOutput io = IOProvider.getDefault().getIO("UseCase4", true);
101
        io.getOut().println("Let's print some info", OutputColor.debug());
102
        io.getOut().println("or warning with appropriate color",
103
                OutputColor.warning());
104
        io.getOut().println("Maybe also text with custom reddish color",
105
                OutputColor.rgb(255, 16, 16));
106
        io.getOut().close();
107
    }
108
109
    @Test
110
    public void useCase5() {
111
        InputOutput io = IOProvider.getDefault().getIO("UseCase5", true);
112
        io.getOut().println("Let's print some text");
113
        io.getErr().println("and reset the pane immediately.");
114
        io.reset();
115
        io.getOut().println("The pane is now empty and we can reuse it simply");
116
        io.getOut().close();
117
    }
118
119
    @Test
120
    public void testTrivialImplementationAlwaysAvailable() {
121
        assertEquals("Trivial", IOProvider.getDefault().getName());
122
        assertEquals("Trivial", IOProvider.get("Trivial").getName());
123
        assertEquals("Trivial", IOProvider.get("Another").getName());
124
    }
125
126
    @Test
127
    public void testGetFromLookup() {
128
        MockServices.setServices(MockInputOutputProvider.class);
129
        try {
130
            assertEquals("mock", IOProvider.getDefault().getName());
131
            assertEquals("mock", IOProvider.get("mock").getName());
132
            assertEquals("mock", IOProvider.get("wrong").getName());
133
        } finally {
134
            MockServices.setServices();
135
        }
136
    }
137
138
    @Test
139
    public void testAllMethodsAreDelegatedToSPI() {
140
        MockServices.setServices(MockInputOutputProvider.class);
141
        try {
142
            IOProvider.getDefault().getIO("test1", true);
143
            Lookup lkp = IOProvider.getDefault()
144
                    .getIO("test1", false, Lookup.EMPTY).getLookup();
145
            CalledMethodList list = lkp.lookup(CalledMethodList.class);
146
            assertEquals("getIO", list.get(0));
147
            assertEquals("getIO", list.get(1));
148
            assertEquals("getIOLookup", list.get(2));
149
            assertEquals(3, list.size());
150
        } finally {
151
            MockServices.setServices();
152
        }
153
    }
154
155
    @SuppressWarnings("PackageVisibleInnerClass")
156
    static class CalledMethodList extends ArrayList<String> {
157
    }
158
159
    @SuppressWarnings("PublicInnerClass")
160
    public static class MockInputOutputProvider implements
161
            InputOutputProvider<Object, PrintWriter> {
162
163
        private final CalledMethodList calledMethods = new CalledMethodList();
164
        private final StringWriter stringWriter = new StringWriter();
165
        private final Lookup lookup = Lookups.fixed(calledMethods, stringWriter);
166
167
        @Override
168
        public String getName() {
169
            return "mock";
170
        }
171
172
        @Override
173
        public Object getIO(String name, boolean newIO, Lookup lookup) {
174
            calledMethods.add("getIO");
175
            return new Object();
176
        }
177
178
        @Override
179
        public Reader getIn(Object io) {
180
            calledMethods.add("getIn");
181
            return new StringReader("");
182
        }
183
184
        @Override
185
        public PrintWriter getOut(Object io) {
186
            calledMethods.add("getOut");
187
            return new PrintWriter(stringWriter);
188
        }
189
190
        @Override
191
        public PrintWriter getErr(Object io) {
192
            calledMethods.add("getErr");
193
            return new PrintWriter(stringWriter);
194
        }
195
196
        @Override
197
        public void print(Object io, PrintWriter writer, String text,
198
                Hyperlink link, OutputColor color, boolean printLineEnd) {
199
            if (link != null || color != null) {
200
                stringWriter.append("<ext");
201
                stringWriter.append(color != null ? " color" : "");
202
                stringWriter.append(link != null ? " link" : "");
203
                stringWriter.append(">");
204
            }
205
            stringWriter.append(text);
206
            if (link != null || color != null) {
207
                stringWriter.append("</ext>");
208
            }
209
            calledMethods.add("print");
210
            if (printLineEnd) {
211
                stringWriter.append(System.getProperty("line.separator"));
212
            }
213
        }
214
215
        @Override
216
        public Lookup getIOLookup(Object io) {
217
            calledMethods.add("getIOLookup");
218
            return lookup;
219
        }
220
221
        @Override
222
        public void resetIO(Object io) {
223
            calledMethods.add("resetIO");
224
        }
225
226
        @Override
227
        public void selectIO(Object io, PrintWriter writer) {
228
            calledMethods.add("selectIO");
229
        }
230
231
        @Override
232
        public void showIO(Object io, PrintWriter writer) {
233
            calledMethods.add("showIO");
234
        }
235
236
        @Override
237
        public void activateIO(Object io, PrintWriter writer) {
238
            calledMethods.add("activateIO");
239
        }
240
241
        @Override
242
        public void closeIO(Object io) {
243
            calledMethods.add("closeIO");
244
        }
245
246
        @Override
247
        public boolean isIOClosed(Object io) {
248
            calledMethods.add("isIOClosed");
249
            return false;
250
        }
251
252
        @Override
253
        public int getCurrentPosition(Object io, PrintWriter writer) {
254
            calledMethods.add("getCurrentPosition");
255
            return 1;
256
        }
257
258
        @Override
259
        public void scrollTo(Object io, PrintWriter writer, int position) {
260
            calledMethods.add("scrollTo");
261
        }
262
263
        @Override
264
        public int startFold(Object io, PrintWriter writer, boolean expanded) {
265
            calledMethods.add("startFold");
266
            return 1;
267
        }
268
269
        @Override
270
        public void endFold(Object io, PrintWriter writer, int foldNumber) {
271
            calledMethods.add("endFold");
272
        }
273
274
        @Override
275
        public void setFoldExpanded(Object io, PrintWriter writer,
276
                int foldNumber, boolean expanded) {
277
            calledMethods.add("setFoldExpanded");
278
        }
279
280
        @Override
281
        public String getIODescription(Object io) {
282
            calledMethods.add("getIODescription");
283
            return null;
284
        }
285
286
        @Override
287
        public void setIODescription(Object io, String description) {
288
            calledMethods.add("setIODescription");
289
        }
290
    }
291
}
(-)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 (+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 org.junit.Test;
45
import static org.junit.Assert.*;
46
47
/**
48
 *
49
 * @author jhavlin
50
 */
51
public class OutputColorTest {
52
53
    @Test
54
    public void testRgbColor() {
55
        OutputColor c = OutputColor.rgb(127, 255, 1);
56
        assertEquals(OutputColor.Type.RGB, c.getType());
57
        int value = c.getRGB();
58
        int r = value >> 16;
59
        int g = value >> 8 & 0xFF;
60
        int b = value & 0xFF;
61
        assertEquals(127, r);
62
        assertEquals(255, g);
63
        assertEquals(1, b);
64
    }
65
66
    @Test
67
    public void testWarningColor() {
68
        OutputColor c = OutputColor.warning();
69
        assertEquals(OutputColor.Type.WARNING, c.getType());
70
    }
71
72
    @Test
73
    public void testFailureColor() {
74
        OutputColor c = OutputColor.failure();
75
        assertEquals(OutputColor.Type.FAILURE, c.getType());
76
    }
77
78
    @Test
79
    public void testDebugColor() {
80
        OutputColor c = OutputColor.debug();
81
        assertEquals(OutputColor.Type.DEBUG, c.getType());
82
    }
83
84
    @Test
85
    public void testSuccessColor() {
86
        OutputColor c = OutputColor.success();
87
        assertEquals(OutputColor.Type.SUCCESS, c.getType());
88
    }
89
}
(-)a/api.io/test/unit/src/org/netbeans/api/io/OutputWriterTest.java (+133 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.select();
75
            ow.show();
76
            ow.activate();
77
            Position p = ow.getCurrentPosition();
78
            p.scrollTo();
79
            Fold f = ow.startFold(true);
80
            f.expad();
81
            f.collapse();
82
            ow.endFold(f);
83
84
            int order = 0;
85
            assertEquals("getIO", list.get(order++));
86
            assertEquals("getOut", list.get(order++));
87
            assertEquals("getIOLookup", list.get(order++));
88
            assertEquals("selectIO", list.get(order++));
89
            assertEquals("showIO", list.get(order++));
90
            assertEquals("activateIO", list.get(order++));
91
            assertEquals("getCurrentPosition", list.get(order++));
92
            assertEquals("scrollTo", list.get(order++));
93
            assertEquals("startFold", list.get(order++));
94
            assertEquals("setFoldExpanded", list.get(order++));
95
            assertEquals("setFoldExpanded", list.get(order++));
96
            assertEquals("endFold", list.get(order++));
97
98
            ow.print("Line");
99
            ow.print(" 1");
100
            ow.println();
101
102
            ow.print("Hyperlink ", Hyperlink.forURI(new URI("file://x")));
103
            ow.print(" ");
104
            ow.print("Color", OutputColor.debug());
105
            ow.print(" ");
106
            ow.print("Color link", Hyperlink.forURI(new URI("file://y")),
107
                    OutputColor.debug());
108
            ow.println();
109
110
            ow.println("Line with link", Hyperlink.forURI(new URI("file://z")));
111
            ow.println("Color line", OutputColor.debug());
112
            ow.println("Color line with link",
113
                    Hyperlink.forURI(new URI("file://a")), OutputColor.debug());
114
115
            StringWriter sw = lkp.lookup(StringWriter.class);
116
            sw.toString();
117
118
            String[] lines = sw.toString().split(
119
                    System.getProperty("line.separator"));
120
121
            assertEquals("Line 1", lines[0]);
122
            assertEquals("<ext link>Hyperlink </ext> <ext color>Color</ext> "
123
                    + "<ext color link>Color link</ext>", lines[1]);
124
            assertEquals("<ext link>Line with link</ext>", lines[2]);
125
            assertEquals("<ext color>Color line</ext>", lines[3]);
126
            assertEquals("<ext color link>Color line with link</ext>", lines[4]);
127
128
        } finally {
129
            MockServices.setServices();
130
        }
131
    }
132
133
}
(-)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.api.io.IOProvider
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 (+8 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/>
(-)a/core.output2/src/org/netbeans/core/output2/BridgeUtils.java (+133 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.core.output2;
43
44
import java.awt.Color;
45
import org.netbeans.api.io.Hyperlink;
46
import org.netbeans.api.io.OutputColor;
47
import org.netbeans.spi.io.Utilities;
48
import org.openide.windows.IOColors;
49
import org.openide.windows.InputOutput;
50
import org.openide.windows.OutputEvent;
51
import org.openide.windows.OutputListener;
52
53
/**
54
 * Utilities for bridging from openide.io to api.io APIs.
55
 *
56
 * @author jhavlin
57
 */
58
public class BridgeUtils {
59
60
    /**
61
     * Convert a hyperlink to an output listener.
62
     *
63
     * @param link The hyperlink.
64
     * @return The wrapping output listener.
65
     */
66
    public static OutputListener hyperlinkToOutputListener(final Hyperlink link) {
67
        if (link == null) {
68
            return null;
69
        } else if (link.isOnClick()) {
70
            return new OutputListenerAdapter() {
71
72
                @Override
73
                public void outputLineAction(OutputEvent ev) {
74
                    link.getRunnable().run();
75
                }
76
            };
77
        } else if (link.isForURI()) {
78
            return new OutputListenerAdapter() {
79
80
                @Override
81
                public void outputLineAction(OutputEvent ev) {
82
                    Utilities.handleUri(link.getURI());
83
                }
84
            };
85
        } else {
86
            return null;
87
        }
88
    }
89
90
    /**
91
     * Convert AWT-independent {@link OutputColor} to {@link java.awt.Color}.
92
     *
93
     * @return Appropriate color, or null if default color should be used.
94
     */
95
    public static Color outputColorToAwtColor(InputOutput io, OutputColor color) {
96
        if (color == null) {
97
            return null;
98
        }
99
        if (color.getType().equals(OutputColor.Type.RGB)) {
100
            return new Color(color.getRGB());
101
        } else if (IOColors.isSupported(io)) {
102
            switch (color.getType()) {
103
                case DEBUG:
104
                    return IOColors.getColor(io, IOColors.OutputType.LOG_DEBUG);
105
                case FAILURE:
106
                    return IOColors.getColor(io, IOColors.OutputType.LOG_FAILURE);
107
                case WARNING:
108
                    return IOColors.getColor(io, IOColors.OutputType.LOG_WARNING);
109
                case SUCCESS:
110
                    return IOColors.getColor(io, IOColors.OutputType.LOG_SUCCESS);
111
                default:
112
                    return null;
113
            }
114
        } else {
115
            return null;
116
        }
117
    }
118
119
    private static class OutputListenerAdapter implements OutputListener {
120
121
        @Override
122
        public void outputLineSelected(OutputEvent ev) {
123
        }
124
125
        @Override
126
        public void outputLineAction(OutputEvent ev) {
127
        }
128
129
        @Override
130
        public void outputLineCleared(OutputEvent ev) {
131
        }
132
    }
133
}
(-)a/core.output2/src/org/netbeans/core/output2/NbIO.java (-4 / +68 lines)
Lines 72-78 Link Here
72
 *
72
 *
73
 * @author  Tim Boudreau
73
 * @author  Tim Boudreau
74
 */
74
 */
75
class NbIO implements InputOutput, Lookup.Provider {
75
public class NbIO implements InputOutput, Lookup.Provider {
76
76
77
    private Boolean focusTaken = null;
77
    private Boolean focusTaken = null;
78
    private volatile boolean closed = false;
78
    private volatile boolean closed = false;
Lines 86-91 Link Here
86
    private Lookup lookup;
86
    private Lookup lookup;
87
    private IOTabImpl ioTab;
87
    private IOTabImpl ioTab;
88
    private IOColorsImpl ioColors;
88
    private IOColorsImpl ioColors;
89
    private IOFoldingImpl ioFolding;
89
    private IOFoldingImpl.NbIoFoldHandleDefinition currentFold = null;
90
    private IOFoldingImpl.NbIoFoldHandleDefinition currentFold = null;
90
91
91
    /** Creates a new instance of NbIO 
92
    /** Creates a new instance of NbIO 
Lines 321-337 Link Here
321
        return getIn();
322
        return getIn();
322
    }
323
    }
323
324
325
    public synchronized IOFoldingImpl getIoFolding() {
326
        if (ioFolding == null) {
327
            ioFolding = new IOFoldingImpl();
328
        }
329
        return ioFolding;
330
    }
331
324
    public synchronized Lookup getLookup() {
332
    public synchronized Lookup getLookup() {
325
        if (lookup == null) {
333
        if (lookup == null) {
326
            ioTab = new IOTabImpl();
334
            ioTab = new IOTabImpl();
327
            ioColors = new IOColorsImpl();
335
            ioColors = new IOColorsImpl();
336
            ioFolding = getIoFolding();
328
            lookup = Lookups.fixed(ioTab, ioColors, new IOPositionImpl(),
337
            lookup = Lookups.fixed(ioTab, ioColors, new IOPositionImpl(),
329
                    new IOColorLinesImpl(), new IOColorPrintImpl(),
338
                    new IOColorLinesImpl(), new IOColorPrintImpl(),
330
                    new IOSelectImpl(), new IOFoldingImpl(), options);
339
                    new IOSelectImpl(), ioFolding, options);
331
        }
340
        }
332
        return lookup;
341
        return lookup;
333
    }
342
    }
334
343
344
    void scrollTo(int pos) {
345
        post(NbIO.this, IOEvent.CMD_SCROLL, pos);
346
    }
347
335
    class IOReader extends Reader {
348
    class IOReader extends Reader {
336
        private boolean pristine = true;
349
        private boolean pristine = true;
337
        IOReader() {
350
        IOReader() {
Lines 481-486 Link Here
481
        return ioTab != null ? ioTab.getToolTipText() : null;
494
        return ioTab != null ? ioTab.getToolTipText() : null;
482
    }
495
    }
483
496
497
    void setTooltipText(String toolTip) {
498
        post(NbIO.this, IOEvent.CMD_SET_TOOLTIP, toolTip);
499
    }
500
484
    Color getColor(IOColors.OutputType type) {
501
    Color getColor(IOColors.OutputType type) {
485
        return ioColors != null ? ioColors.getColor(type) : AbstractLines.getDefColors()[type.ordinal()];
502
        return ioColors != null ? ioColors.getColor(type) : AbstractLines.getDefColors()[type.ordinal()];
486
    }
503
    }
Lines 508-514 Link Here
508
        @Override
525
        @Override
509
        protected void setToolTipText(String text) {
526
        protected void setToolTipText(String text) {
510
            toolTip = text;
527
            toolTip = text;
511
            post(NbIO.this, IOEvent.CMD_SET_TOOLTIP, toolTip);
528
            NbIO.this.setTooltipText(toolTip);
512
        }
529
        }
513
    }
530
    }
514
531
Lines 533-539 Link Here
533
        }
550
        }
534
551
535
        public void scrollTo() {
552
        public void scrollTo() {
536
            post(NbIO.this, IOEvent.CMD_SCROLL, new Integer(pos));
553
            NbIO.this.scrollTo(pos);
537
        }
554
        }
538
    }
555
    }
539
556
Lines 687-692 Link Here
687
                return ((AbstractLines) out().getLines());
704
                return ((AbstractLines) out().getLines());
688
            }
705
            }
689
        }
706
        }
707
708
        /**
709
         * Access to fold creation via org.netbeans.api.io API.
710
         *
711
         * @return The new fold handle definition.
712
         */
713
        private NbIoFoldHandleDefinition createFold(
714
                NbIoFoldHandleDefinition parent, int foldStartIndex,
715
                boolean expanded) {
716
717
            return new NbIoFoldHandleDefinition(parent, foldStartIndex,
718
                    expanded);
719
        }
690
    }
720
    }
691
721
692
    private int getLastLineNumber() {
722
    private int getLastLineNumber() {
Lines 707-710 Link Here
707
    OutputOptions getOptions() {
737
    OutputOptions getOptions() {
708
        return this.options;
738
        return this.options;
709
    }
739
    }
740
741
    @SuppressWarnings("AccessingNonPublicFieldOfAnotherObject")
742
    int startFold(boolean expanded) {
743
        synchronized (outOrException()) {
744
            int foldStartIndex = getLastLineNumber();
745
            if (currentFold != null && currentFold.start == foldStartIndex) {
746
                return foldStartIndex;
747
            } else {
748
                currentFold = getIoFolding().createFold(currentFold,
749
                        foldStartIndex,
750
                        expanded);
751
                return foldStartIndex;
752
            }
753
        }
754
    }
755
756
    @SuppressWarnings("AccessingNonPublicFieldOfAnotherObject")
757
    void endFold(int foldStartIndex) {
758
        synchronized (outOrException()) {
759
            IOFoldingImpl.NbIoFoldHandleDefinition fold = currentFold;
760
            while (fold != null && fold.start != foldStartIndex) {
761
                fold = fold.parent;
762
            }
763
            if (fold != null) {
764
                IOFoldingImpl.NbIoFoldHandleDefinition nested = currentFold;
765
                while (nested != fold) {
766
                    nested.finish();
767
                    nested = nested.parent;
768
                }
769
                fold.finish();
770
                currentFold = fold.parent;
771
            }
772
        }
773
    }
710
}
774
}
(-)a/core.output2/src/org/netbeans/core/output2/NbIOProvider.java (-3 / +180 lines)
Lines 44-65 Link Here
44
44
45
package org.netbeans.core.output2;
45
package org.netbeans.core.output2;
46
46
47
import java.awt.Color;
47
import java.io.IOException;
48
import java.io.IOException;
49
import java.io.Reader;
50
import java.util.Arrays;
51
import java.util.Collections;
52
import java.util.HashSet;
53
import java.util.Set;
48
import java.util.WeakHashMap;
54
import java.util.WeakHashMap;
49
import javax.swing.Action;
55
import javax.swing.Action;
56
import org.netbeans.api.io.Hyperlink;
57
import org.netbeans.api.io.OutputColor;
58
import org.netbeans.spi.io.InputOutputProvider;
50
import org.openide.util.Exceptions;
59
import org.openide.util.Exceptions;
60
import org.openide.util.Lookup;
51
import org.openide.util.NbBundle;
61
import org.openide.util.NbBundle;
62
import org.openide.util.lookup.ServiceProvider;
63
import org.openide.util.lookup.ServiceProviders;
64
import org.openide.windows.IOColorLines;
65
import org.openide.windows.IOColorPrint;
52
import org.openide.windows.IOContainer;
66
import org.openide.windows.IOContainer;
53
import org.openide.windows.IOProvider;
67
import org.openide.windows.IOProvider;
68
import org.openide.windows.IOSelect;
54
import org.openide.windows.InputOutput;
69
import org.openide.windows.InputOutput;
70
import org.openide.windows.OutputListener;
55
import org.openide.windows.OutputWriter;
71
import org.openide.windows.OutputWriter;
56
72
57
/**
73
/**
58
 * Supplies Output Window implementation through Lookup.
74
 * Supplies Output Window implementation through Lookup.
59
 * @author Jesse Glick, Tim Boudreau
75
 * @author Jesse Glick, Tim Boudreau
60
 */
76
 */
61
@org.openide.util.lookup.ServiceProvider(service=org.openide.windows.IOProvider.class, position=100)
77
@ServiceProviders({
62
public final class NbIOProvider extends IOProvider {
78
    @ServiceProvider(service=IOProvider.class, position=100),
79
    @ServiceProvider(service=InputOutputProvider.class, position=100)
80
})
81
public final class NbIOProvider extends IOProvider
82
        implements InputOutputProvider<NbIO, OutputWriter> {
83
84
    private static final Set<IOSelect.AdditionalOperation> OPS_ACTIVATE;
85
    private static final Set<IOSelect.AdditionalOperation> OPS_SELECT;
86
87
    static {
88
        OPS_ACTIVATE = new HashSet(Arrays.asList(
89
                IOSelect.AdditionalOperation.OPEN,
90
                IOSelect.AdditionalOperation.REQUEST_VISIBLE,
91
                IOSelect.AdditionalOperation.REQUEST_ACTIVE));
92
        OPS_SELECT = Collections.emptySet();
93
    }
63
    private static final WeakHashMap<IOContainer, PairMap> containerPairMaps =
94
    private static final WeakHashMap<IOContainer, PairMap> containerPairMaps =
64
            new WeakHashMap<IOContainer, PairMap>();
95
            new WeakHashMap<IOContainer, PairMap>();
65
96
Lines 68-73 Link Here
68
99
69
    private static final String NAME = "output2"; // NOI18N
100
    private static final String NAME = "output2"; // NOI18N
70
    
101
    
102
    @Override
71
    public OutputWriter getStdOut() {
103
    public OutputWriter getStdOut() {
72
        if (Controller.LOG) {
104
        if (Controller.LOG) {
73
            Controller.log("NbIOProvider.getStdOut");
105
            Controller.log("NbIOProvider.getStdOut");
Lines 93-98 Link Here
93
    }
125
    }
94
    
126
    
95
    
127
    
128
    @Override
96
    public InputOutput getIO(String name, boolean newIO) {
129
    public InputOutput getIO(String name, boolean newIO) {
97
        return getIO (name, newIO, new Action[0], null);
130
        return getIO (name, newIO, new Action[0], null);
98
    }
131
    }
Lines 113-119 Link Here
113
    }
146
    }
114
147
115
    @Override
148
    @Override
116
    public InputOutput getIO(String name, boolean newIO,
149
    public NbIO getIO(String name, boolean newIO,
117
            Action[] toolbarActions, IOContainer ioContainer) {
150
            Action[] toolbarActions, IOContainer ioContainer) {
118
        if (Controller.LOG) {
151
        if (Controller.LOG) {
119
            Controller.log("GETIO: " + name + " new:" + newIO);
152
            Controller.log("GETIO: " + name + " new:" + newIO);
Lines 140-145 Link Here
140
        return result;
173
        return result;
141
    }
174
    }
142
    
175
    
176
    @Override
177
    public NbIO getIO(String name, boolean newIO, Lookup lookup) {
178
        Action[] action = lookup.lookup(Action[].class);
179
        IOContainer ioContainer = lookup.lookup(IOContainer.class);
180
        return getIO(name, newIO, action, ioContainer);
181
    }
182
183
    @Override
184
    public Reader getIn(NbIO io) {
185
        return io.getIn();
186
    }
187
188
    @Override
189
    public OutputWriter getOut(NbIO io) {
190
        return io.getOut();
191
    }
192
193
    @Override
194
    public OutputWriter getErr(NbIO io) {
195
        return io.getErr();
196
    }
197
198
    @Override
199
    public void print(NbIO io, OutputWriter writer, String text,
200
            Hyperlink link, OutputColor outputColor, boolean printLineEnd) {
201
202
        Color awtColor = BridgeUtils.outputColorToAwtColor(io, outputColor);
203
        OutputListener listener = BridgeUtils.hyperlinkToOutputListener(link);
204
        boolean listenerImportant = link != null && link.isImportant();
205
        try {
206
            if (printLineEnd && outputColor == null) {
207
                writer.println(text, listener, listenerImportant);
208
            } else if (printLineEnd && IOColorLines.isSupported(io)) {
209
                IOColorLines.println(io, text, listener, listenerImportant,
210
                        awtColor);
211
            } else if (IOColorPrint.isSupported(io)) {
212
                IOColorPrint.print(io, text, listener, listenerImportant,
213
                        awtColor);
214
                if (printLineEnd) {
215
                    writer.println();
216
                }
217
            } else if (printLineEnd) {
218
                writer.println(text);
219
            } else {
220
                writer.print(text);
221
            }
222
        } catch (IOException ex) {
223
            // Ignored by the new API.
224
        }
225
    }
226
227
    @Override
228
    public Lookup getIOLookup(NbIO io) {
229
        if (io instanceof Lookup.Provider) {
230
            return ((Lookup.Provider) io).getLookup();
231
        } else {
232
            return Lookup.EMPTY;
233
        }
234
    }
235
236
    @Override
237
    public void resetIO(NbIO io) {
238
        try {
239
            io.getOut().reset();
240
        } catch (IOException ex) {
241
            // Ignored by the new API.
242
        }
243
    }
244
245
    @Override
246
    public void selectIO(NbIO io, OutputWriter writer) {
247
        if (IOSelect.isSupported(io)) {
248
            IOSelect.select(io, OPS_SELECT);
249
        }
250
    }
251
252
    @Override
253
    public void showIO(NbIO io, OutputWriter writer) {
254
        io.select();
255
    }
256
257
    @Override
258
    public void activateIO(NbIO io, OutputWriter writer) {
259
        if (IOSelect.isSupported(io)) {
260
            IOSelect.select(io, OPS_ACTIVATE);
261
        } else {
262
            io.select();
263
        }
264
    }
265
266
    @Override
267
    public void closeIO(NbIO io) {
268
        io.closeInputOutput();
269
    }
270
271
    @Override
272
    public boolean isIOClosed(NbIO io) {
273
        return io.isClosed();
274
    }
143
    
275
    
144
    static void dispose (NbIO io) {
276
    static void dispose (NbIO io) {
145
        IOContainer ioContainer = io.getIOContainer();
277
        IOContainer ioContainer = io.getIOContainer();
Lines 156-160 Link Here
156
            }
288
            }
157
        }
289
        }
158
    }
290
    }
291
292
    @Override
293
    public int getCurrentPosition(NbIO io, OutputWriter writer) {
294
        OutWriter out = io.out();
295
        int size = 0;
296
        if (out != null) {
297
            size = out.getLines().getCharCount();
298
        }
299
        return size;
300
    }
301
302
    @Override
303
    public void scrollTo(NbIO io, OutputWriter writer, int position) {
304
        io.scrollTo(position);
305
    }
306
307
    @Override
308
    public int startFold(NbIO io, OutputWriter writer, boolean expanded) {
309
        return io.startFold(expanded);
310
    }
311
312
    @Override
313
    public void endFold(NbIO io, OutputWriter writer, int foldNumber) {
314
        io.endFold(foldNumber);
315
    }
316
317
    @Override
318
    public void setFoldExpanded(NbIO io, OutputWriter writer,
319
            int foldNumber, boolean expanded) {
320
        if (expanded) {
321
            io.out().getLines().showFoldAndParentFolds(foldNumber);
322
        } else {
323
            io.out().getLines().hideFold(foldNumber);
324
        }
325
    }
326
327
    @Override
328
    public String getIODescription(NbIO io) {
329
        return io.getToolTipText();
330
    }
331
332
    @Override
333
    public void setIODescription(NbIO io, String description) {
334
        io.setTooltipText(description);
335
    }
159
}
336
}
160
337
(-)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/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 (-9 / +1 lines)
Lines 59-77 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>
63
                    <build-prerequisite/>
64
                    <compile-dependency/>
65
                    <run-dependency>
66
                        <specification-version>9.0</specification-version>
67
                    </run-dependency>
68
                </dependency>
69
                <dependency>
70
                    <code-name-base>org.openide.util.base</code-name-base>
62
                    <code-name-base>org.openide.util.base</code-name-base>
71
                    <build-prerequisite/>
63
                    <build-prerequisite/>
72
                    <compile-dependency/>
64
                    <compile-dependency/>
73
                    <run-dependency>
65
                    <run-dependency>
74
                        <specification-version>9.0</specification-version>
66
                        <specification-version>9.1</specification-version>
75
                    </run-dependency>
67
                    </run-dependency>
76
                </dependency>
68
                </dependency>
77
                <dependency>
69
                <dependency>
(-)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