📄 jremextensionview.java
字号:
package fildiv.jremcntl.server.gui.app;import java.awt.Color;import java.awt.Component;import java.awt.Dimension;import java.awt.Font;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import java.awt.event.ComponentEvent;import java.awt.event.ComponentListener;import java.util.ArrayList;import java.util.Collection;import java.util.List;import javax.swing.BorderFactory;import javax.swing.JCheckBox;import javax.swing.JComboBox;import javax.swing.JLabel;import javax.swing.JLayeredPane;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.SwingConstants;import fildiv.jremcntl.common.core.Logger;import fildiv.jremcntl.common.core.SupportExtension;import fildiv.jremcntl.server.core.AppExtension;import fildiv.jremcntl.server.core.Controller;import fildiv.jremcntl.server.core.ExtensionLoader;import fildiv.jremcntl.server.core.JRemEnv;import fildiv.jremcntl.server.core.JRemExtension;import fildiv.jremcntl.server.core.JRemPropertyDomainValue;import fildiv.jremcntl.server.gui.core.DocumentAttachedEvent;import fildiv.jremcntl.server.gui.core.DocumentDetachedEvent;import fildiv.jremcntl.server.gui.core.DocumentEvent;import fildiv.jremcntl.server.gui.core.DocumentListener;import fildiv.jremcntl.server.gui.core.DocumentModifiedEvent;import fildiv.jremcntl.server.gui.core.Frame;import fildiv.jremcntl.server.gui.model.JRemExtensionDoc;import fildiv.jremcntl.server.gui.util.swing.GlassPane;import fildiv.jremcntl.server.gui.util.swing.SwingUtils;import fildiv.jremcntl.server.utils.JRemServerUtils;public class JRemExtensionView extends JPanel { private static final long serialVersionUID = 1L; private JComboBox jComboBoxSchema = null; private JScrollPane jScrollPaneExtProperties = null; private JRemExtensionDoc extDoc; // @jve:decl-index=0: private JRemExtension ext; private JRemEnv env; private Logger logger; DocumentListener listener = new DocumentListener() { public void actionPerformed(DocumentEvent event) { updateView(event); // @jve:decl-index=0: } }; private boolean updating = false; private Frame frame; private JPanel jPanelExtProp = null; private JCheckBox jCheckBoxInherited = null; private SupportExtension se; private JLabel jLabel1 = null; private JLabel jLabel31 = null; private JLayeredPane jLayeredPaneExtProperties = null; private JPanel jPanelGlass = null; private JLabel jLabelFiller = null; /** * This is the default constructor * @param serverGUI */ public JRemExtensionView(Frame frame) { super(); this.env = JRemEnv.getInstance(); this.logger = env.getLogger(); this.frame = frame; initialize(); } protected void updateView(DocumentEvent event) { try { updating = true; SwingUtils.showWaitCursor(this, false); if (event instanceof DocumentModifiedEvent) { updateThisView(); updateCustomView(event); } else { if (event instanceof DocumentAttachedEvent) { init(); updateThisView(); updateCustomView(event); } else { updateThisView(); updateCustomView(event); clearAll(); disableAll(); } } } finally { updating = false; SwingUtils.showWaitCursor(this, false); } } private void updateCustomView(DocumentEvent event) { if (ext == null) return; Controller c = ext.getController(); if (c == null) return; Controller controller = ext.getController(); controller.updateState(frame, ext.getDocument(), remapEvent(event)); boolean isInHerited = se.isInHerited(); enableExtView(!isInHerited); } private DocumentEvent remapEvent(DocumentEvent event) { if (event instanceof DocumentModifiedEvent) { DocumentModifiedEvent e = (DocumentModifiedEvent) event; event = new DocumentModifiedEvent(this, e.getWhatModified()); } else if (event instanceof DocumentAttachedEvent) { event = new DocumentAttachedEvent(this); } else if (event instanceof DocumentDetachedEvent) { event = new DocumentDetachedEvent(this); } else { assert false; } return event; } private void disableAll() { getJCheckBoxInherited().setEnabled(false); getJComboBoxSchema().setEnabled(false); enableExtView(true); } private void enableExtView(boolean enable) { if (ext == null) return; Controller c = ext.getController(); if (c == null) return; JPanel p = c.getPanel(); p.enableInputMethods(enable); } private void init() { List appExtsList = env.getAppExtensions().asList(); Collection domainValues = new ArrayList(); for (int index = 0; index < appExtsList.size(); ++index) { AppExtension ext = (AppExtension) appExtsList.get(index); domainValues.add( new JRemPropertyDomainValue(ext.getID(), ext.getShortName())); } getJComboBoxSchema().removeAllItems(); JRemServerUtils.addComboItemsFromDomainValues(getJComboBoxSchema(), domainValues); setupExtView(ext); } private void setupExtView(JRemExtension ext) { Component c = null; boolean showPropPane = false; if (ext != null) { Controller controller = ext.getController(); if (controller != null) { c = controller.getPanel(); showPropPane = true; } } getJScrollPaneExtProperties().setViewportView(c); getJPanelExtProp().setVisible(showPropPane); getJLabelFiller().setVisible(!showPropPane); } private void updateThisView() { if (ext == null) { disableAll(); clearAll(); return; } JRemServerUtils.setSelectDomainComboFromValue( getJComboBoxSchema(), extDoc.getID()); boolean isInherited = se.isInHerited(); getJCheckBoxInherited().setSelected(isInherited); getJComboBoxSchema().setEnabled(!isInherited); getJCheckBoxInherited().setEnabled( se.getParent() != null); } private void clearAll() { setupExtView(null); } public void setDocument(SupportExtension se) { this.se = se; if (this.extDoc != null) { commitPendings(); this.extDoc.removeActionListener(listener); } this.extDoc = (JRemExtensionDoc) se.getExtension(true); if (this.extDoc != null) { this.ext = (JRemExtension) extDoc.getImplObj(); this.extDoc.addActionListener(listener); } else { this.ext = null; } } private void commitPendings() { } /** * This method initializes this * * @return void */ private void initialize() { GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); gridBagConstraints2.gridx = 0; gridBagConstraints2.weighty = 1.0; gridBagConstraints2.weightx = 1.0; gridBagConstraints2.fill = GridBagConstraints.BOTH; gridBagConstraints2.gridwidth = 7; gridBagConstraints2.gridy = 6; GridBagConstraints gridBagConstraints8 = new GridBagConstraints(); gridBagConstraints8.gridx = 0; gridBagConstraints8.insets = new Insets(2, 2, 2, 2); gridBagConstraints8.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints8.weightx = 1.0; gridBagConstraints8.gridwidth = 6; gridBagConstraints8.gridy = 0; jLabel31 = new JLabel(); jLabel31.setText("Output management"); GridBagConstraints gridBagConstraints61 = new GridBagConstraints(); gridBagConstraints61.gridx = 0; gridBagConstraints61.anchor = GridBagConstraints.WEST; gridBagConstraints61.insets = new Insets(2, 2, 2, 2); gridBagConstraints61.gridy = 2; jLabel1 = new JLabel(); jLabel1.setText("Manager"); jLabel1.setMinimumSize(new Dimension(60, 15)); jLabel1.setHorizontalAlignment(SwingConstants.LEFT); jLabel1.setHorizontalTextPosition(SwingConstants.LEFT); jLabel1.setFont(new Font("Dialog", Font.PLAIN, 12)); jLabel1.setMaximumSize(new Dimension(60, 15)); GridBagConstraints gridBagConstraints51 = new GridBagConstraints(); gridBagConstraints51.gridx = 1; gridBagConstraints51.gridwidth = 2; gridBagConstraints51.insets = new Insets(2, 2, 2, 2); gridBagConstraints51.fill = GridBagConstraints.HORIZONTAL; gridBagConstraints51.gridy = 1; GridBagConstraints gridBagConstraints31 = new GridBagConstraints(); gridBagConstraints31.gridx = 6; gridBagConstraints31.gridy = 0; GridBagConstraints gridBagConstraints11 = new GridBagConstraints(); gridBagConstraints11.fill = GridBagConstraints.BOTH; gridBagConstraints11.gridheight = 1; gridBagConstraints11.gridx = 0; gridBagConstraints11.gridy = 5; gridBagConstraints11.gridwidth = 8; gridBagConstraints11.weighty = 0.8; gridBagConstraints11.insets = new Insets(2, 2, 2, 2); GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); gridBagConstraints1.fill = GridBagConstraints.BOTH; gridBagConstraints1.gridy = 2; gridBagConstraints1.weightx = 1.0; gridBagConstraints1.insets = new Insets(2, 2, 2, 2); gridBagConstraints1.gridwidth = 5; gridBagConstraints1.gridx = 2; this.setSize(467, 200); this.setLayout(new GridBagLayout()); this.add(getJComboBoxSchema(), gridBagConstraints1); this.add(getJPanelExtProp(), gridBagConstraints11); this.add(getJCheckBoxInherited(), gridBagConstraints31); this.add(jLabel1, gridBagConstraints61); this.add(jLabel31, gridBagConstraints8); this.add(getJLabelFiller(), gridBagConstraints2); } /** * This method initializes jComboBoxSchema * * @return javax.swing.JComboBox */ private JComboBox getJComboBoxSchema() { if (jComboBoxSchema == null) { jComboBoxSchema = new JComboBox(); jComboBoxSchema.setFont(new Font("Dialog", Font.PLAIN, 12)); jComboBoxSchema.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { if (updating) return; onShemaChanged(); } }); } return jComboBoxSchema; } /** * This method initializes jScrollPaneExtProperties * * @return javax.swing.JScrollPane */ private JScrollPane getJScrollPaneExtProperties() { if (jScrollPaneExtProperties == null) { jScrollPaneExtProperties = new JScrollPane(); jScrollPaneExtProperties.setBorder(BorderFactory.createLineBorder(Color.gray, 1)); } return jScrollPaneExtProperties; } /** * This method initializes jPanelExtProp * * @return javax.swing.JPanel */ private JPanel getJPanelExtProp() { if (jPanelExtProp == null) { GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.anchor = GridBagConstraints.CENTER; gridBagConstraints.gridy = 2; jPanelExtProp = new JPanel(); jPanelExtProp.setLayout(new GridBagLayout()); jPanelExtProp.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); jPanelExtProp.add(getJLayeredPaneExtProperties(), gridBagConstraints); } return jPanelExtProp; } /** * This method initializes jCheckBoxInherited * * @return javax.swing.JCheckBox */ private JCheckBox getJCheckBoxInherited() { if (jCheckBoxInherited == null) { jCheckBoxInherited = new JCheckBox(); jCheckBoxInherited.setText("Inherited from parent"); jCheckBoxInherited.setFont(new Font("Dialog", Font.PLAIN, 12)); jCheckBoxInherited.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { if (updating) return; onInheritedChecked(); } }); } return jCheckBoxInherited; } protected void onShemaChanged() { JRemExtensionDoc newExtDoc = createExtDocFromSelection(); JRemExtension newExt = (JRemExtension) newExtDoc.getImplObj(); JRemExtension actExt = (JRemExtension) extDoc.getImplObj(); if (newExt.getID().equals(actExt.getID())) return; boolean apply = true; if (actExt.getDocument() != null) { int res = SwingUtils.askYN(this, env, "Are you sure you want to change the output manager ?"); apply = res == JOptionPane.YES_OPTION; } if (apply) { setExtensionDoc(newExtDoc); } else { updateThisView(); } } protected JRemExtensionDoc createExtDocFromSelection() { JRemPropertyDomainValue v = (JRemPropertyDomainValue) getJComboBoxSchema().getSelectedItem(); String extID = (String) v.getKey(); AppExtension appExt = env.getAppExtensions().getExtension(extID); ExtensionLoader loader = env.getExtensionLoader(); JRemExtension ext = loader.getExtension(appExt.getClassName()); JRemExtensionDoc extDoc = new JRemExtensionDoc(se, ext); return extDoc; } protected void onInheritedChecked() { try { JRemExtensionDoc newExtDoc = null; boolean setExtDoc = true; if (se.isInHerited()) { newExtDoc = createExtDocFromSelection(); } else { int res = SwingUtils.askYN(this, env, "Are you sure you want to change inherith state ?"); if (res == JOptionPane.YES_OPTION) newExtDoc = null; else setExtDoc = false; } if (setExtDoc) { setExtensionDoc(newExtDoc); } else { updateThisView(); } } catch(Exception e) { logger.error(e); SwingUtils.showErrorMessage(env, this, "Unable to perform the operation"); } } private void setExtensionDoc(JRemExtensionDoc newExtDoc) { se.setExtension(newExtDoc); setDocument(se); } /** * This method initializes jLayeredPaneExtProperties * * @return javax.swing.JLayeredPane */ private JLayeredPane getJLayeredPaneExtProperties() { if (jLayeredPaneExtProperties == null) { jLayeredPaneExtProperties = new JLayeredPane(); jLayeredPaneExtProperties.setFont(new Font("Dialog", Font.PLAIN, 12)); jLayeredPaneExtProperties.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); jLayeredPaneExtProperties.add(getJScrollPaneExtProperties(), 0);// jLayeredPaneExtProperties.add(getJPanelGlass(), 1); jLayeredPaneExtProperties.addComponentListener(new ComponentListener() { public void componentHidden(ComponentEvent e) { } public void componentMoved(ComponentEvent e) { } public void componentResized(ComponentEvent e) { getJScrollPaneExtProperties().setBounds(e.getComponent().getBounds());// getJPanelGlass().setBounds(e.getComponent().getBounds()); } public void componentShown(ComponentEvent e) { } }); } return jLayeredPaneExtProperties; } /** * This method initializes jPanelGlass * * @return javax.swing.JPanel */ private JPanel getJPanelGlass() { if (jPanelGlass == null) { jPanelGlass = new GlassPane(); } return jPanelGlass; } /** * This method initializes jLabelFiller * * @return javax.swing.JLabel */ private JLabel getJLabelFiller() { if (jLabelFiller == null) { jLabelFiller = new JLabel(); jLabelFiller.setText(""); } return jLabelFiller; }} // @jve:decl-index=0:visual-constraint="10,10"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -