📄 inlinepanel.java
字号:
package org.enhydra.jawe.base.panel;import java.awt.BorderLayout;import java.awt.Component;import java.util.ArrayList;import java.util.EventObject;import java.util.HashMap;import java.util.List;import java.util.Map;import javax.swing.BorderFactory;import javax.swing.Box;import javax.swing.BoxLayout;import javax.swing.JComponent;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JToolBar;import javax.swing.JViewport;import javax.swing.ScrollPaneConstants;import org.enhydra.jawe.BarFactory;import org.enhydra.jawe.HistoryManager;import org.enhydra.jawe.JaWEComponent;import org.enhydra.jawe.JaWEComponentView;import org.enhydra.jawe.JaWEManager;import org.enhydra.jawe.Settings;import org.enhydra.jawe.XPDLElementChangeInfo;import org.enhydra.jawe.base.controller.JaWESelectionManager;import org.enhydra.jawe.base.display.DisplayNameGenerator;import org.enhydra.jawe.base.label.LabelGenerator;import org.enhydra.jawe.base.panel.panels.XMLBasicPanel;import org.enhydra.jawe.base.panel.panels.XMLPanel;import org.enhydra.jawe.base.panel.panels.XMLTabbedPanel;import org.enhydra.jawe.base.tooltip.TooltipGenerator;import org.enhydra.shark.xpdl.XMLComplexChoice;import org.enhydra.shark.xpdl.XMLElement;import org.enhydra.shark.xpdl.XMLElementChangeInfo;import org.enhydra.shark.xpdl.XMLUtil;public class InlinePanel extends JPanel implements JaWEComponentView, PanelContainer { protected JaWEComponent controller; protected JScrollPane scrollPane; protected boolean displayTitle = false; protected JLabel title; protected boolean isModified = false; protected PanelGenerator panelGenerator; protected Map lastActiveTabs = new HashMap(); protected HistoryManager hm; public void configure() { } public InlinePanel() { } public void setJaWEComponent(JaWEComponent jc) { this.controller = jc; } public PanelSettings getPanelSettings() { return (PanelSettings) this.controller.getSettings(); } public void init() { ClassLoader cl = getClass().getClassLoader(); try { this.panelGenerator = (PanelGenerator) cl.loadClass(JaWEManager.getInstance().getPanelGeneratorClassName()) .newInstance(); } catch (Exception ex) { String msg = "InlinePanel -> Problems while instantiating Panel Generator class '" + JaWEManager.getInstance().getPanelGeneratorClassName() + "' - using default implementation!"; JaWEManager.getInstance().getLoggingManager().error(msg, ex); this.panelGenerator=new StandardPanelGenerator(); } this.panelGenerator.setPanelContainer(this); try { String hmc = getPanelSettings().historyManagerClass(); if (hmc != null && !hmc.equals("")) { hm = (HistoryManager) Class.forName(hmc).newInstance(); hm.init(getPanelSettings().historySize()); } } catch (Exception ex) { System.err.println("Failed to instantiate history manager - my controller is "+controller); } getPanelSettings().adjustActions(); displayTitle = ((Boolean) controller.getSettings().getSetting("DisplayTitle")).booleanValue(); // creates scroll panel scrollPane = new JScrollPane(); if (((Boolean) controller.getSettings().getSetting("UseScrollBar")).booleanValue()) { scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); } else { scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); } JViewport port = scrollPane.getViewport(); port.setScrollMode(JViewport.BLIT_SCROLL_MODE); scrollPane.getVerticalScrollBar().setUnitIncrement(20); scrollPane.getHorizontalScrollBar().setUnitIncrement(40); setBorder(BorderFactory.createEtchedBorder()); setLayout(new BorderLayout()); JPanel wp = new JPanel(); JToolBar toolbar = BarFactory.createToolbar("defaultToolbar", controller); toolbar.setFloatable(false); toolbar.setRollover(true); wp.setLayout(new BoxLayout(wp, BoxLayout.Y_AXIS)); wp.add(Box.createVerticalStrut(5)); if (displayTitle) { JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); title = new JLabel(""); title.setAlignmentX(Component.LEFT_ALIGNMENT); title.setAlignmentY(Component.BOTTOM_ALIGNMENT); // p.add(Box.createHorizontalGlue()); p.add(title); p.add(Box.createHorizontalGlue()); wp.add(p); } wp.add(scrollPane); add(toolbar, BorderLayout.NORTH); add(wp, BorderLayout.CENTER); } public JaWEComponent getJaWEComponent() { return controller; } public JComponent getDisplay() { return this; } public void update(XPDLElementChangeInfo info) { if (info.getSource() == this) { return; } XMLElement changedElement = info.getChangedElement(); XMLElement current = getActiveElement(); List removedElements = new ArrayList(); JaWESelectionManager jsm = JaWEManager.getInstance().getJaWEController().getSelectionManager(); if (changedElement == null || (jsm.getSelectedElements().size() == 1 && !jsm.canEditProperties())) { setActiveElement(null); } else if (info.getAction() == XMLElementChangeInfo.UPDATED) { if (current != null && XMLUtil.isChildsParent(current, info.getChangedElement())) { setActiveElement(current); } } else if (info.getAction() == XPDLElementChangeInfo.SELECTED) { setActiveElement(changedElement); // TODO: send multi sel to XMLTable and XMLList panels // if (changedElement instanceof XMLCollection) { // List chngdSubEls=info.getChangedSubElements(); // if (chngdSubEls.size()>0) { // } // } } else if (info.getAction() == XMLElementChangeInfo.REMOVED) { List l = info.getChangedSubElements(); if (l == null || l.size() == 0) { l = new ArrayList(); l.add(info.getChangedElement()); } for (int i = 0; i < l.size(); i++) { XMLElement el = (XMLElement) l.get(i); if (el==current || XMLUtil.isParentsChild(el, current)) { setActiveElement(null); } removedElements.add(el); } } if (hm != null) { for (int i = 0; i < removedElements.size(); i++) { hm.removeFromHistory((XMLElement) removedElements.get(i)); } } getPanelSettings().adjustActions(); } public void setViewPanel(XMLPanel panel) { XMLPanel current = getViewPanel(); if (current != null) { current.cleanup(); } if (displayTitle) { XMLElement el = panel.getOwner(); String t = ""; if (el != null) {// t = " " + getLabelGenerator().getLabel(el); t = " " + panel.getTitle(); } title.setText(t); } this.scrollPane.setViewportView(panel); } public XMLPanel getViewPanel() { if (scrollPane != null) return (XMLPanel) this.scrollPane.getViewport().getView(); return null; } public XMLElement getActiveElement() { XMLPanel p = getViewPanel(); if (p != null) { XMLElement current = p.getOwner(); if (current instanceof SpecialChoiceElement) { current = ((SpecialChoiceElement) current).getControlledElement(); } else if (current instanceof ActivityTypesChoiceElement) { current = ((ActivityTypesChoiceElement) current).getControlledElement(); } return current; } return null; } public void apply() { XMLPanel p = getViewPanel(); if (p != null) { p.setElements(); } } public boolean canApplyChanges() { if (getViewPanel() != null) { XMLPanel p = getViewPanel();// System.err.println("CAAAAAAAACCCCCCCC for "+p); if (p.validateEntry()) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -