| | package graphicalrefactor.views; |
---|
| | |
---|
| | import java.awt.Dimension; |
---|
| | import java.awt.GridBagConstraints; |
---|
| | import java.awt.GridBagLayout; |
---|
| | import java.awt.GridLayout; |
---|
| | import java.awt.Panel; |
---|
| | import java.awt.Rectangle; |
---|
| | import java.util.EventObject; |
---|
| | import java.util.List; |
---|
| | |
---|
| | import javax.swing.BorderFactory; |
---|
| | import javax.swing.JComboBox; |
---|
| | import javax.swing.JEditorPane; |
---|
| | import javax.swing.JFrame; |
---|
| | import javax.swing.JLabel; |
---|
| | import javax.swing.JOptionPane; |
---|
| | import javax.swing.JPanel; |
---|
| | import javax.swing.JTextArea; |
---|
| | import javax.swing.JTextField; |
---|
| | |
---|
| | import com.mxgraph.model.mxCell; |
---|
| | import com.mxgraph.model.mxIGraphModel; |
---|
| | import com.mxgraph.swing.mxGraphComponent; |
---|
| |
---|
| | import com.mxgraph.util.mxUtils; |
---|
| | import com.mxgraph.view.mxCellState; |
---|
| | |
---|
| | import graphicalrefactor.editor.Editor; |
---|
| | import models.algebra.Expression; |
---|
| | import models.dataFlowModel.DataFlowModel; |
---|
| | import models.dataFlowModel.DataflowChannelGenerator; |
---|
| | import models.dataFlowModel.PushPullAttribute; |
---|
| | import models.dataFlowModel.PushPullValue; |
---|
| | |
---|
| | public class GraphicalRefactorCellEditor implements mxICellEditor { |
---|
| | import models.visualModel.FormulaChannelGenerator; |
---|
| | import parser.ExpectedRightBracket; |
---|
| | import parser.Parser; |
---|
| | import parser.Parser.TokenStream; |
---|
| | |
---|
| | public class GraphicalRefactorCellEditor implements mxICellEditor { |
---|
| | public int DEFAULT_MIN_WIDTH = 70; |
---|
| | public int DEFAULT_MIN_HEIGHT = 30; |
---|
| | public double DEFAULT_MINIMUM_EDITOR_SCALE = 1; |
---|
| | |
---|
| |
---|
| | //resource |
---|
| | return; |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | if(ch instanceof FormulaChannelGenerator) { |
---|
| | |
---|
| | JPanel panel = new JPanel(); |
---|
| | JLabel label1 = new JLabel("Formula: "); |
---|
| | JLabel label2 = new JLabel("Source: "); |
---|
| | GridBagLayout layout = new GridBagLayout(); |
---|
| | panel.setLayout(layout); |
---|
| | GridBagConstraints gbc = new GridBagConstraints(); |
---|
| | |
---|
| | gbc.gridx = 0; |
---|
| | gbc.gridy = 0; |
---|
| | layout.setConstraints(label1, gbc); |
---|
| | panel.add(label1); |
---|
| | |
---|
| | gbc.gridx = 1; |
---|
| | gbc.gridy = 0; |
---|
| | JTextField formulaText = new JTextField(((FormulaChannelGenerator) ch).getFormula(),15); |
---|
| | layout.setConstraints(formulaText, gbc); |
---|
| | panel.add(formulaText); |
---|
| | |
---|
| | gbc.gridx = 0; |
---|
| | gbc.gridy = 1; |
---|
| | layout.setConstraints(label2, gbc); |
---|
| | panel.add(label2); |
---|
| | |
---|
| | gbc.gridx = 1; |
---|
| | gbc.gridy = 1; |
---|
| | JTextArea textArea = new JTextArea(ch.getSourceText(),7,15); |
---|
| | textArea.setEditable(false); |
---|
| | layout.setConstraints(textArea, gbc); |
---|
| | panel.add(textArea); |
---|
| | |
---|
| | int r = JOptionPane.showConfirmDialog( |
---|
| | null, // オーナーウィンドウ |
---|
| | panel, // メッセージ |
---|
| | "Edit Formula Channel", // ウィンドウタイトル |
---|
| | JOptionPane.OK_CANCEL_OPTION, // オプション(ボタンの種類) |
---|
| | JOptionPane.QUESTION_MESSAGE); // メッセージタイプ(アイコンの種類) |
---|
| | if(r == JOptionPane.OK_OPTION) { |
---|
| | String formula = formulaText.getText(); |
---|
| | TokenStream stream = new TokenStream(); |
---|
| | stream.addLine(formula.split(Parser.EQUALS)[1]); |
---|
| | try { |
---|
| | Expression exp = Parser.parseTerm(stream, editor.getModel()); |
---|
| | ((FormulaChannelGenerator) ch).setFormula(formula); |
---|
| | ((FormulaChannelGenerator) ch).setFormulaTerm(exp); |
---|
| | } catch (ExpectedRightBracket e) { |
---|
| | e.printStackTrace(); |
---|
| | } |
---|
| | } |
---|
| | }else { |
---|
| | JPanel panel = new JPanel(); |
---|
| | JTextArea textArea = new JTextArea(ch.getSourceText(), 10, 20); |
---|
| | panel.add(textArea); |
---|
| | // JEditorPane panel = new JEditorPane("text/plain", ch.toString()); |
---|
| | // panel.setEditable(true); |
---|
| | int ret = JOptionPane.showConfirmDialog(null, panel, "Channel Code", JOptionPane.OK_CANCEL_OPTION); |
---|
| | if (ret == JOptionPane.OK_OPTION) { |
---|
| | editor.setChannelCode(ch, textArea.getText()); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | return; |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | mxCellState state = graphComponent.getGraph().getView().getState(cell); |
---|
| | if (state != null && state.getLabel() != null && !state.getLabel().equals("")) { |
---|
| | editingCell = cell; |
---|
| |
---|
| | |