Java tutorial
// Description: Java 8 Swing View/Edit JInternalFrame implementation for Cluster. /* * Code Factory Asterisk 11 Configuration Model * * Copyright (c) 2014-2015 Mark Sobkow * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSwing; import java.math.*; import java.sql.*; import java.text.*; import java.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import net.sourceforge.msscodefactory.cflib.v2_3.CFLib.*; import net.sourceforge.msscodefactory.cflib.v2_3.CFLib.Swing.*; import org.apache.commons.codec.binary.Base64; import net.sourceforge.msscodefactory.cfsecurity.v2_4.CFSecurity.*; import net.sourceforge.msscodefactory.cfinternet.v2_4.CFInternet.*; import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsterisk.*; import net.sourceforge.msscodefactory.cfsecurity.v2_4.CFSecurityObj.*; import net.sourceforge.msscodefactory.cfinternet.v2_4.CFInternetObj.*; import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskObj.*; /** * CFAsteriskSwingClusterViewEditJInternalFrame Swing View/Edit JInternalFrame implementation * for Cluster. */ public class CFAsteriskSwingClusterViewEditJInternalFrame extends CFJInternalFrame implements ICFAsteriskSwingClusterJPanelCommon { protected ICFAsteriskSwingSchema swingSchema = null; protected JPanel swingViewEditJPanel = null; protected class ActionEdit extends AbstractAction { public ActionEdit() { super(); putValue(Action.NAME, "Edit Cluster"); setEnabled(true); } public void actionPerformed(ActionEvent e) { final String S_ProcName = "actionPerformed"; if (getSwingFocusAsCluster() != null) { if (null == getSwingFocusAsCluster().getEdit()) { setPanelMode(CFJPanel.PanelMode.Edit); } else { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Cannot begin an edit of an object already edited by another window instance"); } } } } protected class ActionSave extends AbstractAction { public ActionSave() { super(); putValue(Action.NAME, "Save and Close"); setEnabled(true); } public void actionPerformed(ActionEvent e) { final String S_ProcName = "actionPerformed"; ICFSecurityClusterObj focus = getSwingFocusAsCluster(); if (focus != null) { ICFAsteriskClusterEditObj editObj = (ICFAsteriskClusterEditObj) (focus.getEdit()); if (editObj != null) { setPanelMode(CFJPanel.PanelMode.Update); } else { throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName, "Cannot save on object that isn't being edited"); } } try { setClosed(true); } catch (Exception x) { } } } protected class ActionClose extends AbstractAction { public ActionClose() { super(); putValue(Action.NAME, "Close/Cancel"); setEnabled(true); } public void actionPerformed(ActionEvent e) { ICFSecurityClusterObj focus = getSwingFocusAsCluster(); if (focus != null) { ICFAsteriskClusterEditObj editObj = (ICFAsteriskClusterEditObj) focus.getEdit(); if (editObj != null) { if (editObj.getIsNew()) { editObj.endEdit(); setSwingFocus(null); setPanelMode(CFJPanel.PanelMode.Unknown); } else { editObj.endEdit(); setPanelMode(CFJPanel.PanelMode.View); } } } try { setClosed(true); } catch (Exception x) { } } } protected Action actionEdit = null; protected Action actionSave = null; protected Action actionClose = null; protected JMenuBar frameMenuBar = null; protected JMenu menuFile = null; public CFAsteriskSwingClusterViewEditJInternalFrame(ICFAsteriskSwingSchema argSchema, ICFSecurityClusterObj argFocus) { super(); final String S_ProcName = "construct-schema-focus"; if (argSchema == null) { throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1, "argSchema"); } setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // argFocus is optional; focus may be set later during execution as // conditions of the runtime change. swingSchema = argSchema; swingFocus = argFocus; if ((argFocus != null) && (!argFocus.getIsNew())) { argFocus = (ICFAsteriskClusterObj) argFocus.read(true); swingFocus = argFocus; } swingViewEditJPanel = argSchema.getClusterFactory().newViewEditJPanel(argFocus); setContentPane(swingViewEditJPanel); Dimension dim = new Dimension(1024, 480); setSize(dim); dim = new Dimension(320, 240); setMinimumSize(dim); setTitle("View/Edit Cluster"); setJMenuBar(getFrameMenuBar()); setIconifiable(true); setMaximizable(true); setResizable(true); setClosable(false); } public ICFAsteriskSwingSchema getSwingSchema() { return (swingSchema); } public void setSwingFocus(ICFLibAnyObj value) { final String S_ProcName = "setSwingFocus"; if ((value == null) || (value instanceof ICFSecurityClusterObj)) { super.setSwingFocus(value); } else { throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "value", value, "ICFSecurityClusterObj"); } ((ICFAsteriskSwingClusterJPanelCommon) swingViewEditJPanel).setSwingFocus(value); ICFAsteriskClusterObj argFocus = (ICFAsteriskClusterObj) value; if ((argFocus != null) && (!argFocus.getIsNew())) { argFocus = (ICFAsteriskClusterObj) argFocus.read(true); super.setSwingFocus(argFocus); } } public ICFSecurityClusterObj getSwingFocusAsCluster() { return ((ICFSecurityClusterObj) getSwingFocus()); } public void setSwingFocusAsCluster(ICFSecurityClusterObj value) { setSwingFocus(value); } public JMenuBar getFrameMenuBar() { if (frameMenuBar == null) { JMenuItem menuItem; frameMenuBar = new JMenuBar(); menuFile = new JMenu("File"); actionEdit = new ActionEdit(); menuItem = new JMenuItem(actionEdit); menuFile.add(menuItem); actionSave = new ActionSave(); menuItem = new JMenuItem(actionSave); menuFile.add(menuItem); actionClose = new ActionClose(); menuItem = new JMenuItem(actionClose); menuFile.add(menuItem); frameMenuBar.add(menuFile); } return (frameMenuBar); } public void setPanelMode(CFJPanel.PanelMode value) { CFJPanel.PanelMode oldMode = getPanelMode(); if (oldMode == value) { return; } super.setPanelMode(value); ((ICFAsteriskSwingClusterJPanelCommon) swingViewEditJPanel).setPanelMode(value); if (value == CFJPanel.PanelMode.View) { if (actionEdit != null) { actionEdit.setEnabled(true); } if (actionSave != null) { actionSave.setEnabled(false); } if (actionClose != null) { actionClose.setEnabled(true); } } else if (value == CFJPanel.PanelMode.Edit) { if (actionEdit != null) { actionEdit.setEnabled(false); } if (actionSave != null) { actionSave.setEnabled(true); } if (actionClose != null) { actionClose.setEnabled(true); } } else if (value == CFJPanel.PanelMode.Add) { if (actionEdit != null) { actionEdit.setEnabled(false); } if (actionSave != null) { actionSave.setEnabled(true); } if (actionClose != null) { actionClose.setEnabled(true); } } else { if (actionEdit != null) { actionEdit.setEnabled(false); } if (actionSave != null) { actionSave.setEnabled(false); } if (actionClose != null) { actionClose.setEnabled(true); } } } }