Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
   *
   * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   * Other names may be trademarks of their respective owners.
   *
   * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common
  * Development and Distribution License("CDDL") (collectively, the
  * "License"). You may not use this file except in compliance with the
  * License. You can obtain a copy of the License at
  * http://www.netbeans.org/cddl-gplv2.html
  * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  * specific language governing permissions and limitations under the
  * License.  When distributing the software, include this License Header
  * Notice in each file and include the License file at
  * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
  * particular file as subject to the "Classpath" exception as provided
  * by Oracle in the GPL Version 2 section of the License file that
  * accompanied this code. If applicable, add the following below the
  * License Header, with the fields enclosed by brackets [] replaced by
  * your own identifying information:
  * "Portions Copyrighted [year] [name of copyright owner]"
  *
  * Contributor(s):
  * The Original Software is NetBeans. The Initial Developer of the Original
  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
  * Microsystems, Inc. All Rights Reserved.
  *
  * If you wish your version of this file to be governed by only the CDDL
  * or only the GPL Version 2, indicate your decision by adding
  * "[Contributor] elects to include this software in this distribution
  * under the [CDDL or GPL Version 2] license." If you do not indicate a
  * single choice of license, a recipient has the option to distribute
  * your version of this file under either the CDDL, the GPL Version 2 or
  * to extend the choice of license to its licensees as provided above.
  * However, if you add GPL Version 2 code and therefore, elected the GPL
  * Version 2 license, then the option applies only if the new code is
  * made subject to such option by the copyright holder.
  */
 
 package org.netbeans.modules.profiler.ppoints;
 
 import java.awt.Font;
 import java.io.File;
 import java.net.URL;
 import java.util.List;

Author(s):
Jiri Sedlacek
 
     "ResetResultsProfilingPoint_OneHitString=<b>1 hit</b> at {0}, <a href='#'>report</a>",
     "ResetResultsProfilingPoint_NHitsString=<b>{0} hits</b>, last at {1}, <a href='#'>report</a>",
     "ResetResultsProfilingPoint_NoResultsString=No results available",
     "ResetResultsProfilingPoint_ReportAccessDescr=Report of {0}",
     "ResetResultsProfilingPoint_NoHitsString=no hits",
     "ResetResultsProfilingPoint_HeaderTypeString=<b>Type:</b> {0}",
     "ResetResultsProfilingPoint_HeaderEnabledString=<b>Enabled:</b> {0}",
     "ResetResultsProfilingPoint_HeaderProjectString=<b>Project:</b> {0}",
     "ResetResultsProfilingPoint_HeaderLocationString=<b>Location:</b> <a href='#'>{0}, line {1}</a>",
     "ResetResultsProfilingPoint_HeaderHitsString=<b>Hits:</b> {0}",
     "ResetResultsProfilingPoint_HitSuccessString=<b>{0}.</b> hit at <b>{1}</b>",
     "ResetResultsProfilingPoint_DataString=Data:"
 })
 public final class ResetResultsProfilingPoint extends CodeProfilingPoint.Single implements PropertyChangeListener {
     //~ Inner Classes ------------------------------------------------------------------------------------------------------------
 
     private class Annotation extends CodeProfilingPoint.Annotation {
         //~ Methods --------------------------------------------------------------------------------------------------------------
 
         @Override
         public String getAnnotationType() {
            return ResetResultsProfilingPoint.this.isEnabled() ?  : ;
        }
        @Override
        public String getShortDescription() {
            return getName();
        }
        @Override
        public CodeProfilingPoint profilingPoint() {
            return ResetResultsProfilingPoint.this;
        }
    }
    private class Report extends ProfilingPointReport {
        //~ Instance fields ------------------------------------------------------------------------------------------------------
        private HTMLTextArea dataArea;
        private HTMLTextArea headerArea;
        //~ Constructors ---------------------------------------------------------------------------------------------------------
        public Report() {
            initDefaults();
            initComponents();
            refresh();
        }
        //~ Methods --------------------------------------------------------------------------------------------------------------
        protected void refresh() {
            StringBuilder headerAreaTextBuilder = new StringBuilder();
            headerAreaTextBuilder.append(getHeaderName());
            headerAreaTextBuilder.append("<br>"); // NOI18N
            headerAreaTextBuilder.append("&nbsp;&nbsp;&nbsp;&nbsp;");
            headerAreaTextBuilder.append(getHeaderType());
            headerAreaTextBuilder.append("<br>"); // NOI18N
            headerAreaTextBuilder.append("&nbsp;&nbsp;&nbsp;&nbsp;");
            headerAreaTextBuilder.append(getHeaderEnabled());
            headerAreaTextBuilder.append("<br>"); // NOI18N
            headerAreaTextBuilder.append("&nbsp;&nbsp;&nbsp;&nbsp;");
            headerAreaTextBuilder.append(getHeaderProject());
            headerAreaTextBuilder.append("<br>"); // NOI18N
            headerAreaTextBuilder.append("&nbsp;&nbsp;&nbsp;&nbsp;");
            headerAreaTextBuilder.append(getHeaderLocation());
            headerAreaTextBuilder.append("<br>"); // NOI18N
            headerAreaTextBuilder.append("&nbsp;&nbsp;&nbsp;&nbsp;");
            headerAreaTextBuilder.append(getHeaderHitsCount()); // NOI18N
            .setText(headerAreaTextBuilder.toString());
            StringBuilder dataAreaTextBuilder = new StringBuilder();
            synchronized() {
                if (.isEmpty()) {
                    dataAreaTextBuilder.append(ProfilingPointReport.getNoDataHint(ResetResultsProfilingPoint.this));
                } else {
                    for (int i = 0; i < .size(); i++) {
                        dataAreaTextBuilder.append("&nbsp;&nbsp;");
                        dataAreaTextBuilder.append(getDataResultItem(i));
                        dataAreaTextBuilder.append("<br>"); // NOI18N
                    }
                    ProfilingPointsManager m = ProfilingPointsManager.getDefault();
                    if (!m.belowMaxHits(.size()))
                        dataAreaTextBuilder.append(m.getTruncatedResultsText());
                }
            }
            .setText(dataAreaTextBuilder.toString());
        }
        void refreshProperties() {
            setName(ResetResultsProfilingPoint.this.getName());
            setIcon(((ImageIconResetResultsProfilingPoint.this.getFactory().getIcon()).getImage());
        }
        private String getDataResultItem(int index) {
            synchronized() {
                Result result = .get(index);
                // TODO: enable once thread name by id is available
                //String threadName = Utils.getThreadName(result.getThreadID());
                //String threadClassName = Utils.getThreadClassName(result.getThreadID());
                //String threadInformation = (threadName == null ? "&lt;unknown thread&gt;" : (threadClassName == null ? threadName : threadName + " (" + threadClassName + ")"));
                //return "<b>" + (index + 1) + ".</b> hit at <b>" + Utils.formatProfilingPointTimeHiRes(result.getTimestamp()) + "</b> by " + threadInformation;
                return Bundle.ResetResultsProfilingPoint_HitSuccessString((index + 1), Utils.formatProfilingPointTimeHiRes(result.getTimestamp()));
            }
        }
        private String getHeaderEnabled() {
        }
        private String getHeaderHitsCount() {
            synchronized() {
                return Bundle.ResetResultsProfilingPoint_HeaderHitsString(.size());
            }
        }
        private String getHeaderLocation() {
            CodeProfilingPoint.Location location = ResetResultsProfilingPoint.this.getLocation();
            String shortFileName = new File(location.getFile()).getName();
            int lineNumber = location.getLine();
            return Bundle.ResetResultsProfilingPoint_HeaderLocationString(shortFileNamelineNumber);
        }
        private String getHeaderName() {
            return "<h2><b>" + ResetResultsProfilingPoint.this.getName() + "</b></h2>"// NOI18N
        }
        private String getHeaderProject() {
            return Bundle.ResetResultsProfilingPoint_HeaderProjectString(
                        ProjectUtilities.getDisplayName(ResetResultsProfilingPoint.this.getProject()));
        }
        private String getHeaderType() {
            return Bundle.ResetResultsProfilingPoint_HeaderTypeString(
                        ResetResultsProfilingPoint.this.getFactory().getType());
        }
        private void initComponents() {
            setLayout(new BorderLayout());
            JPanel contentsPanel = new JPanel(new BorderLayout());
            contentsPanel.setBackground(UIUtils.getProfilerResultsBackground());
            contentsPanel.setOpaque(true);
            contentsPanel.setBorder(BorderFactory.createMatteBorder(0, 15, 15, 15, UIUtils.getProfilerResultsBackground()));
             = new HTMLTextArea() {
                    protected void showURL(URL url) {
                        Utils.openLocation(ResetResultsProfilingPoint.this.getLocation());
                    }
                };
            JScrollPane headerAreaScrollPane = new JScrollPane(.,
                                                               .);
            headerAreaScrollPane.setBorder(BorderFactory.createMatteBorder(0, 0, 15, 0, UIUtils.getProfilerResultsBackground()));
            headerAreaScrollPane.setViewportBorder(BorderFactory.createEmptyBorder());
            contentsPanel.add(headerAreaScrollPane.);
             = new HTMLTextArea();
            JScrollPane dataAreaScrollPane = new JScrollPane(.,
                                                             .);
            TitledBorder tb = new TitledBorder(Bundle.ResetResultsProfilingPoint_DataString());
            tb.setTitleFont(Utils.getTitledBorderFont(tb).deriveFont(.));
            tb.setTitleColor(javax.swing.UIManager.getColor("Label.foreground")); // NOI18N
            dataAreaScrollPane.setBorder(tb);
            dataAreaScrollPane.setViewportBorder(BorderFactory.createEmptyBorder());
            dataAreaScrollPane.setBackground(UIUtils.getProfilerResultsBackground());
            contentsPanel.add(dataAreaScrollPane.);
            add(contentsPanel.);
        }
        private void initDefaults() {
            refreshProperties();
            setFocusable(true);
        }
    }
    private static class Result {
        //~ Instance fields ------------------------------------------------------------------------------------------------------
        private final int threadId;
        private final long timestamp;
        //~ Constructors ---------------------------------------------------------------------------------------------------------
        public Result(long timestampint threadId) {
            this. = timestamp;
            this. = threadId;
        }
        //~ Methods --------------------------------------------------------------------------------------------------------------
        public int getThreadID() {
            return ;
        }
        public long getTimestamp() {
            return ;
        }
    }
    //~ Static fields/initializers -----------------------------------------------------------------------------------------------
    // --- Implementation --------------------------------------------------------
    private static final String ANNOTATION_ENABLED = "resetResultsProfilingPoint"// NOI18N
    private static final String ANNOTATION_DISABLED = "resetResultsProfilingPointD"// NOI18N
    //~ Instance fields ----------------------------------------------------------------------------------------------------------
    private Annotation annotation;
    private List<Resultresults = new ArrayList();
    private final Object resultsSync = new Object();
    //~ Constructors -------------------------------------------------------------------------------------------------------------
    public ResetResultsProfilingPoint(String nameLocation locationLookup.Provider projectProfilingPointFactory factory) {
        super(namelocationprojectfactory);
    }
    //~ Methods ------------------------------------------------------------------------------------------------------------------
    public boolean hasResults() {
        synchronized() {
            return .size() > 0;
        }
    }
    public void hideResults() {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                Report report = getReport(false);
                if (report != nullreport.close();
            }
        });
    }
    public void propertyChange(PropertyChangeEvent evt) {
        Report report = getReport(false);
        if (report != null) {
            if (evt.getPropertyName() == ) {
                report.refreshProperties();
            }
            report.refresh();
        }
    }
    public void showResults(URL url) {
        TopComponent topComponent = getReport(true);
        topComponent.open();
        topComponent.requestActive();
    }
        if ( == null) {
             = new Annotation();
        }
        return ;
    }
    protected String getResultsText() {
        synchronized() {
            if (hasResults()) {
                int size = .size();
                long timeStamp = .get(size - 1).getTimestamp();
                String time = Utils.formatProfilingPointTime(timeStamp);
                return (size == 1)
                       ? Bundle.ResetResultsProfilingPoint_OneHitString(time)
                       : Bundle.ResetResultsProfilingPoint_NHitsString(sizetime);
            } else {
                return Bundle.LoadGenProfilingPoint_NoResultsString();
            }
        }
    }
    protected void updateCustomizer(ValidityAwarePanel c) {
        ResetResultsCustomizer customizer = (ResetResultsCustomizerc;
        customizer.setPPName(getName());
        customizer.setPPLocation(getLocation());
    }
    void setValues(ValidityAwarePanel c) {
        ResetResultsCustomizer customizer = (ResetResultsCustomizerc;
        setName(customizer.getPPName());
        setLocation(customizer.getPPLocation());
        
        Utils.checkLocation(this);
    }
    void hit(RuntimeProfilingPoint.HitEvent hitEventint index) {
        synchronized() {
            if (ProfilingPointsManager.getDefault().belowMaxHits(.size()))
                .add(new Result(hitEvent.getTimestamp(), hitEvent.getThreadId()));
        }
        //    ResultsManager.getDefault().reset();
        getChangeSupport().firePropertyChange(falsetrue);
    }
    void reset() {
        synchronized() {
            boolean change = .size() > 0;
            .clear();
            if (change) {
                getChangeSupport().firePropertyChange(falsetrue);
            }
        }
    }
    private Report getReport(boolean create) {
        Report report =  == null ? null : .get();
        if (report == null && create) {
            report = new Report();
             = new WeakReference<Report>(report);
        }
        return report;
    }
New to GrepCode? Check out our FAQ X