// GraphSheetグラフ描画コントロールパネル // JDK 1.0.2 // 1998 N.Inoue import java.awt.*; public class ControlPanel extends Panel { // 色 private final Color COLOR[] = { QuickColor.red, QuickColor.orange, QuickColor.limegreen, QuickColor.dodgerblue, QuickColor.blue, QuickColor.magenta }; private final String COLORNAME[] = { "red", "orange", "limegreen", "dodgerblue", "blue", "magenta" }; private final int COLORS = 6; // 変数、クラス private TextField inputtf; private TextField jumpnumtf; private TextField inputtfx; private TextField inputtfy; private TextField inputtff; private TextField inputtft; private GraphSheet graph; private Choice colchoice; private Choice graphchoice; private Checkbox linecheck; private Button drawbtn; private Button drawbtn_b; private Button clearbtn; private Panel northpanel; private Panel northpanel_b; private boolean indirect = false; public ControlPanel(GraphSheet gs) { super(); // 引数が操作対象になる graph = gs; this.setLayout(new BorderLayout()); // パネルのレイアウトコントローラの作成 GridBagLayout gb = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = new Insets(0, 2, 0, 2); // northパネルは式入力など northpanel = new Panel(); Label ylbl = new Label("y="); inputtf = new TextField("x", 40); drawbtn = new Button("Draw"); gbc.weightx = 0.6; gb.setConstraints(ylbl, gbc); gbc.weightx = 1.0; gb.setConstraints(drawbtn, gbc); gbc.weightx = 10.0; gb.setConstraints(inputtf, gbc); northpanel.setLayout(gb); northpanel.add(ylbl); northpanel.add(inputtf); northpanel.add(drawbtn); northpanel_b = new Panel(); Label xis = new Label("x=", Label.RIGHT); Label yis = new Label("y=", Label.RIGHT); inputtfx = new TextField("t", 13); inputtfy = new TextField("t", 13); inputtff = new TextField("0.0", 4); inputtft = new TextField("10.0", 4); drawbtn_b = new Button("Draw"); gbc.weightx = 0.5; gb.setConstraints(xis, gbc); gb.setConstraints(yis, gbc); gbc.weightx = 0.7; gb.setConstraints(inputtff, gbc); gb.setConstraints(inputtft, gbc); gbc.weightx = 1.0; gb.setConstraints(drawbtn_b, gbc); gbc.weightx = 5.0; gb.setConstraints(inputtfx, gbc); gb.setConstraints(inputtfy, gbc); northpanel_b.setLayout(gb); northpanel_b.add(xis); northpanel_b.add(inputtfx); northpanel_b.add(yis); northpanel_b.add(inputtfy); northpanel_b.add(drawbtn_b); northpanel_b.add(inputtff); northpanel_b.add(inputtft); // southパネルは表示オプションなど Panel southpanel = new Panel(); colchoice = new Choice(); for(int i = 0; i < COLORS; i++) colchoice.addItem(COLORNAME[i]); graphchoice = new Choice(); graphchoice.addItem("y=x"); graphchoice.addItem("x=t,y=t"); linecheck = new Checkbox("Line"); jumpnumtf = new TextField("0.01"); clearbtn = new Button("All clear"); Label jmplbl = new Label("Jump:", Label.RIGHT); Label collbl = new Label("Color:", Label.RIGHT); Label typlbl = new Label("Type:", Label.RIGHT); gbc.weightx = 0.8; gb.setConstraints(linecheck, gbc); gbc.weightx = 1.0; gb.setConstraints(jmplbl, gbc); gb.setConstraints(collbl, gbc); gb.setConstraints(typlbl, gbc); gb.setConstraints(clearbtn, gbc); gbc.weightx = 1.5; gb.setConstraints(jumpnumtf, gbc); gbc.weightx = 3.0; gb.setConstraints(colchoice, gbc); gb.setConstraints(graphchoice, gbc); southpanel.setLayout(gb); southpanel.add(jmplbl); southpanel.add(jumpnumtf); southpanel.add(linecheck); southpanel.add(collbl); southpanel.add(colchoice); southpanel.add(typlbl); southpanel.add(graphchoice); southpanel.add(clearbtn); // パネルを配置 this.add("North", northpanel); this.add("South", southpanel); this.setBackground(Color.white); } public boolean action(Event evt, Object obj) { if(evt.target instanceof Choice) { if(evt.target == colchoice) graph.setGraphColor(COLOR[colchoice.getSelectedIndex()]); else { if(graphchoice.getSelectedIndex() == 0) { // y=xが選択されている/された if(indirect) { this.remove(northpanel_b); this.add("North", northpanel); indirect = false; validate(); } } else if(graphchoice.getSelectedIndex() == 1) { // x=t、y=tが選択されている/された if(!indirect) { this.remove(northpanel); this.add("North", northpanel_b); indirect = true; validate(); } } } } if(evt.target instanceof Checkbox) { if(linecheck.getState()) jumpnumtf.setText("0.1"); else jumpnumtf.setText("0.01"); } else if(evt.target == drawbtn) { graph.drawGraph(inputtf.getText(), linecheck.getState(), Double.valueOf(jumpnumtf.getText()).doubleValue()); } else if(evt.target == drawbtn_b) { graph.drawGraph(inputtfx.getText(), inputtfy.getText(), linecheck.getState(), Double.valueOf(jumpnumtf.getText()).doubleValue(), Double.valueOf(inputtff.getText()).doubleValue(), Double.valueOf(inputtft.getText()).doubleValue()); } else if(evt.target == clearbtn) { graph.clearGraph(); } return true; } }