📄 formulaviewer.java
字号:
* @param contentPane Where this area should be added * @return New empty collapsable area */ private JPanel createCollapsableArea(String title, Container contentPane) { // Create panels JPanel holdingPanel = new JPanel() { public Dimension getMaximumSize() { return new Dimension(super.getMaximumSize().width, getPreferredSize().height); } }; holdingPanel.setLayout(new BoxLayout(holdingPanel, BoxLayout.Y_AXIS)); final JPanel collapsableArea = new JPanel() { public Dimension getMaximumSize() { return new Dimension(super.getMaximumSize().width, getPreferredSize().height); } }; collapsableArea.setLayout(new BoxLayout(collapsableArea, BoxLayout.Y_AXIS)); collapsableArea.setVisible(false); JPanel titlePanel = new JPanel(new BorderLayout()) { public Dimension getMaximumSize() { return new Dimension(super.getMaximumSize().width, getPreferredSize().height); } }; titlePanel.add(BorderLayout.WEST, new JLabel(title)); JCheckBox collapseCheckBox = new JCheckBox("show settings", false); collapseCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (((JCheckBox) e.getSource()).isSelected()) { collapsableArea.setVisible(true); } else { collapsableArea.setVisible(false); } } }); collapsableArea.putClientProperty("my_checkbox", collapseCheckBox); titlePanel.add(BorderLayout.EAST, collapseCheckBox); collapsableArea.setBorder( BorderFactory.createLineBorder(Color.LIGHT_GRAY) ); collapsableArea.setAlignmentY(Component.TOP_ALIGNMENT); holdingPanel.add(titlePanel); holdingPanel.add(collapsableArea); contentPane.add(holdingPanel); return collapsableArea; } /** * Creates and adds a panel with a label and a * text field which accepts doubles. * * @param id Identifier of new parameter * @param description Description of new parameter * @param contentPane Where to add created panel * @param initialValue Initial value * @return Text field in created panel */ private JFormattedTextField addDoubleParameter(String id, String description, Container contentPane, double initialValue) { JPanel panel = new JPanel(); JLabel label; JFormattedTextField textField; panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.setAlignmentY(Component.TOP_ALIGNMENT); panel.add(Box.createHorizontalStrut(10)); panel.add(label = new JLabel(description)); label.setPreferredSize(labelDimension); panel.add(Box.createHorizontalGlue()); panel.add(textField = new JFormattedTextField(doubleFormat)); textField.setValue(new Double(initialValue)); textField.setColumns(4); textField.putClientProperty("id", id); textField.addPropertyChangeListener("value", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { Object sourceObject = e.getSource(); Double newValue = ((Number) e.getNewValue()).doubleValue(); String id = (String) ((JFormattedTextField) sourceObject).getClientProperty("id"); currentChannelModel.setParameterValue(id, newValue); } }); allDoubleParameters.add(textField); contentPane.add(panel); return textField; } /** * Creates and adds a panel with a label and a * text field which accepts integers. * * @param id Identifier of new parameter * @param description Description of new parameter * @param contentPane Where to add created panel * @param initialValue Initial value * @return Text field in created panel */ private JFormattedTextField addIntegerParameter(String id, String description, Container contentPane, int initialValue) { JPanel panel = new JPanel(); JLabel label; JFormattedTextField textField; panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.setAlignmentY(Component.TOP_ALIGNMENT); panel.add(Box.createHorizontalStrut(10)); panel.add(label = new JLabel(description)); label.setPreferredSize(labelDimension); panel.add(Box.createHorizontalGlue()); panel.add(textField = new JFormattedTextField(integerFormat)); textField.setValue(new Double(initialValue)); textField.setColumns(4); textField.putClientProperty("id", id); textField.addPropertyChangeListener("value", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { Object sourceObject = e.getSource(); Integer newValue = ((Number) e.getNewValue()).intValue(); String id = (String) ((JFormattedTextField) sourceObject).getClientProperty("id"); currentChannelModel.setParameterValue(id, newValue); } }); allIntegerParameters.add(textField); contentPane.add(panel); return textField; } /** * Creates and adds a panel with a label and a * boolean checkbox. * * @param id Identifier of new parameter * @param description Description of new parameter * @param contentPane Where to add created panel * @param initialValue Initial value * @return Checkbox in created panel */ private JCheckBox addBooleanParameter(String id, String description, Container contentPane, boolean initialValue) { JPanel panel = new JPanel(); JLabel label; JCheckBox checkBox; panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.setAlignmentY(Component.TOP_ALIGNMENT); panel.add(Box.createHorizontalStrut(10)); panel.add(label = new JLabel(description)); label.setPreferredSize(labelDimension); panel.add(Box.createHorizontalGlue()); panel.add(checkBox = new JCheckBox()); checkBox.setSelected(initialValue); checkBox.putClientProperty("id", id); checkBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JCheckBox source = (JCheckBox) e.getSource(); currentChannelModel.setParameterValue( (String) source.getClientProperty("id"), new Boolean(source.isSelected()) ); } }); allBooleanParameters.add(checkBox); contentPane.add(panel); return checkBox; } /** * Creates and adds a panel with a description label. * * @param description Description of new parameter * @param contentPane Where to add created panel * @return Created label */ private JLabel addLabelParameter(String description, Container contentPane) { JPanel panel = new JPanel(); JLabel label; panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.setAlignmentY(Component.TOP_ALIGNMENT); panel.add(Box.createHorizontalStrut(10)); panel.add(label = new JLabel(description)); label.setPreferredSize(labelDimension); panel.add(Box.createHorizontalGlue()); contentPane.add(panel); return label; } /** * Listens to settings changes in the channel model. * If it changes, all GUI parameters are updated accordingly. */ private Observer channelModelSettingsObserver = new Observer() { public void update(Observable obs, Object obj) { // Update all integers for (int i=0; i < allIntegerParameters.size(); i++) { JFormattedTextField textField = allIntegerParameters.get(i); String id = (String) textField.getClientProperty("id"); textField.setValue(currentChannelModel.getParameterValue(id)); } // Update all doubles for (int i=0; i < allDoubleParameters.size(); i++) { JFormattedTextField textField = allDoubleParameters.get(i); String id = (String) textField.getClientProperty("id"); textField.setValue(currentChannelModel.getParameterValue(id)); } // Update all booleans for (int i=0; i < allBooleanParameters.size(); i++) { JCheckBox checkBox = allBooleanParameters.get(i); String id = (String) checkBox.getClientProperty("id"); checkBox.setSelected(currentChannelModel.getParameterBooleanValue(id)); } repaint(); } }; public void closePlugin() { // Remove the channel model observer if (currentChannelModel != null && channelModelSettingsObserver != null) { currentChannelModel.deleteSettingsObserver(channelModelSettingsObserver); } else { logger.fatal("Can't remove channel model observer: " + channelModelSettingsObserver); } } /** * Returns XML elements representing the current configuration. * * @see #setConfigXML(Collection) * @return XML element collection */ public Collection<Element> getConfigXML() { Vector<Element> config = new Vector<Element>(); Element element; element = new Element("show_general"); element.setText(Boolean.toString(areaGeneral.isVisible())); config.add(element); element = new Element("show_transmitter"); element.setText(Boolean.toString(areaTransmitter.isVisible())); config.add(element); element = new Element("show_receiver"); element.setText(Boolean.toString(areaReceiver.isVisible())); config.add(element); element = new Element("show_raytracer"); element.setText(Boolean.toString(areaRayTracer.isVisible())); config.add(element); element = new Element("show_shadowing"); element.setText(Boolean.toString(areaShadowing.isVisible())); config.add(element); return config; } /** * Sets the configuration depending on the given XML elements. * * @see #getConfigXML() * @param configXML * Config XML elements * @return True if config was set successfully, false otherwise */ public boolean setConfigXML(Collection<Element> configXML) { for (Element element : configXML) { if (element.getName().equals("show_general")) { JCheckBox checkBox = (JCheckBox) areaGeneral.getClientProperty("my_checkbox"); checkBox.setSelected(Boolean.parseBoolean(element.getText())); checkBox.getActionListeners()[0].actionPerformed(new ActionEvent(checkBox, ActionEvent.ACTION_PERFORMED, "")); } else if (element.getName().equals("show_transmitter")) { JCheckBox checkBox = (JCheckBox) areaTransmitter.getClientProperty("my_checkbox"); checkBox.setSelected(Boolean.parseBoolean(element.getText())); checkBox.getActionListeners()[0].actionPerformed(new ActionEvent(checkBox, ActionEvent.ACTION_PERFORMED, "")); } else if (element.getName().equals("show_receiver")) { JCheckBox checkBox = (JCheckBox) areaReceiver.getClientProperty("my_checkbox"); checkBox.setSelected(Boolean.parseBoolean(element.getText())); checkBox.getActionListeners()[0].actionPerformed(new ActionEvent(checkBox, ActionEvent.ACTION_PERFORMED, "")); } else if (element.getName().equals("show_raytracer")) { JCheckBox checkBox = (JCheckBox) areaRayTracer.getClientProperty("my_checkbox"); checkBox.setSelected(Boolean.parseBoolean(element.getText())); checkBox.getActionListeners()[0].actionPerformed(new ActionEvent(checkBox, ActionEvent.ACTION_PERFORMED, "")); } else if (element.getName().equals("show_shadowing")) { JCheckBox checkBox = (JCheckBox) areaShadowing.getClientProperty("my_checkbox"); checkBox.setSelected(Boolean.parseBoolean(element.getText())); checkBox.getActionListeners()[0].actionPerformed(new ActionEvent(checkBox, ActionEvent.ACTION_PERFORMED, "")); } } return true; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -