/* * Copyright (C) 2006-2012 Gabriel Burca (gburca dash virtmus at ebixio dot com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ package com.ebixio.virtmus; import java.io.Serializable; import javax.swing.ActionMap; import javax.swing.text.DefaultEditorKit; import org.openide.ErrorManager; import org.openide.explorer.ExplorerManager; import org.openide.explorer.ExplorerUtils; import org.openide.nodes.AbstractNode; import org.openide.util.ImageUtilities; import org.openide.util.NbBundle; import org.openide.windows.TopComponent; import org.openide.windows.WindowManager; /** * Top component which displays something. */ final class PlayListTopComponent extends TopComponent implements ExplorerManager.Provider { private static PlayListTopComponent instance; /** path to the icon used by the component and its open action */ static final String ICON_PATH = "com/ebixio/virtmus/resources/PlayListTopComponent.png"; private static final String PREFERRED_ID = "PlayListTopComponent"; private PlayListTopComponent() { initComponents(); setName(NbBundle.getMessage(PlayListTopComponent.class, "CTL_PlayListTopComponent")); setToolTipText(NbBundle.getMessage(PlayListTopComponent.class, "HINT_PlayListTopComponent")); setIcon(ImageUtilities.loadImage(ICON_PATH, true)); ExplorerManager manager = CommonExplorers.MainExplorerManager; ActionMap map = this.getActionMap(); map.put(DefaultEditorKit.copyAction, ExplorerUtils.actionCopy(manager)); map.put(DefaultEditorKit.cutAction, ExplorerUtils.actionCut(manager)); map.put(DefaultEditorKit.pasteAction, ExplorerUtils.actionPaste(manager)); map.put("delete", ExplorerUtils.actionDelete(manager, true)); // or false // Place the Explorer Manager in the TopComponent's Lookup associateLookup(ExplorerUtils.createLookup(manager, map)); PlayLists pl = new PlayLists(); pl.init(); manager.setRootContext(new AbstractNode(pl)); manager.getRootContext().setDisplayName("Playlists"); this.playlistTreeView.setRootVisible(false); } /** 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. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { playlistTreeView = new org.openide.explorer.view.BeanTreeView(); setOpaque(true); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(playlistTreeView, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(playlistTreeView, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private org.openide.explorer.view.BeanTreeView playlistTreeView; // End of variables declaration//GEN-END:variables /** * Gets default instance. Do not use directly: reserved for *.settings files only, * i.e. deserialization routines; otherwise you could get a non-deserialized instance. * To obtain the singleton instance, use {@link findInstance}. */ public static synchronized PlayListTopComponent getDefault() { if (instance == null) { instance = new PlayListTopComponent(); } return instance; } /** * Obtain the PlayListTopComponent instance. Never call {@link #getDefault} directly! */ public static synchronized PlayListTopComponent findInstance() { TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID); if (win == null) { ErrorManager.getDefault().log(ErrorManager.WARNING, "Cannot find MyWindow component. It will not be located properly in the window system."); return getDefault(); } if (win instanceof PlayListTopComponent) { return (PlayListTopComponent)win; } ErrorManager.getDefault().log(ErrorManager.WARNING, "There seem to be multiple components with the '" + PREFERRED_ID + "' ID. That is a potential source of errors and unexpected behavior."); return getDefault(); } @Override public int getPersistenceType() { return TopComponent.PERSISTENCE_ALWAYS; } @Override protected void componentActivated() { ExplorerUtils.activateActions(getExplorerManager(), true); // See StandardToolbar.xml and http://wiki.netbeans.org/DevFaqHideShowToolbar // Configuring toolbar from ModuleInstall.restored() because NB activates // the last activated component on start-up, so this function might not // get called until the user selects a node. //ToolbarPool.getDefault().setConfiguration("StandardToolbar"); } @Override protected void componentDeactivated() { ExplorerUtils.activateActions(getExplorerManager(), false); } @Override public ExplorerManager getExplorerManager() { return CommonExplorers.MainExplorerManager; } // <editor-fold defaultstate="collapsed" desc=" Wizzard generated "> /** replaces this in object stream */ @Override public Object writeReplace() { return new ResolvableHelper(); } @Override protected String preferredID() { return PREFERRED_ID; } final static class ResolvableHelper implements Serializable { private static final long serialVersionUID = 1L; public Object readResolve() { return PlayListTopComponent.getDefault(); } } // </editor-fold> }