diff --git a/manifest.mf b/manifest.mf index 42c1476..dca7d16 100644 --- a/manifest.mf +++ b/manifest.mf @@ -1,5 +1,6 @@ Manifest-Version: 1.0 OpenIDE-Module: org.fakebelieve.netbeans.plugin.logviewer OpenIDE-Module-Localizing-Bundle: org/fakebelieve/netbeans/plugin/logviewer/Bundle.properties -OpenIDE-Module-Specification-Version: 1.0.1 +OpenIDE-Module-Requires: org.openide.windows.WindowManager +OpenIDE-Module-Specification-Version: 1.1.0 diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index 02e98a6..41aa5ee 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=2f414bea +build.xml.data.CRC32=ef12045e build.xml.script.CRC32=141c9c2f build.xml.stylesheet.CRC32=a56c6a5b@2.50.1 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=2f414bea +nbproject/build-impl.xml.data.CRC32=ef12045e nbproject/build-impl.xml.script.CRC32=1d202a84 nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.50.1 diff --git a/nbproject/project.xml b/nbproject/project.xml index 935ef74..47a52e4 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -33,6 +33,15 @@ 1.31.1 + + org.netbeans.modules.settings + + + + 1 + 1.35.1 + + org.openide.actions @@ -121,6 +130,14 @@ 8.15.1 + + org.openide.windows + + + + 6.55.1 + + diff --git a/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewer.java b/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewer.java index 396e172..4bdaf87 100644 --- a/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewer.java +++ b/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewer.java @@ -15,8 +15,10 @@ import java.util.LinkedList; import java.util.logging.Level; import java.util.logging.Logger; +import javax.swing.Action; import org.openide.util.Exceptions; import org.openide.util.RequestProcessor; +import org.openide.windows.IOContainer; import org.openide.windows.IOProvider; import org.openide.windows.InputOutput; @@ -25,8 +27,9 @@ */ public class LogViewer implements Runnable { - protected int maxIoName = 36; protected static final Logger log = Logger.getLogger(LogViewer.class.getName()); + protected static IOContainer ioc = null; + protected int maxIoName = 36; ContextLogSupport logSupport; protected InputStream logStream = null; protected BufferedReader logReader = null; @@ -51,14 +54,13 @@ public class LogViewer implements Runnable { * @param process process whose streams to connect to the output window * @param ioName name of the output window tab to use */ - public LogViewer() { logSupport = new ContextLogSupport("/tmp", null); } public LogViewer(String logConfig) { this(); - + this.logConfig = logConfig; this.ioName = logConfig; } @@ -107,23 +109,27 @@ public boolean checkShouldStop() { public void run() { log.log(Level.FINE, "{0} - isClosed() = {1}", new Object[]{ioName, io.isClosed()}); if (!checkShouldStop() && !io.isClosed()) { - try { - if (maxLines > 0 && linesRead >= maxLines) { - io.getOut().reset(); - linesRead = ring.output(); - } // end of if (lines >= MAX_LINES) - - String line; - while ((line = lineReader.readLine()) != null) { - if ((line = ring.add(line)) != null) { - //io.getOut().println(line); - processLine(line); - linesRead++; - } // end of if ((line = ring.add(line)) != null) + if (intervalCount == 0) { + init(); + } else { + try { + if (maxLines > 0 && linesRead >= maxLines) { + io.getOut().reset(); + linesRead = ring.output(); + } // end of if (lines >= MAX_LINES) + + String line; + while ((line = lineReader.readLine()) != null) { + if ((line = ring.add(line)) != null) { + //io.getOut().println(line); + processLine(line); + linesRead++; + } // end of if ((line = ring.add(line)) != null) + } + + } catch (IOException e) { + log.log(Level.SEVERE, "Failed reading log file and printing to output.", e); } - - } catch (IOException e) { - log.log(Level.SEVERE, "Failed reading log file and printing to output.", e); } // For the first few intervals, update every second, just to make sure @@ -141,7 +147,14 @@ public void configViewer() throws IOException { * **/ public void showLogViewer() throws IOException { - io = IOProvider.getDefault().getIO(ioName, true); + if (ioc == null) { + ioc = IOContainer.create(new LogViewerTopComponent()); + } + //InputOutput io = IOProvider.getDefault().getIO("test", new Action[0], ioc); + //io.getOut().println("Hi there"); + //io.select(); + + io = IOProvider.getDefault().getIO(ioName, new Action[0], ioc); io.getOut().reset(); io.select(); @@ -165,7 +178,7 @@ public void showLogViewer() throws IOException { log.log(Level.FINE, "Showing error."); } - init(); + //init(); task.schedule(0); } diff --git a/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewerButtonAction.java b/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewerButtonAction.java index 9abd8fe..d72664b 100644 --- a/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewerButtonAction.java +++ b/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewerButtonAction.java @@ -25,9 +25,9 @@ id = "org.fakebelieve.netbeans.plugin.logviewer.LogViewerAction") @ActionRegistration( iconBase = "org/fakebelieve/netbeans/plugin/logviewer/wilbur.png", -displayName = "#CTL_LogViewerAction") +displayName = "#CTL_LogViewerButtonAction") @ActionReference(path = "Toolbars/Debug", position = 1050) -@Messages("CTL_LogViewerAction=Log Viewer") +@Messages("CTL_LogViewerButtonAction=Log Viewer") public class LogViewerButtonAction implements ActionListener { protected static final Logger log = Logger.getLogger(LogViewer.class.getName()); diff --git a/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewerTopComponent.form b/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewerTopComponent.form new file mode 100644 index 0000000..7feb40a --- /dev/null +++ b/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewerTopComponent.form @@ -0,0 +1,37 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewerTopComponent.java b/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewerTopComponent.java new file mode 100644 index 0000000..d95e9f4 --- /dev/null +++ b/src/org/fakebelieve/netbeans/plugin/logviewer/LogViewerTopComponent.java @@ -0,0 +1,199 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.fakebelieve.netbeans.plugin.logviewer; + +import java.awt.Component; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.Action; +import javax.swing.Icon; +import javax.swing.JComponent; +import javax.swing.JTabbedPane; +import org.netbeans.api.settings.ConvertAsProperties; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.TabbedPaneFactory; +import org.openide.util.NbBundle.Messages; +import org.openide.windows.IOContainer; +import org.openide.windows.IOContainer.CallBacks; +import org.openide.windows.TopComponent; + +/** + * Top component which displays something. + */ +@ConvertAsProperties( + dtd = "-//org.fakebelieve.netbeans.plugin.logviewer//LogViewer//EN", +autostore = false) +@TopComponent.Description( + preferredID = "LogViewerTopComponent", +iconBase = "org/fakebelieve/netbeans/plugin/logviewer/wilbur.png", +persistenceType = TopComponent.PERSISTENCE_ALWAYS) +@TopComponent.Registration(mode = "output", openAtStartup = false) +@ActionID(category = "Window", id = "org.fakebelieve.netbeans.plugin.logviewer.LogViewerTopComponent") +@ActionReference(path = "Menu/Window" /*, position = 333 */) +@TopComponent.OpenActionRegistration( + displayName = "#CTL_LogViewerAction", +preferredID = "LogViewerTopComponent") +@Messages({ + "CTL_LogViewerAction=Log Viewer", + "CTL_LogViewerTopComponent=Log Viewer", + "HINT_LogViewerTopComponent=Log Viewer Plugin Window" +}) +public final class LogViewerTopComponent extends TopComponent implements IOContainer.Provider { + + private boolean activated; + protected static final Logger log = Logger.getLogger(LogViewer.class.getName()); + + public LogViewerTopComponent() { + initComponents(); + setName(Bundle.CTL_LogViewerTopComponent()); + setToolTipText(Bundle.HINT_LogViewerTopComponent()); + + } + + private JTabbedPane createTabbedPane() { + JTabbedPane pane = TabbedPaneFactory.createCloseButtonTabbedPane(); + pane.addPropertyChangeListener(TabbedPaneFactory.PROP_CLOSE, new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + JTabbedPane pane = (JTabbedPane) evt.getSource(); + int sel = pane.getSelectedIndex(); + Component component = pane.getSelectedComponent(); + if (component instanceof IOContainer.CallBacks) { + IOContainer.CallBacks tab = (IOContainer.CallBacks) component; + tab.closed(); + } + pane.removeTabAt(sel); + } + }); + return pane; + } + + /** + * This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + jTabbedPane1 = createTabbedPane(); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE) + ); + }// //GEN-END:initComponents + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JTabbedPane jTabbedPane1; + // End of variables declaration//GEN-END:variables + + @Override + public void componentOpened() { + super.componentOpened(); + } + + @Override + public void componentClosed() { + log.log(Level.FINE, "Closed. Shutting down tabs."); + for (Component component : jTabbedPane1.getComponents()) { + if (component instanceof IOContainer.CallBacks) { + IOContainer.CallBacks tab = (IOContainer.CallBacks) component; + tab.closed(); + } + jTabbedPane1.remove(component); + } + super.componentClosed(); + } + + void writeProperties(java.util.Properties p) { + // better to version settings since initial version as advocated at + // http://wiki.apidesign.org/wiki/PropertyFiles + p.setProperty("version", "1.0"); + // TODO store your settings + } + + void readProperties(java.util.Properties p) { + String version = p.getProperty("version"); + // TODO read your settings according to their version + } + + @Override + public boolean isActivated() { + return activated; + } + + @Override + public void add(JComponent comp, CallBacks cb) { + log.log(Level.FINE, "CLASS = {0}", comp.getClass().getName()); + jTabbedPane1.add(comp); + validate(); + } + + @Override + public void remove(JComponent jc) { + if (jc instanceof IOContainer.CallBacks) { + IOContainer.CallBacks tab = (IOContainer.CallBacks) jc; + } + jTabbedPane1.remove(jc); + } + + @Override + public void select(JComponent jc) { + jTabbedPane1.setSelectedComponent(jc); + } + + @Override + public JComponent getSelected() { + return (JComponent) jTabbedPane1.getSelectedComponent(); + } + + @Override + public boolean isCloseable(JComponent jc) { + return true; + } + + @Override + public int getPersistenceType() { + return PERSISTENCE_NEVER; + } + + private int indexOfComponent(Component comp) { + for (int idx = 0; idx < jTabbedPane1.getComponentCount(); idx++) { + if (comp.equals(jTabbedPane1.getComponentAt(idx))) { + return idx; + } + } + return 0; + } + + @Override + public void setToolbarActions(JComponent jc, Action[] actions) { + } + + @Override + public void setTitle(JComponent jc, String string) { + jTabbedPane1.setTitleAt(indexOfComponent(jc), string); + } + + @Override + public void setToolTipText(JComponent jc, String string) { + jTabbedPane1.setToolTipTextAt(indexOfComponent(jc), string); + } + + @Override + public void setIcon(JComponent jc, Icon icon) { + jTabbedPane1.setIconAt(indexOfComponent(jc), icon); + } +}