1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
27
28
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
37
38 private FrameWebFotos() {
39 initComponents();
40
41
42 pack();
43 setLocationRelativeTo(null);
44 }
45
46
47
48
49
50
51
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");
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 }
134
135 private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
136 FrameWebFotos.exit();
137 }
138
139 private void formComponentResized(java.awt.event.ComponentEvent evt) {
140
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 }
155
156 private void formWindowClosing(java.awt.event.WindowEvent evt) {
157 FrameWebFotos.exit();
158 }
159
160
161
162
163
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
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
198
199
200 }