001: /*
002: Copyright (C) 2004 David Bucciarelli (davibu@interfree.it)
003:
004: This program is free software; you can redistribute it and/or
005: modify it under the terms of the GNU General Public License
006: as published by the Free Software Foundation; either version 2
007: of the License, or (at your option) any later version.
008:
009: This program is distributed in the hope that it will be useful,
010: but WITHOUT ANY WARRANTY; without even the implied warranty of
011: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: GNU General Public License for more details.
013:
014: You should have received a copy of the GNU General Public License
015: along with this program; if not, write to the Free Software
016: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: */
018:
019: package org.homedns.dade.jcgrid.cmd.povray;
020:
021: import java.io.*;
022: import java.awt.*;
023: import java.awt.image.*;
024: import javax.swing.*;
025:
026: import org.apache.log4j.*;
027:
028: import org.homedns.dade.jcgrid.*;
029: import org.homedns.dade.jcgrid.cmd.*;
030: import org.homedns.dade.jcgrid.client.*;
031: import org.homedns.dade.jcgrid.admin.*;
032: import org.homedns.dade.jcgrid.gui.*;
033:
034: public class guiJCGridClient extends javax.swing.JFrame {
035: private final static String className = guiJCGridClient.class
036: .getName();
037: private static Logger log = Logger.getLogger(className);
038: private static Logger logDetail = Logger.getLogger("DETAIL."
039: + className);
040:
041: private static final long serialVersionUID = 1L;
042:
043: private guiJCGridConfig pGridConfig;
044: private guiPOVRenderingPannel pPic;
045: private guiRenderingSetting pSet;
046: private guiJCGridAdminStatus pServerStatus;
047: private guiJCGridAbout pAbout;
048:
049: private GridNodeClientConfig clientConfig;
050: private GridNodeAdminConfig adminConfig;
051:
052: public guiJCGridClient() {
053: pServerStatus = null;
054: pAbout = null;
055:
056: initComponents();
057:
058: clientConfig = new GridNodeClientConfig();
059: adminConfig = new GridNodeAdminConfig();
060: adminConfig.autoSessioName();
061:
062: // Share the same config
063:
064: adminConfig.setGridConfig(clientConfig.getGridConfig());
065:
066: // Grid config pannel
067:
068: pGridConfig = new guiJCGridConfig(clientConfig.getGridConfig(),
069: this , false);
070: pGridConfig.setVisible(true);
071:
072: // Rendering pannel
073:
074: pPic = new guiPOVRenderingPannel();
075: GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
076: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
077: gridBagConstraints.weightx = 1.0;
078: gridBagConstraints.weighty = 1.0;
079: this .getContentPane().add(pPic, gridBagConstraints);
080:
081: // Rendering settings pannel
082:
083: pSet = new guiRenderingSetting(clientConfig, this , false, pPic);
084: pSet.setVisible(true);
085: }
086:
087: /** This method is called from within the constructor to
088: * initialize the form.
089: * WARNING: Do NOT modify this code. The content of this method is
090: * always regenerated by the Form Editor.
091: */
092: private void initComponents() {//GEN-BEGIN:initComponents
093: mBar = new javax.swing.JMenuBar();
094: mFile = new javax.swing.JMenu();
095: mLoadSettings = new javax.swing.JMenuItem();
096: mSaveAsSettings = new javax.swing.JMenuItem();
097: mSepa1 = new javax.swing.JSeparator();
098: mSaveImageAs = new javax.swing.JMenuItem();
099: mSepa2 = new javax.swing.JSeparator();
100: mAbout = new javax.swing.JMenuItem();
101: mSepa3 = new javax.swing.JSeparator();
102: mExit = new javax.swing.JMenuItem();
103: mAdmin = new javax.swing.JMenu();
104: mStatus = new javax.swing.JMenuItem();
105:
106: getContentPane().setLayout(new java.awt.GridBagLayout());
107:
108: setTitle("JCGrid POVRay Client");
109: setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
110: setName("fMain");
111: addWindowListener(new java.awt.event.WindowAdapter() {
112: public void windowClosing(java.awt.event.WindowEvent evt) {
113: exitForm(evt);
114: }
115: });
116:
117: mFile.setText("File");
118: mLoadSettings.setText("Load settings");
119: mLoadSettings
120: .addActionListener(new java.awt.event.ActionListener() {
121: public void actionPerformed(
122: java.awt.event.ActionEvent evt) {
123: mLoadSettingsActionPerformed(evt);
124: }
125: });
126:
127: mFile.add(mLoadSettings);
128:
129: mSaveAsSettings.setText("Save settings as...");
130: mSaveAsSettings
131: .addActionListener(new java.awt.event.ActionListener() {
132: public void actionPerformed(
133: java.awt.event.ActionEvent evt) {
134: mSaveAsSettingsActionPerformed(evt);
135: }
136: });
137:
138: mFile.add(mSaveAsSettings);
139:
140: mFile.add(mSepa1);
141:
142: mSaveImageAs.setText("Save image as...");
143: mSaveImageAs
144: .addActionListener(new java.awt.event.ActionListener() {
145: public void actionPerformed(
146: java.awt.event.ActionEvent evt) {
147: mSaveImageAsActionPerformed(evt);
148: }
149: });
150:
151: mFile.add(mSaveImageAs);
152:
153: mFile.add(mSepa2);
154:
155: mAbout.setText("About");
156: mAbout.setMnemonic('a');
157: mAbout.addActionListener(new java.awt.event.ActionListener() {
158: public void actionPerformed(java.awt.event.ActionEvent evt) {
159: mAboutActionPerformed(evt);
160: }
161: });
162:
163: mFile.add(mAbout);
164:
165: mFile.add(mSepa3);
166:
167: mExit.setText("Exit");
168: mExit.addActionListener(new java.awt.event.ActionListener() {
169: public void actionPerformed(java.awt.event.ActionEvent evt) {
170: mExitActionPerformed(evt);
171: }
172: });
173:
174: mFile.add(mExit);
175:
176: mBar.add(mFile);
177:
178: mAdmin.setText("Admin.");
179: mStatus.setText("Server status");
180: mStatus.addActionListener(new java.awt.event.ActionListener() {
181: public void actionPerformed(java.awt.event.ActionEvent evt) {
182: mStatusActionPerformed(evt);
183: }
184: });
185:
186: mAdmin.add(mStatus);
187:
188: mBar.add(mAdmin);
189:
190: setJMenuBar(mBar);
191:
192: setBounds(0, 0, 400, 300);
193: }//GEN-END:initComponents
194:
195: private void mAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mAboutActionPerformed
196: if ((pAbout == null) || (!pAbout.isVisible())) {
197: pAbout = new guiJCGridAbout(this , false);
198: pAbout.setVisible(true);
199: }
200: }//GEN-LAST:event_mAboutActionPerformed
201:
202: private void mStatusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mStatusActionPerformed
203: if ((pServerStatus != null) && (pServerStatus.isVisible()))
204: pServerStatus.refreshInfo(adminConfig);
205: else {
206: try {
207: pServerStatus = new guiJCGridAdminStatus(adminConfig,
208: this , false);
209: pServerStatus.setVisible(true);
210: } catch (Exception ex) {
211: log.warn(
212: "Error while opening the Admin. Status dialog",
213: ex);
214:
215: JOptionPane.showMessageDialog(this ,
216: "Error while opening the Admin. Status dialog",
217: "Admin error", JOptionPane.ERROR_MESSAGE);
218: }
219: }
220: }//GEN-LAST:event_mStatusActionPerformed
221:
222: private void mSaveImageAsActionPerformed(
223: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mSaveImageAsActionPerformed
224: JFileChooser chooser = new JFileChooser();
225: chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
226: chooser.setCurrentDirectory(new File(System
227: .getProperty("user.dir")));
228:
229: int res = chooser.showSaveDialog(this );
230:
231: if (res == JFileChooser.APPROVE_OPTION)
232: pPic.saveImage(chooser.getSelectedFile().getAbsolutePath());
233: }//GEN-LAST:event_mSaveImageAsActionPerformed
234:
235: private void mLoadSettingsActionPerformed(
236: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mLoadSettingsActionPerformed
237: JFileChooser chooser = new JFileChooser();
238: chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
239: chooser.setCurrentDirectory(new File(System
240: .getProperty("user.dir")));
241:
242: int res = chooser.showOpenDialog(this );
243:
244: if (res == JFileChooser.APPROVE_OPTION) {
245: GridNodeClientConfig cfg = pSet.loadSettings(chooser
246: .getSelectedFile().getAbsolutePath());
247:
248: if (cfg != null) {
249: clientConfig = cfg;
250:
251: // Share the same config
252:
253: adminConfig.setGridConfig(clientConfig.getGridConfig());
254:
255: pGridConfig.refreshConfig(clientConfig.getGridConfig());
256: }
257: }
258: }//GEN-LAST:event_mLoadSettingsActionPerformed
259:
260: private void mSaveAsSettingsActionPerformed(
261: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mSaveAsSettingsActionPerformed
262: JFileChooser chooser = new JFileChooser();
263: chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
264: chooser.setCurrentDirectory(new File(System
265: .getProperty("user.dir")));
266:
267: int res = chooser.showSaveDialog(this );
268:
269: if (res == JFileChooser.APPROVE_OPTION)
270: pSet.saveSettings(chooser.getSelectedFile()
271: .getAbsolutePath());
272: }//GEN-LAST:event_mSaveAsSettingsActionPerformed
273:
274: private void mExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mExitActionPerformed
275: this .exitForm(null);
276: }//GEN-LAST:event_mExitActionPerformed
277:
278: /** Exit the Application */
279: private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
280: System.exit(0);
281: }//GEN-LAST:event_exitForm
282:
283: /**
284: * @param args the command line arguments
285: */
286: public static void main(String args[]) {
287: try {
288: // Setup log4j
289:
290: MainCmd.setUpLog4J("gui-client", false);
291:
292: new guiJCGridClient().setVisible(true);
293: } catch (Exception ex) {
294: log.warn("Error", ex);
295: System.exit(0);
296: }
297: }
298:
299: // Variables declaration - do not modify//GEN-BEGIN:variables
300: private javax.swing.JMenuItem mAbout;
301: private javax.swing.JMenu mAdmin;
302: private javax.swing.JMenuBar mBar;
303: private javax.swing.JMenuItem mExit;
304: private javax.swing.JMenu mFile;
305: private javax.swing.JMenuItem mLoadSettings;
306: private javax.swing.JMenuItem mSaveAsSettings;
307: private javax.swing.JMenuItem mSaveImageAs;
308: private javax.swing.JSeparator mSepa1;
309: private javax.swing.JSeparator mSepa2;
310: private javax.swing.JSeparator mSepa3;
311: private javax.swing.JMenuItem mStatus;
312: // End of variables declaration//GEN-END:variables
313:
314: }
|