View Javadoc

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  package net.sf.webphotos.gui;
17  
18  import java.sql.SQLException;
19  import java.util.logging.Level;
20  import java.util.logging.Logger;
21  import net.sf.webphotos.BancoImagem;
22  import net.sf.webphotos.util.Util;
23  import net.sf.webphotos.util.legacy.CacheFTP;
24  
25  /**
26   * Gera um frame que aloca PainelWebFotos.
27   * Seu construtor chama o método initComponents() para gerar o frame, método gerado automaticamente pela IDE.
28   * @author guilherme
29   */
30  public class FrameWebFotos extends javax.swing.JFrame {
31      
32      private static final Logger log = Logger.getLogger(FrameWebFotos.class.getName());
33      private static FrameWebFotos janela;
34      
35      /**
36       * Creates new form FrameWebFotos 
37       */
38      private FrameWebFotos() {
39          initComponents();
40          // TODO: corrigir o painel para se transformar num bean totalmente funcional
41          //add(PainelWebFotos.getInstance());
42          pack();
43          setLocationRelativeTo(null);
44      }
45      
46      /** This method is called from within the constructor to
47       * initialize the form.
48       * WARNING: Do NOT modify this code. The content of this method is
49       * always regenerated by the Form Editor.
50       */
51      // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
52      private void initComponents() {
53  
54          painelWebFotos = PainelWebFotos.getInstance();
55          menuBar = new javax.swing.JMenuBar();
56          fileMenu = new javax.swing.JMenu();
57          openMenuItem = new javax.swing.JMenuItem();
58          saveMenuItem = new javax.swing.JMenuItem();
59          saveAsMenuItem = new javax.swing.JMenuItem();
60          exitMenuItem = new javax.swing.JMenuItem();
61          editMenu = new javax.swing.JMenu();
62          cutMenuItem = new javax.swing.JMenuItem();
63          copyMenuItem = new javax.swing.JMenuItem();
64          pasteMenuItem = new javax.swing.JMenuItem();
65          deleteMenuItem = new javax.swing.JMenuItem();
66          helpMenu = new javax.swing.JMenu();
67          contentsMenuItem = new javax.swing.JMenuItem();
68          aboutMenuItem = new javax.swing.JMenuItem();
69  
70          setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
71          setTitle("WebPhotos");
72          setName("Frame WebFotos"); // NOI18N
73          addWindowListener(new java.awt.event.WindowAdapter() {
74              public void windowClosing(java.awt.event.WindowEvent evt) {
75                  formWindowClosing(evt);
76              }
77          });
78          addComponentListener(new java.awt.event.ComponentAdapter() {
79              public void componentResized(java.awt.event.ComponentEvent evt) {
80                  formComponentResized(evt);
81              }
82          });
83          getContentPane().add(painelWebFotos, java.awt.BorderLayout.CENTER);
84  
85          fileMenu.setText("Arquivo");
86  
87          openMenuItem.setText("Open");
88          fileMenu.add(openMenuItem);
89  
90          saveMenuItem.setText("Save");
91          fileMenu.add(saveMenuItem);
92  
93          saveAsMenuItem.setText("Save As ...");
94          fileMenu.add(saveAsMenuItem);
95  
96          exitMenuItem.setText("Exit");
97          exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
98              public void actionPerformed(java.awt.event.ActionEvent evt) {
99                  exitMenuItemActionPerformed(evt);
100             }
101         });
102         fileMenu.add(exitMenuItem);
103 
104         menuBar.add(fileMenu);
105 
106         editMenu.setText("Editar");
107 
108         cutMenuItem.setText("Cut");
109         editMenu.add(cutMenuItem);
110 
111         copyMenuItem.setText("Copy");
112         editMenu.add(copyMenuItem);
113 
114         pasteMenuItem.setText("Paste");
115         editMenu.add(pasteMenuItem);
116 
117         deleteMenuItem.setText("Delete");
118         editMenu.add(deleteMenuItem);
119 
120         menuBar.add(editMenu);
121 
122         helpMenu.setText("Ajuda");
123 
124         contentsMenuItem.setText("Contents");
125         helpMenu.add(contentsMenuItem);
126 
127         aboutMenuItem.setText("About");
128         helpMenu.add(aboutMenuItem);
129 
130         menuBar.add(helpMenu);
131 
132         setJMenuBar(menuBar);
133     }// </editor-fold>//GEN-END:initComponents
134 
135     private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
136         FrameWebFotos.exit();
137     }//GEN-LAST:event_exitMenuItemActionPerformed
138 
139     private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
140         // Blocks resizing if size bellow minimumSize
141         FrameWebFotos comp = (FrameWebFotos)evt.getComponent();
142         int width = comp.getSize().width;
143         int height = comp.getSize().height;
144         int minWidth = comp.getPreferredSize().width;
145         int minHeight = comp.getPreferredSize().height;
146         
147         if(width < minWidth && height < minHeight ) {
148             comp.setSize(minWidth, minHeight);
149         } else if (width < minWidth) {
150             comp.setSize(minWidth, height);
151         } else if (height < minHeight) {
152             comp.setSize(width, minHeight);
153         }
154     }//GEN-LAST:event_formComponentResized
155 
156     private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
157         FrameWebFotos.exit();
158     }//GEN-LAST:event_formWindowClosing
159     
160     /**
161      * Retorna a instância de FrameWebFotos.
162      * Caso não exista nenhuma, inicia uma.
163      * @return Retorna um frame.
164      */
165     public static FrameWebFotos getInstance() {
166         if(janela == null) {
167             janela = new FrameWebFotos();
168         }
169         return janela;
170     }
171 
172     private static void exit() {
173         log.log(Level.FINE, "Shutting down WebPhotos");
174         CacheFTP.getCache().saveFile();
175         Util.setLoggingTextArea(null);
176         try { BancoImagem.closeConnection(); } catch (SQLException ex) { }
177         getInstance().dispose();
178     }
179     
180  
181     // Variables declaration - do not modify//GEN-BEGIN:variables
182     private static javax.swing.JMenuItem aboutMenuItem;
183     private static javax.swing.JMenuItem contentsMenuItem;
184     private static javax.swing.JMenuItem copyMenuItem;
185     private static javax.swing.JMenuItem cutMenuItem;
186     private static javax.swing.JMenuItem deleteMenuItem;
187     private static javax.swing.JMenu editMenu;
188     private static javax.swing.JMenuItem exitMenuItem;
189     private static javax.swing.JMenu fileMenu;
190     private static javax.swing.JMenu helpMenu;
191     private static javax.swing.JMenuBar menuBar;
192     private static javax.swing.JMenuItem openMenuItem;
193     private static javax.swing.JPanel painelWebFotos;
194     private static javax.swing.JMenuItem pasteMenuItem;
195     private static javax.swing.JMenuItem saveAsMenuItem;
196     private static javax.swing.JMenuItem saveMenuItem;
197     // End of variables declaration//GEN-END:variables
198 
199 	
200 }