?? specialattributesproperties.java
字號:
package wapide;import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.util.*;/** * A small dialog for setting the id, class, and xml:lang attributes. * * Copyright: Copyright (c) 2003 * Company: * @author Mark Busman * @version 1.0 * * For License and contact information see WAPIDE.java */public class SpecialAttributesProperties extends JDialog { private JPanel ButtonPanel = new JPanel(); private FlowLayout flowLayout1 = new FlowLayout(); private JButton Cancel = new JButton(); private JButton Ok = new JButton(); private JPanel MainPanel = new JPanel(); private GridLayout gridLayout1 = new GridLayout(); private JLabel IdLabel = new JLabel(); private JLabel ClassLabel = new JLabel(); private JLabel XmllangLabel = new JLabel(); private JTextField IdText = new JTextField(); private JTextField ClassText = new JTextField(); private JTextField XmllangText = new JTextField(); // User data /** * The selected panel passed into the constructor from the calling dialog. */ Component theSelectedPanel; /** * The validator for checking for reserved words and symbols in text boxes. */ WMLTextValidator textValidator = new WMLTextValidator(); /** * Determines if the xml:lang attribute can be set, true means the attribute * is editable. */ boolean AllowXMLLang = true; /** * Constructs a SpecialAttributesProperties dialog. */ public SpecialAttributesProperties() { try { jbInit(); setSize(345, 145); setProperties(); show(); } catch(Exception e) { e.printStackTrace(); } } /** * Constructs a SpecialAttributesProperties dialog and initializes the * appropriate values * @param Component panel - A panel with it's name attribute set. * @param boolean allowcmllang - enable or disable xmllang editting. */ public SpecialAttributesProperties(Component panel, boolean allowxmllang) { try { theSelectedPanel = panel; AllowXMLLang = allowxmllang; jbInit(); setSize(345, 145); setProperties(); show(); } catch(Exception e) { e.printStackTrace(); } } //public static void main(String[] args) { // SpecialAttributesProperties specialAttributesProperties1 = new SpecialAttributesProperties(); //} /** * Initializes the dialog and its controls. */ private void jbInit() throws Exception { this.setResizable(false); this.setModal(true); this.setTitle("Id, class, and xml:lang properties"); ButtonPanel.setLayout(flowLayout1); flowLayout1.setAlignment(FlowLayout.RIGHT); Cancel.setNextFocusableComponent(IdText); Cancel.setText("Cancel"); Cancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { Cancel_actionPerformed(e); } }); Ok.setNextFocusableComponent(Cancel); Ok.setPreferredSize(new Dimension(81, 29)); Ok.setText("Ok"); Ok.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { Ok_actionPerformed(e); } }); MainPanel.setLayout(gridLayout1); gridLayout1.setRows(3); gridLayout1.setColumns(2); IdLabel.setRequestFocusEnabled(false); IdLabel.setText("Id"); ClassLabel.setRequestFocusEnabled(false); ClassLabel.setText("Class"); XmllangLabel.setRequestFocusEnabled(false); XmllangLabel.setText("Xml:lang"); ButtonPanel.setRequestFocusEnabled(false); MainPanel.setRequestFocusEnabled(false); IdText.setNextFocusableComponent(ClassText); ClassText.setNextFocusableComponent(XmllangText); XmllangText.setNextFocusableComponent(Ok); this.getContentPane().add(ButtonPanel, BorderLayout.SOUTH); ButtonPanel.add(Ok, null); ButtonPanel.add(Cancel, null); this.getContentPane().add(MainPanel, BorderLayout.CENTER); MainPanel.add(IdLabel, null); MainPanel.add(IdText, null); MainPanel.add(ClassLabel, null); MainPanel.add(ClassText, null); MainPanel.add(XmllangLabel, null); MainPanel.add(XmllangText, null); } /** * Handles the OK Button, if pressed prepares the data for retrieval, performs * validation checks on the data entered, and hides the dialog. */ private void Ok_actionPerformed(ActionEvent e) { boolean[] invalid = new boolean[3]; String[] controls = {"Id", "Class", "Xml:lang"}; String message = ""; String properties = ""; if (IdText.getText().length() > 0) { properties = properties + "id=\"" + IdText.getText() + "\" "; invalid[0] = textValidator.checkText(IdText.getText()); } if (ClassText.getText().length() > 0) { properties = properties + "class=\"" + ClassText.getText() + "\" "; invalid[1] = textValidator.checkText(ClassText.getText()); } if (XmllangText.getText().length() > 0) { properties = properties + "xml:lang=\"" + XmllangText.getText() + "\" "; invalid[2] = textValidator.checkText(XmllangText.getText()); } properties = properties.trim(); boolean valid = true; for (int x = 0; x < 3; x++) { if ((valid) && (invalid[x])) valid = false; if (invalid[x]) message = message + controls[x] + "\n"; } if (valid) { theSelectedPanel.setName(properties); setVisible(false); dispose(); } else { message = "The following fields have one or more restricted character(s):\n" + message; message = message + "\nThe following characters are reserved for WML:\n"; message = message + "<, >, \", ', and =\n"; message = message + "\nThey cannot be used in the values of attributes,\n"; message = message + "the = character is not accepted by all attributes."; message = message + "\n\nSee WAP Developer's Guide for more Information."; textValidator.displayWarning(null, message); } } /** * Handles the Cancel Button, if pressed discards edits and hides dialog. */ private void Cancel_actionPerformed(ActionEvent e) { setVisible(false); dispose(); } /** * Sets the properties specified in the dialog and assigns them to the * name attribute of the panel provided as a single string for further * processing outside this class. */ private void setProperties() { String properties = theSelectedPanel.getName(); if (properties == null) properties = ""; if (properties.indexOf("id=") > -1) { int pos = properties.indexOf("id=") + 4; int end = properties.indexOf("\"", pos); String text = properties.substring(pos, end); IdText.setText(text); } if (properties.indexOf("class=") > -1) { int pos = properties.indexOf("class=") + 7; int end = properties.indexOf("\"", pos); String text = properties.substring(pos, end); ClassText.setText(text); } if (AllowXMLLang) { XmllangText.setEnabled(true); if (properties.indexOf("xml:lang=") > -1) { int pos = properties.indexOf("xml:lang=") + 10; int end = properties.indexOf("\"", pos); String text = properties.substring(pos, end); XmllangText.setText(text); } } else { XmllangText.setEnabled(true); XmllangText.setText(""); XmllangText.setEnabled(false); } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -