📄 promptat.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: PromptAt.java * Display a prompt dialog over a specific piece of circuitry. * Written by Steven M. Rubin, Sun Microsystems. * * Copyright (c) 2005 Sun Microsystems and Static Free Software * * Electric(tm) is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * Electric(tm) is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Electric(tm); see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, Mass 02111-1307, USA. */package com.sun.electric.tool.user.dialogs;import com.sun.electric.database.text.TextUtils;import com.sun.electric.database.topology.NodeInst;import com.sun.electric.database.variable.EditWindow_;import java.awt.Color;import java.awt.Dimension;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import javax.swing.JButton;import javax.swing.JColorChooser;import javax.swing.JComboBox;import javax.swing.JComponent;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.event.DocumentEvent;import javax.swing.event.DocumentListener;/** * This class places an inquiry dialog at specific places on the display. */public class PromptAt extends EDialog{ private boolean yesNo; private String value; private boolean goodClicked; private String customButtonClicked; private boolean closed; private Field [] fieldList; private Field [][] fieldArray; /** * Class to define a single entry in the custom prompt dialog. */ public static class Field { private String label; private Object initial; private Object finalValue; private int type; private JTextField textField; private JComboBox combo; private JButton but; private JPanel patch; private JLabel labelObj; private static final int FIELD_MESSAGE = 1; private static final int FIELD_BOOL = 2; private static final int FIELD_STRING = 3; private static final int FIELD_SELECT = 4; private static final int FIELD_COLOR = 5; private static final int FIELD_BUTTON = 6; /** * Constructor for a field in a prompt dialog that displays a message. * @param label the question to ask. */ public Field(String label) { this.label = label; this.initial = null; this.finalValue = null; this.type = FIELD_MESSAGE; } /** * Constructor for a field in a prompt dialog that chooses between Yes and No. * @param label the question to ask. * @param initial the default response. */ public Field(String label, boolean initial) { this.label = label; this.initial = Boolean.valueOf(initial); this.finalValue = this.initial; this.type = FIELD_BOOL; } /** * Constructor for a field in a prompt dialog that edits a string. * @param label the label of the string. * @param initial the initial string value. */ public Field(String label, String initial) { this.label = label; this.initial = initial; this.finalValue = this.initial; this.type = FIELD_STRING; } /** * Constructor for a field in a prompt dialog that selects among different choices. * @param label the label of the choice. * @param choices the array of choices. * @param initial the default choice. */ public Field(String label, String [] choices, String initial) { this.label = label; this.initial = choices; this.finalValue = initial; this.type = FIELD_SELECT; } /** * Constructor for a field in a prompt dialog that edits a color value. * @param label the label of the color. * @param initial the initial Color value. */ public Field(String label, Color initial) { this.label = label; this.initial = initial; this.finalValue = initial; this.type = FIELD_COLOR; } /** * Constructor for a field in a prompt dialog that places a button. * @param id the returned value of the dialog if the button is pressed. * @param but the button. */ public Field(String id, JButton but) { this.label = null; this.initial = but; this.finalValue = id; this.type = FIELD_BUTTON; } /** * Method to return the final value for a field, after the dialog has completed. * @return the final value (dependent on the type of field). */ public Object getFinal() { return finalValue; } } /** * Method to invoke a "yes/no" dialog centered at a point in the circuit. * @param wnd the window displaying the circuit. * @param ni the NodeInst about which to display the dialog. * @param title the dialog title. * @param label the message inside of the dialog, before the text area. * @param initial the default button (true for yes, false for no). * @return the returned value. */ public static boolean showPromptAt(EditWindow_ wnd, NodeInst ni, String title, String label, boolean initial) { Field [] fields = new Field[1]; fields[0] = new PromptAt.Field(label); PromptAt dialog = new PromptAt(true); dialog.initComponents(wnd, ni, title, fields, null); dialog.setVisible(true); if (dialog.closed) return initial; return dialog.goodClicked; } /** * Method to invoke a popup dialog centered at a point in the circuit. * @param wnd the window displaying the circuit. * @param ni the NodeInst about which to display the dialog. * @param title the dialog title. * @param label the message inside of the dialog, before the choices. * @param initial the default choice. * @param choices an array of strings to present as choices. * @return the returned choice (null if cancelled). */ public static String showPromptAt(EditWindow_ wnd, NodeInst ni, String title, String label, String initial, String [] choices) { Field [] fields = new Field[1]; fields[0] = new PromptAt.Field(label, choices, initial); PromptAt dialog = new PromptAt(false); dialog.initComponents(wnd, ni, title, fields, null); dialog.setVisible(true); if (!dialog.goodClicked) return null; return (String)fields[0].finalValue; } /** * Method to invoke an input dialog centered at a point in the circuit. * @param wnd the window displaying the circuit. * @param ni the NodeInst about which to display the dialog. * @param title the dialog title. * @param label the message inside of the dialog, before the text area. * @param initial the initial value of the text area. * @return the returned value (null if cancelled). */ public static String showPromptAt(EditWindow_ wnd, NodeInst ni, String title, String label, String initial) { Field [] fields = new Field[1]; fields[0] = new PromptAt.Field(label, initial); PromptAt dialog = new PromptAt(false); dialog.initComponents(wnd, ni, title, fields, null); dialog.setVisible(true); if (!dialog.goodClicked) return null; return (String)fields[0].finalValue; } /** * Method to invoke a custom dialog centered at a point in the circuit. * @param wnd the window displaying the circuit. * @param ni the NodeInst about which to display the dialog. * @param title the dialog title. * @param fields an array of Field objects that describe each field in the dialog. * @return null if cancelled, non-null if OK (the results are stored in the Field objects). */ public static String showPromptAt(EditWindow_ wnd, NodeInst ni, String title, Field [] fields) { PromptAt dialog = new PromptAt(false); dialog.initComponents(wnd, ni, title, fields, null); dialog.setVisible(true); if (!dialog.goodClicked) return null; return dialog.value; } /** * Method to invoke a custom dialog centered at a point in the circuit. * @param wnd the window displaying the circuit. * @param ni the NodeInst about which to display the dialog. * @param title the dialog title. * @param fields an array of Field objects that describe each field in the dialog. * @return null if cancelled, non-null if OK (the results are stored in the Field objects). */ public static String showPromptAt(EditWindow_ wnd, NodeInst ni, String title, Field [][] fields) { PromptAt dialog = new PromptAt(false); dialog.initComponents(wnd, ni, title, null, fields); dialog.setVisible(true); if (!dialog.goodClicked) return null; return dialog.value; } /** Creates new form PromptAt */ public PromptAt(boolean yesNo) { super(null, true); this.yesNo = yesNo; this.closed = false; } protected void escapePressed() { closed = true; exit(false); } /** * Call this method when the user closes the dialog. * @param goodButton true if it is an "OK" completion, false if a "Cancel" completion. */ private void exit(boolean goodButton) { goodClicked = goodButton; if (goodClicked) { if (!yesNo) { if (fieldList != null) { for(int i=0; i<fieldList.length; i++) { finishField(fieldList[i]); } } else if (fieldArray != null) { for(int i=0; i<fieldArray.length; i++) { Field [] row = fieldArray[i]; for(int j=0; j<row.length; j++) finishField(row[j]); } } value = "";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -