Coverage Report - net.sf.webphotos.netbeans.WebPhotosFormTopComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
WebPhotosFormTopComponent
0%
0/127
0%
0/10
1,467
WebPhotosFormTopComponent$1
0%
0/5
N/A
1,467
WebPhotosFormTopComponent$ResolvableHelper
0%
0/2
N/A
1,467
 
 1  
 /**
 2  
  * Copyright 2008 WebPhotos
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 /*
 17  
  * To change this template, choose Tools | Templates
 18  
  * and open the template in the editor.
 19  
  */
 20  
 package net.sf.webphotos.netbeans;
 21  
 
 22  
 import java.awt.event.MouseEvent;
 23  
 import java.io.Serializable;
 24  
 import java.util.logging.Logger;
 25  
 import org.openide.util.ImageUtilities;
 26  
 import org.openide.util.NbBundle;
 27  
 import org.openide.windows.TopComponent;
 28  
 import org.openide.windows.WindowManager;
 29  
 
 30  
 /**
 31  
  * Top component which displays something.
 32  
  */
 33  0
 final class WebPhotosFormTopComponent extends TopComponent {
 34  
 
 35  
     private static WebPhotosFormTopComponent instance;
 36  
     /** path to the icon used by the component and its open action */
 37  
     static final String ICON_PATH = "net/sf/webphotos/netbeans/frame.png";
 38  
     private static final String PREFERRED_ID = "WebPhotosFormTopComponent";
 39  
 
 40  0
     private WebPhotosFormTopComponent() {
 41  0
         initComponents();
 42  0
         setName(NbBundle.getMessage(WebPhotosFormTopComponent.class, "CTL_WebPhotosFormTopComponent"));
 43  0
         setToolTipText(NbBundle.getMessage(WebPhotosFormTopComponent.class, "HINT_WebPhotosFormTopComponent"));
 44  0
         setIcon(ImageUtilities.loadImage(ICON_PATH, true));
 45  
 
 46  0
     }
 47  
 
 48  
     public void tbFotosPopupCalled(MouseEvent evt) {
 49  0
         if (tbFotos.getSelectedRowCount() <= 1) {
 50  0
             int selecao = tbFotos.rowAtPoint(evt.getPoint());
 51  0
             tbFotos.setRowSelectionInterval(selecao, selecao);
 52  
         }
 53  0
         if (evt.isPopupTrigger()) {
 54  
             //menuFoto.show(evt.getComponent(), evt.getX(), evt.getY());
 55  
         }
 56  0
     }
 57  
 
 58  
     /** This method is called from within the constructor to
 59  
      * initialize the form.
 60  
      * WARNING: Do NOT modify this code. The content of this method is
 61  
      * always regenerated by the Form Editor.
 62  
      */
 63  
     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
 64  
     private void initComponents() {
 65  
         java.awt.GridBagConstraints gridBagConstraints;
 66  
 
 67  0
         painelInfoAlbum = new javax.swing.JPanel();
 68  0
         lblAlbum = new javax.swing.JLabel();
 69  0
         txtTitulo = new javax.swing.JTextField();
 70  0
         lblCategoria = new javax.swing.JLabel();
 71  0
         lstCategoriasAlbum = new javax.swing.JComboBox();
 72  0
         lblData = new javax.swing.JLabel();
 73  0
         txtData = new javax.swing.JFormattedTextField();
 74  0
         lblDescricao = new javax.swing.JLabel();
 75  0
         scrDescricao = new javax.swing.JScrollPane();
 76  0
         txtDescricao = new javax.swing.JTextArea();
 77  0
         scrFotos = new javax.swing.JScrollPane();
 78  0
         tbFotos = new javax.swing.JTable();
 79  
 
 80  0
         setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
 81  0
         setLayout(new java.awt.BorderLayout());
 82  
 
 83  0
         painelInfoAlbum.setMinimumSize(new java.awt.Dimension(500, 250));
 84  0
         painelInfoAlbum.setPreferredSize(new java.awt.Dimension(500, 300));
 85  0
         painelInfoAlbum.setLayout(new java.awt.GridBagLayout());
 86  
 
 87  0
         org.openide.awt.Mnemonics.setLocalizedText(lblAlbum, org.openide.util.NbBundle.getMessage(WebPhotosFormTopComponent.class, "WebPhotosFormTopComponent.lblAlbum.text")); // NOI18N
 88  0
         gridBagConstraints = new java.awt.GridBagConstraints();
 89  0
         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
 90  0
         gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
 91  0
         painelInfoAlbum.add(lblAlbum, gridBagConstraints);
 92  
 
 93  0
         txtTitulo.setPreferredSize(new java.awt.Dimension(477, 22));
 94  0
         gridBagConstraints = new java.awt.GridBagConstraints();
 95  0
         gridBagConstraints.gridx = 1;
 96  0
         gridBagConstraints.gridy = 0;
 97  0
         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
 98  0
         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
 99  0
         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
 100  0
         gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
 101  0
         painelInfoAlbum.add(txtTitulo, gridBagConstraints);
 102  
 
 103  0
         org.openide.awt.Mnemonics.setLocalizedText(lblCategoria, org.openide.util.NbBundle.getMessage(WebPhotosFormTopComponent.class, "WebPhotosFormTopComponent.lblCategoria.text")); // NOI18N
 104  0
         gridBagConstraints = new java.awt.GridBagConstraints();
 105  0
         gridBagConstraints.gridx = 0;
 106  0
         gridBagConstraints.gridy = 1;
 107  0
         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
 108  0
         gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
 109  0
         painelInfoAlbum.add(lblCategoria, gridBagConstraints);
 110  
 
 111  0
         lstCategoriasAlbum.setModel(/*new javax.swing.DefaultComboBoxModel(Album.getAlbum().getCategoriasArray())*/new javax.swing.DefaultComboBoxModel());
 112  0
         gridBagConstraints = new java.awt.GridBagConstraints();
 113  0
         gridBagConstraints.gridx = 1;
 114  0
         gridBagConstraints.gridy = 1;
 115  0
         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
 116  0
         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
 117  0
         gridBagConstraints.weightx = 5.0;
 118  0
         gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
 119  0
         painelInfoAlbum.add(lstCategoriasAlbum, gridBagConstraints);
 120  
 
 121  0
         org.openide.awt.Mnemonics.setLocalizedText(lblData, org.openide.util.NbBundle.getMessage(WebPhotosFormTopComponent.class, "WebPhotosFormTopComponent.lblData.text")); // NOI18N
 122  0
         gridBagConstraints = new java.awt.GridBagConstraints();
 123  0
         gridBagConstraints.gridx = 2;
 124  0
         gridBagConstraints.gridy = 1;
 125  0
         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
 126  0
         gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
 127  0
         painelInfoAlbum.add(lblData, gridBagConstraints);
 128  
 
 129  0
         txtData.setMinimumSize(new java.awt.Dimension(11, 22));
 130  0
         txtData.setPreferredSize(new java.awt.Dimension(72, 22));
 131  0
         gridBagConstraints = new java.awt.GridBagConstraints();
 132  0
         gridBagConstraints.gridx = 3;
 133  0
         gridBagConstraints.gridy = 1;
 134  0
         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
 135  0
         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
 136  0
         gridBagConstraints.weightx = 1.0;
 137  0
         gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
 138  0
         painelInfoAlbum.add(txtData, gridBagConstraints);
 139  
 
 140  0
         org.openide.awt.Mnemonics.setLocalizedText(lblDescricao, org.openide.util.NbBundle.getMessage(WebPhotosFormTopComponent.class, "WebPhotosFormTopComponent.lblDescricao.text")); // NOI18N
 141  0
         gridBagConstraints = new java.awt.GridBagConstraints();
 142  0
         gridBagConstraints.gridx = 0;
 143  0
         gridBagConstraints.gridy = 2;
 144  0
         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
 145  0
         gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
 146  0
         painelInfoAlbum.add(lblDescricao, gridBagConstraints);
 147  
 
 148  0
         scrDescricao.setAutoscrolls(true);
 149  
 
 150  0
         txtDescricao.setLineWrap(true);
 151  0
         txtDescricao.setWrapStyleWord(true);
 152  0
         scrDescricao.setViewportView(txtDescricao);
 153  
 
 154  0
         gridBagConstraints = new java.awt.GridBagConstraints();
 155  0
         gridBagConstraints.gridx = 1;
 156  0
         gridBagConstraints.gridy = 2;
 157  0
         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
 158  0
         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
 159  0
         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
 160  0
         gridBagConstraints.weighty = 5.0;
 161  0
         gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
 162  0
         painelInfoAlbum.add(scrDescricao, gridBagConstraints);
 163  
 
 164  0
         tbFotos.setToolTipText(org.openide.util.NbBundle.getMessage(WebPhotosFormTopComponent.class, "WebPhotosFormTopComponent.tbFotos.toolTipText")); // NOI18N
 165  0
         tbFotos.addMouseListener(new java.awt.event.MouseAdapter() {
 166  
             public void mousePressed(java.awt.event.MouseEvent evt) {
 167  0
                 tbFotosMousePressed(evt);
 168  0
             }
 169  
             public void mouseReleased(java.awt.event.MouseEvent evt) {
 170  0
                 tbFotosMouseReleased(evt);
 171  0
             }
 172  
         });
 173  0
         scrFotos.setViewportView(tbFotos);
 174  
 
 175  0
         gridBagConstraints = new java.awt.GridBagConstraints();
 176  0
         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
 177  0
         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
 178  0
         gridBagConstraints.weighty = 10.0;
 179  0
         gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
 180  0
         painelInfoAlbum.add(scrFotos, gridBagConstraints);
 181  
 
 182  0
         add(painelInfoAlbum, java.awt.BorderLayout.CENTER);
 183  0
     }// </editor-fold>//GEN-END:initComponents
 184  
 
 185  
     private void tbFotosMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbFotosMousePressed
 186  0
         tbFotosPopupCalled(evt);
 187  0
 }//GEN-LAST:event_tbFotosMousePressed
 188  
 
 189  
     private void tbFotosMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbFotosMouseReleased
 190  0
         tbFotosPopupCalled(evt);
 191  0
 }//GEN-LAST:event_tbFotosMouseReleased
 192  
     // Variables declaration - do not modify//GEN-BEGIN:variables
 193  
     private javax.swing.JLabel lblAlbum;
 194  
     private javax.swing.JLabel lblCategoria;
 195  
     private javax.swing.JLabel lblData;
 196  
     private javax.swing.JLabel lblDescricao;
 197  
     private javax.swing.JComboBox lstCategoriasAlbum;
 198  
     private javax.swing.JPanel painelInfoAlbum;
 199  
     private javax.swing.JScrollPane scrDescricao;
 200  
     private javax.swing.JScrollPane scrFotos;
 201  
     private javax.swing.JTable tbFotos;
 202  
     private javax.swing.JFormattedTextField txtData;
 203  
     private javax.swing.JTextArea txtDescricao;
 204  
     private javax.swing.JTextField txtTitulo;
 205  
     // End of variables declaration//GEN-END:variables
 206  
 
 207  
     /**
 208  
      * Gets default instance. Do not use directly: reserved for *.settings files only,
 209  
      * i.e. deserialization routines; otherwise you could get a non-deserialized instance.
 210  
      * To obtain the singleton instance, use {@link #findInstance}.
 211  
      */
 212  
     public static synchronized WebPhotosFormTopComponent getDefault() {
 213  0
         if (instance == null) {
 214  0
             instance = new WebPhotosFormTopComponent();
 215  
         }
 216  0
         return instance;
 217  
     }
 218  
 
 219  
     /**
 220  
      * Obtain the WebPhotosFormTopComponent instance. Never call {@link #getDefault} directly!
 221  
      */
 222  
     public static synchronized WebPhotosFormTopComponent findInstance() {
 223  0
         TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
 224  0
         if (win == null) {
 225  0
             Logger.getLogger(WebPhotosFormTopComponent.class.getName()).warning(
 226  
                     "Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system.");
 227  0
             return getDefault();
 228  
         }
 229  0
         if (win instanceof WebPhotosFormTopComponent) {
 230  0
             return (WebPhotosFormTopComponent) win;
 231  
         }
 232  0
         Logger.getLogger(WebPhotosFormTopComponent.class.getName()).warning(
 233  
                 "There seem to be multiple components with the '" + PREFERRED_ID +
 234  
                 "' ID. That is a potential source of errors and unexpected behavior.");
 235  0
         return getDefault();
 236  
     }
 237  
 
 238  
     @Override
 239  
     public int getPersistenceType() {
 240  0
         return TopComponent.PERSISTENCE_ALWAYS;
 241  
     }
 242  
 
 243  
     @Override
 244  
     public void componentOpened() {
 245  
         // TODO add custom code on component opening
 246  0
     }
 247  
 
 248  
     @Override
 249  
     public void componentClosed() {
 250  
         // TODO add custom code on component closing
 251  0
     }
 252  
 
 253  
     /** replaces this in object stream */
 254  
     @Override
 255  
     public Object writeReplace() {
 256  0
         return new ResolvableHelper();
 257  
     }
 258  
 
 259  
     @Override
 260  
     protected String preferredID() {
 261  0
         return PREFERRED_ID;
 262  
     }
 263  
 
 264  0
     final static class ResolvableHelper implements Serializable {
 265  
 
 266  
         private static final long serialVersionUID = 1L;
 267  
 
 268  
         public Object readResolve() {
 269  0
             return WebPhotosFormTopComponent.getDefault();
 270  
         }
 271  
     }
 272  
 }