View Javadoc

1   // Copyright (C) 2004, Brian Enigma <enigma at netninja.com>
2   // This file is part of iGallery.
3   //
4   // iGallery is free software; you can redistribute it and/or modify
5   // it under the terms of the GNU General Public License as published by
6   // the Free Software Foundation; either version 2 of the License, or
7   // (at your option) any later version.
8   //
9   // iGallery is distributed in the hope that it will be useful,
10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  // GNU General Public License for more details.
13  //
14  // You should have received a copy of the GNU General Public License
15  // along with Foobar; if not, write to the Free Software
16  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  package org.ninjasoft.igallery.swingui;
18  
19  import java.awt.*;
20  import javax.swing.*;
21  
22  /***
23   * @author enigma
24   *
25   * To change the template for this generated type comment go to
26   * Window - Preferences - Java - Code Generation - Code and Comments
27   */
28  public class PanelBuilder {
29      public static JPanel createLoginPanel(  JTextField urlText,
30  											JTextField usernameText,
31  											JPasswordField passwordText,
32  											JButton loginButton,
33                                              JCheckBox debugCheckbox) {
34          JPanel panel = new JPanel();
35          panel.setLayout(new GridBagLayout());
36          panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 0, 20));
37          GridBagConstraints c = new GridBagConstraints();
38          c.insets = new Insets(3, 3, 3, 3);
39          c.gridx = c.gridy = 0;
40          c.gridwidth = c.gridheight = 1;
41          c.weighty = 1;
42          c.weightx = 1;
43          c.anchor = GridBagConstraints.EAST;
44          c.fill = GridBagConstraints.NONE;
45          panel.add(new JLabel("Gallery URL:"), c);
46          c.gridx++;
47          c.weightx = 6;
48          c.anchor = GridBagConstraints.WEST;
49          c.fill = GridBagConstraints.HORIZONTAL;
50          panel.add(urlText, c);
51          c.gridx = 0;
52          c.gridy++;
53          c.weightx = 1;
54          c.anchor = GridBagConstraints.EAST;
55          c.fill = GridBagConstraints.NONE;
56          panel.add(new JLabel("Username:"), c);
57          c.gridx++;
58          c.weightx = 6;
59          c.anchor = GridBagConstraints.WEST;
60          c.fill = GridBagConstraints.HORIZONTAL;
61          panel.add(usernameText, c);
62          c.gridx = 0;
63          c.gridy++;
64          c.weightx = 1;
65          c.anchor = GridBagConstraints.EAST;
66          c.fill = GridBagConstraints.NONE;
67          panel.add(new JLabel("Password:"), c);
68          c.gridx++;
69          c.weightx = 6;
70          c.anchor = GridBagConstraints.WEST;
71          c.fill = GridBagConstraints.HORIZONTAL;
72          panel.add(passwordText, c);
73          c.gridx = 0;
74          c.gridy++;
75          c.weightx = 1;
76          c.gridwidth = 1;
77          c.anchor = GridBagConstraints.WEST;
78          c.fill = GridBagConstraints.NONE;
79          panel.add(debugCheckbox, c);
80          c.gridx++;
81          c.weightx = 1;
82          c.gridwidth = 1;
83          c.anchor = GridBagConstraints.EAST;
84          c.fill = GridBagConstraints.NONE;
85          panel.add(loginButton, c);
86          c.gridx = 0;
87          c.gridy++;
88          c.weightx = 1;
89          c.gridwidth = 2;
90          c.anchor = GridBagConstraints.CENTER;
91          c.fill = GridBagConstraints.HORIZONTAL;
92          panel.add(new JSeparator(), c);
93          return panel;
94      }
95      public static JPanel createLists(JTable iPhotoTable, JTable galleryTable) {
96          JPanel panel = new JPanel();
97          panel.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 20));
98          panel.setLayout(new GridBagLayout());
99          GridBagConstraints c = new GridBagConstraints();
100         c.insets = new Insets(3, 3, 3, 3);
101         c.gridx = c.gridy = 0;
102         c.weightx = 0;
103         c.weighty = 0;
104         c.anchor = GridBagConstraints.WEST;
105         c.fill = GridBagConstraints.NONE;
106         c.gridwidth = 1;
107         c.gridheight = 1;
108         panel.add(new JLabel("iPhoto Albums"), c);
109         c.gridx += 2;
110         panel.add(new JLabel("Gallery Albums"), c);
111         c.gridx = 0;
112         c.gridy++;
113         c.weightx = 3;
114         c.weighty = 3;
115         c.anchor = GridBagConstraints.CENTER;
116         c.fill = GridBagConstraints.BOTH;
117         panel.add(new JScrollPane(iPhotoTable), c);
118         c.gridx++;
119         c.weightx = 1;
120         c.weighty = 3;
121         c.anchor = GridBagConstraints.CENTER;
122         c.fill = GridBagConstraints.VERTICAL;
123         panel.add(new JLabel(new ImageIcon(PanelBuilder.class.getResource("/org/ninjasoft/igallery/swingui/images/arrow.gif"))), c);
124         c.gridx++;
125         c.weightx = 3;
126         c.weighty = 3;
127         c.anchor = GridBagConstraints.CENTER;
128         c.fill = GridBagConstraints.BOTH;
129         panel.add(new JScrollPane(galleryTable), c);
130         return panel;
131     }
132     public static JPanel createButtons(JTextArea status, JButton compareButton, JPanel buttonSwapPanel, JButton cancelButton, JButton uploadButton) {
133         JPanel panel = new JPanel();
134         panel.setBorder(BorderFactory.createEmptyBorder(0, 20, 20, 20));
135         panel.setLayout(new GridBagLayout());
136         GridBagConstraints c = new GridBagConstraints();
137         c.insets = new Insets(3, 3, 3, 3);
138         c.gridx = c.gridy = 0;
139         c.weightx = 4;
140         c.weighty = 1;
141         c.anchor = GridBagConstraints.WEST;
142         c.fill = GridBagConstraints.HORIZONTAL;
143         c.gridwidth = 1;
144         c.gridheight = 2;
145         JScrollPane scrolly = new JScrollPane(status, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
146         scrolly.setOpaque(false);
147         panel.add(scrolly, c);
148         
149         int width = Math.max(Math.max(compareButton.getWidth(), uploadButton.getWidth()), cancelButton.getWidth());
150         compareButton.setSize(width, compareButton.getHeight());
151         uploadButton.setSize(width, uploadButton.getHeight());
152         cancelButton.setSize(width, cancelButton.getHeight());
153         buttonSwapPanel.setSize(width, Math.max(uploadButton.getHeight(), cancelButton.getHeight()));
154         
155         c.weightx = 1;
156         c.weighty = 1;
157         c.gridwidth = 1;
158         c.gridheight = 1;
159         c.gridy = 0;
160         c.gridx++;
161         c.fill = GridBagConstraints.HORIZONTAL;
162         c.anchor = GridBagConstraints.SOUTHEAST;
163         panel.add(compareButton, c);
164         c.gridy++;
165         c.anchor = GridBagConstraints.NORTHEAST;
166         panel.add(buttonSwapPanel, c);
167         return panel;
168     }
169 }