?? anchortagdesigner.java
字號:
package wapide;import javax.swing.*;import java.awt.*;import javax.swing.border.*;import java.awt.event.*;import java.text.*;import java.util.*;import java.lang.*;import javax.swing.text.*;/** * This class creates a dialog for graphically adding <go>, <prev>, and <refresh> * tags to an anchor tag. It provides methods for setting up the dialog as well * as retrieving data from the dialog. Data os returned as a SimpleAttribteSet to be * applied to the text that represents the anchor tag element. * * Copyright: Copyright (c) 2003 * @author Mark Busman * @version 1.0 * * For License and contact information see WAPIDE.java */public class AnchorTagDesigner extends JDialog { private BorderLayout borderLayout1 = new BorderLayout(); private ImageIcon imgrefresh; private ImageIcon imgprev; private ImageIcon imggo; private ImageIcon imgvar; private ImageIcon imgpost; private ImageIcon imgdown; private ImageIcon imgup; private ImageIcon imgpic; private TitledBorder titledBorder1; private Border border1; private TitledBorder titledBorder2; private Border border2; private TitledBorder titledBorder3; private JPanel ContentPanel = new JPanel(); private BorderLayout borderLayout4 = new BorderLayout(); private JToggleButton RefreshToggleButton = new JToggleButton(); private JToggleButton PrevToggleButton = new JToggleButton(); private JPanel ActionPanel = new JPanel(); private JToggleButton GoToggleButton = new JToggleButton(); private JScrollPane ListScrollPane = new JScrollPane(); private BorderLayout borderLayout2 = new BorderLayout(); private JPanel Additionals = new JPanel(); private JPanel AcceptPanel = new JPanel(); private FlowLayout flowLayout2 = new FlowLayout(); private JButton CancelButton = new JButton(); private JButton OkButton = new JButton(); private ButtonGroup actionGroup = new ButtonGroup(); private JToggleButton NoneToggleButton = new JToggleButton(); private FlowLayout flowLayout1 = new FlowLayout(); private JPanel AdditionalControlsPanel = new JPanel(); private BorderLayout borderLayout5 = new BorderLayout(); private JPanel AdditionalButtonPanel = new JPanel(); private JPanel LayoutPanel = new JPanel(); private GridLayout gridLayout1 = new GridLayout(); private JButton PostfieldButton = new JButton(); private JButton SetVarButton = new JButton(); private JList AdditionalActionList = new JList(); private JButton PropertiesButton = new JButton(); private JScrollPane PropertiesScrollPane = new JScrollPane(); private JButton DeleteButton = new JButton(); private JLabel jLabel1 = new JLabel(); private Border border3; private JTextField PropertiesText = new JTextField(); // User defined Variables and constants /** * Maintains the list items displayed by the list. */ private Vector listData = new Vector(); /** * The String of the previous ToggleButton. Used to determine if the * same buton is pressed twice, and thus avoid loss of data due to * button specific initializations. */ private String prevAction = ""; /** * The boolean value used to determine if the OK Button was used to * close the dialog, defualt is <i>false<i>. */ private boolean OkPressed = false; // Constants private static int LEFT_MOUSE_BUTTON = 16; private static int RIGHT_MOUSE_BUTTON = 4; /** * Displays the dialog without setting any values. */ public AnchorTagDesigner() { try { jbInit(); pack(); show(); } catch(Exception e) { e.printStackTrace(); } } /** * Displays the dialog after setting the values specified by set. * @param SimpleAttributeSet set - The set of attributes taken from the anchor * element. These attributes must be stored as sub-attributes of the anchor tag * element. */ public AnchorTagDesigner(SimpleAttributeSet set) { try { jbInit(); pack(); setData(set); show(); } catch(Exception e) { e.printStackTrace(); } } //public static void main(String[] args) { // AnchorTagDesigner anchorTagDesigner1 = new AnchorTagDesigner(); //} /** * Initializes dialog components. */ private void jbInit() throws Exception { imgrefresh = new ImageIcon(wapide.IDEFrame.class.getResource("refreshTag.gif")); imgprev = new ImageIcon(wapide.IDEFrame.class.getResource("prevTag.gif")); imggo = new ImageIcon(wapide.IDEFrame.class.getResource("goTag.gif")); imgvar = new ImageIcon(wapide.IDEFrame.class.getResource("setvarTag.gif")); imgpost = new ImageIcon(wapide.IDEFrame.class.getResource("postfieldTag.gif")); imgdown = new ImageIcon(wapide.IDEFrame.class.getResource("darrow.gif")); imgup = new ImageIcon(wapide.IDEFrame.class.getResource("uarrow.gif")); imgpic = new ImageIcon(wapide.IDEFrame.class.getResource("imgTag.gif")); titledBorder1 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(142, 142, 142)),"Data"); border1 = BorderFactory.createEtchedBorder(Color.white,new Color(142, 142, 142)); titledBorder2 = new TitledBorder(border1,"Action Type"); border2 = BorderFactory.createEtchedBorder(Color.white,new Color(142, 142, 142)); titledBorder3 = new TitledBorder(new EtchedBorder(EtchedBorder.RAISED,Color.white,new Color(142, 142, 142)),"Additional Actions"); border3 = new EtchedBorder(EtchedBorder.RAISED,Color.white,new Color(142, 142, 142)); this.getContentPane().setLayout(borderLayout1); ContentPanel.setLayout(borderLayout4); RefreshToggleButton.setNextFocusableComponent(PropertiesButton); RefreshToggleButton.setIcon(imgrefresh); RefreshToggleButton.setText("Refresh"); RefreshToggleButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { ToggleButton_actionPerformed(e); } }); PrevToggleButton.setNextFocusableComponent(RefreshToggleButton); PrevToggleButton.setIcon(imgprev); PrevToggleButton.setText("Prev"); PrevToggleButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { ToggleButton_actionPerformed(e); } }); ActionPanel.setBorder(titledBorder2); ActionPanel.setMinimumSize(new Dimension(301, 50)); ActionPanel.setPreferredSize(new Dimension(512, 70)); ActionPanel.setRequestFocusEnabled(false); ActionPanel.setLayout(flowLayout1); GoToggleButton.setNextFocusableComponent(PrevToggleButton); GoToggleButton.setIcon(imggo); GoToggleButton.setText("Go"); GoToggleButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { ToggleButton_actionPerformed(e); } }); Additionals.setBorder(titledBorder3); Additionals.setMinimumSize(new Dimension(332, 200)); Additionals.setPreferredSize(new Dimension(404, 230)); Additionals.setRequestFocusEnabled(false); Additionals.setLayout(borderLayout2); AcceptPanel.setLayout(flowLayout2); flowLayout2.setAlignment(FlowLayout.RIGHT); CancelButton.setNextFocusableComponent(NoneToggleButton); CancelButton.setText("Cancel"); CancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { CancelButton_actionPerformed(e); } }); OkButton.setMaximumSize(new Dimension(81, 29)); OkButton.setMinimumSize(new Dimension(81, 29)); OkButton.setNextFocusableComponent(CancelButton); OkButton.setPreferredSize(new Dimension(81, 29)); OkButton.setText("Ok"); OkButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { OkButton_actionPerformed(e); } }); ContentPanel.setMaximumSize(new Dimension(390, 340)); ContentPanel.setMinimumSize(new Dimension(380, 301)); ContentPanel.setPreferredSize(new Dimension(385, 370)); ContentPanel.setRequestFocusEnabled(false); NoneToggleButton.setNextFocusableComponent(GoToggleButton); NoneToggleButton.setText("None"); NoneToggleButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { ToggleButton_actionPerformed(e); } }); AdditionalControlsPanel.setLayout(borderLayout5); AdditionalButtonPanel.setLayout(gridLayout1); gridLayout1.setRows(3); gridLayout1.setColumns(1); PostfieldButton.setNextFocusableComponent(SetVarButton); PostfieldButton.setHorizontalAlignment(SwingConstants.LEFT); PostfieldButton.setIcon(imgpost); PostfieldButton.setText("Postfield"); PostfieldButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { PostfieldButton_actionPerformed(e); } }); SetVarButton.setNextFocusableComponent(DeleteButton); SetVarButton.setHorizontalAlignment(SwingConstants.LEFT); SetVarButton.setIcon(imgvar); SetVarButton.setText("Setvar"); SetVarButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { SetVarButton_actionPerformed(e); } }); LayoutPanel.setBorder(BorderFactory.createEtchedBorder()); LayoutPanel.setRequestFocusEnabled(false); AdditionalActionList.setNextFocusableComponent(OkButton); AdditionalActionList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); AdditionalActionList.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(MouseEvent e) { AdditionalActionList_mouseClicked(e); } }); PropertiesButton.setNextFocusableComponent(PropertiesScrollPane); PropertiesButton.setText("Properties"); PropertiesButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { PropertiesButton_actionPerformed(e); } }); PropertiesScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); PropertiesScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); PropertiesScrollPane.setNextFocusableComponent(PostfieldButton); PropertiesScrollPane.setPreferredSize(new Dimension(242, 40)); DeleteButton.setNextFocusableComponent(AdditionalActionList); DeleteButton.setText("Delete"); DeleteButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { DeleteButton_actionPerformed(e); } }); jLabel1.setBorder(border3); jLabel1.setPreferredSize(new Dimension(360, 2)); jLabel1.setRequestFocusEnabled(false); this.setModal(true); PropertiesText.setRequestFocusEnabled(false); PropertiesText.setEditable(false); AdditionalControlsPanel.setRequestFocusEnabled(false); AdditionalButtonPanel.setRequestFocusEnabled(false); AcceptPanel.setRequestFocusEnabled(false); this.getContentPane().add(ContentPanel, BorderLayout.CENTER); ContentPanel.add(ActionPanel, BorderLayout.CENTER); ActionPanel.add(NoneToggleButton, null); ActionPanel.add(GoToggleButton, null); ActionPanel.add(PrevToggleButton, null); ActionPanel.add(RefreshToggleButton, null); ActionPanel.add(jLabel1, null); ActionPanel.add(PropertiesScrollPane, null); PropertiesScrollPane.getViewport().add(PropertiesText, null); ActionPanel.add(PropertiesButton, null); ContentPanel.add(Additionals, BorderLayout.SOUTH); Additionals.add(ListScrollPane, BorderLayout.CENTER); ListScrollPane.getViewport().add(AdditionalActionList, null); Additionals.add(AdditionalControlsPanel, BorderLayout.EAST); AdditionalControlsPanel.add(LayoutPanel, BorderLayout.CENTER); LayoutPanel.add(AdditionalButtonPanel, null); AdditionalButtonPanel.add(PostfieldButton, null); AdditionalButtonPanel.add(SetVarButton, null); AdditionalControlsPanel.add(DeleteButton, BorderLayout.SOUTH); this.getContentPane().add(AcceptPanel, BorderLayout.SOUTH); AcceptPanel.add(OkButton, null); AcceptPanel.add(CancelButton, null); actionGroup.add(NoneToggleButton); actionGroup.add(GoToggleButton); actionGroup.add(PrevToggleButton); actionGroup.add(RefreshToggleButton); } /** * General ToggleButton handler, detects clicks on the "None", "Go", "Prev", * and "Refresh" ToggleButtons in the dialog. Based on what button is selected * dialog controls are updated and control states changed to reflect the * choices available to the selected button. */ private void ToggleButton_actionPerformed(ActionEvent e) { String action = (String) e.getActionCommand(); if (!prevAction.equals(action)) { listData = new Vector(); AdditionalActionList.setListData(listData); } if (action.equals("None")) { SetVarButton.setEnabled(false); PostfieldButton.setEnabled(false); DeleteButton.setEnabled(false); AdditionalActionList.setEnabled(false); PropertiesButton.setEnabled(false); PropertiesText.setEnabled(false); PropertiesText.setText(""); } if (action.equals("Prev") && !prevAction.equals("Prev")) { AdditionalActionList.setCellRenderer(new CustomCellRenderer(SetVarButton.getIcon())); SetVarButton.setEnabled(true); PostfieldButton.setEnabled(false); DeleteButton.setEnabled(true); AdditionalActionList.setEnabled(true); PropertiesButton.setEnabled(true); PropertiesText.setEnabled(true); PropertiesText.setText(""); } if (action.equals("Go") && !prevAction.equals("Go")) { AdditionalActionList.setCellRenderer(new CustomCellRenderer(PostfieldButton.getIcon())); SetVarButton.setEnabled(true); PostfieldButton.setEnabled(true); DeleteButton.setEnabled(true); AdditionalActionList.setEnabled(true); PropertiesButton.setEnabled(true); PropertiesText.setEnabled(true); PropertiesText.setText(""); } if (action.equals("Refresh") && !prevAction.equals("Refresh")) { prevAction = action; AdditionalActionList.setCellRenderer(new CustomCellRenderer(SetVarButton.getIcon())); SetVarButton.setEnabled(true); PostfieldButton.setEnabled(false); DeleteButton.setEnabled(true); AdditionalActionList.setEnabled(true); PropertiesButton.setEnabled(true); PropertiesText.setEnabled(true); PropertiesText.setText(""); } if (!prevAction.equals(action)) prevAction = action; } /** * Adds a String with the neccessary "postfield" data to the list. */ private void PostfieldButton_actionPerformed(ActionEvent e) { listData.add(new String("<postfield name=\"\" value=\"\"/>")); AdditionalActionList.setListData(listData); AdditionalActionList.setSelectedIndex(listData.size() - 1);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -