/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package info.havlin.output.base.check; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import java.util.EnumSet; import java.util.Timer; import java.util.TimerTask; import org.openide.awt.ActionID; import org.openide.awt.ActionReference; import org.openide.awt.ActionRegistration; import org.openide.io.base.BaseColor; import org.openide.io.base.BaseFoldHandle; import org.openide.io.base.BaseIOColorLines; import org.openide.io.base.BaseIOColorPrint; import org.openide.io.base.BaseIOColors; import org.openide.io.base.BaseIOFolding; import org.openide.io.base.BaseIOHyperlink; import org.openide.io.base.BaseIOPosition; import org.openide.io.base.BaseIOProvider; import org.openide.io.base.BaseIOSelect; import org.openide.io.base.BaseIOTab; import org.openide.io.base.BaseInputOutput; import org.openide.io.base.BaseOutputEvent; import org.openide.io.base.BaseOutputListener; import org.openide.util.Exceptions; import org.openide.util.NbBundle.Messages; @ActionID( category = "File", id = "info.havlin.output.base.check.BasicOutputAction" ) @ActionRegistration( displayName = "#CTL_BasicOutputAction" ) @ActionReference(path = "Menu/File", position = 0, separatorAfter = 50) @Messages("CTL_BasicOutputAction=Basic Output") public final class BasicOutputAction implements ActionListener { @Override public void actionPerformed(ActionEvent e) { try (final BaseInputOutput io = BaseIOProvider.getDefault().getIO( "Test", true);) { io.getOut().println("Test1 without link"); final BaseIOPosition.Position p; if (BaseIOPosition.isSupported(io)) { p = BaseIOPosition.currentPosition(io); } else { p = null; } if (BaseIOHyperlink.isSupported(io, BaseOutputListener.class)) { BaseOutputListener ol = createOutputListener(); BaseIOHyperlink.println(io, BaseIOHyperlink.Type.OUT, "Line with a link", true, ol); } if (BaseIOSelect.isSupported(io)) { BaseIOSelect.select(io, EnumSet.of( BaseIOSelect.AdditionalOperation.OPEN, BaseIOSelect.AdditionalOperation.REQUEST_ACTIVE)); } if (BaseIOTab.isSupported(io)) { BaseIOTab.setToolTipText(io, "Test Tab"); } if (BaseIOColorLines.isSupported(io)) { BaseIOColorLines.println(io, "Red Line Output", new BaseColor(Color.RED.getRGB())); BaseOutputListener bol = new BaseOutputListener() { @Override public void outputLineAction(BaseOutputEvent ev) { } }; BaseIOColorLines.println(io, "Green Line Output with Link", true, new BaseColor(Color.GREEN.getRGB()), bol); } if (BaseIOColorPrint.isSupported(io)) { io.getOut().print("Some "); BaseIOColorPrint.print(io, "magenta", new BaseColor(Color.MAGENTA.getRGB())); io.getOut().print(" and "); BaseOutputListener bol = new BaseOutputListener() { @Override public void outputLineAction(BaseOutputEvent ev) { } }; BaseIOColorPrint.print(io, "orange", false, new BaseColor(Color.ORANGE.getRGB()), bol); io.getOut().println(" text"); } if (BaseIOColors.isSupported(io)) { BaseIOColors.setColor(io, BaseIOColors.OutputType.ERROR, new BaseColor(Color.GRAY.getRGB())); io.getErr().println("Some error printed in gray"); } if (BaseIOFolding.isSupported(io)) { BaseFoldHandle foldHandle = BaseIOFolding.startFold(io, true); io.getOut().println("Fold line 1"); io.getOut().println("Fold line 2"); io.getOut().println("Fold line 3"); foldHandle.silentFinish(); } if (BaseIOHyperlink.isSupported(io, BaseOutputListener.class)) { BaseOutputListener changePosition = new BaseOutputListener() { @Override public void outputLineAction(BaseOutputEvent ev) { new Timer("scroll").schedule(new TimerTask() { @Override public void run() { p.scrollTo(); } }, 1000); } }; BaseIOHyperlink.println(io, BaseIOHyperlink.Type.OUT, "Change position", true, changePosition); } } catch (IOException ex) { Exceptions.printStackTrace(ex); } try (final BaseInputOutput io = BaseIOProvider.getDefault().getIO( "Test", false);) { io.getOut().println("Printed to reopened I/O"); } } private BaseOutputListener createOutputListener() { return new BaseOutputListener() { @Override public void outputLineAction(BaseOutputEvent ev) { BaseInputOutput io = BaseIOProvider.getDefault().getIO("Test", false); io.getOut().println("Line action"); } }; } }