📄 taghandler.java
字号:
package wapide;/** * A helper class for the IDEFrame class. Provides convsersion subroutines for * converting between graphics and text and vise versa. Also provides rotuines for * inserting the proper text when the toolbar tag buttons are pressed. * * Copyright: Copyright (c) 2003 * Company: * @author Mark Busman * @version 1.0 * * For License and contact information see WAPIDE.java */import java.awt.*;import java.awt.event.*;import java.awt.datatransfer.*;import javax.swing.*;import javax.swing.border.*;import javax.swing.event.*;import javax.swing.text.*;import javax.swing.text.html.*;import javax.swing.tree.*;import java.util.*;import java.lang.*;import java.io.*;import wbmp.WAPImage;public class TagHandler { /** * The popup menu used in both this class and the IDEFrame class. */ protected JPopupMenu ControlPopupMenu = new JPopupMenu(); private JMenuItem ControlInsertColumn = new JMenuItem(); private JMenuItem ControlDeleteRow = new JMenuItem(); private JMenuItem ControlDeleteColumn = new JMenuItem(); private JMenuItem ControlInsertRow = new JMenuItem(); private JMenuItem ControlProperties = new JMenuItem(); private JMenuItem ControlCut = new JMenuItem(); private JMenuItem ControlCopy = new JMenuItem(); private JMenuItem ControlPaste = new JMenuItem(); private ImageIcon image1; // images used in the popup menu private ImageIcon image2; private ImageIcon image3; private ImageIcon image4; private ImageIcon image5; private ImageIcon image6; private JMenu Menu; private JToolBar Tools; private JToolBar AdvancedTools; private JMenuItem ControlEditAnchor = new JMenuItem(); // User defined variables /** * The type of control currently selected, values range from -1 to 5. * -1 means nothing selected, a value b/w 0 and 5 indicates one of the * control inner-classes defined in this class. */ private int type = -1; /** * Unique control ID. */ private int GlobalControlCounter = -1; /** * The GraphicsPane reference to which all controls are added. */ private JTextPane gp = new JTextPane(); /** * Used by the table when a cell is selected. */ private JTextPane focusControl = null; /** * Reference to the card tabs panel in the IDEFrame class. */ private JTabbedPane CardPane = new JTabbedPane(); /** * Reference to the IDEFrame class statusbar. */ private JLabel Statusbar = new JLabel(); /** * Used by several inner-classes to indicate that a designer * window is open since these windows are non-modal. */ private boolean dialogOpen = false; /** * Indicates that the current card has card level tags such as do * before the "p" and "pre" tags. */ private boolean CardTagsCreated = false; /** * Main OptionDesigner dialog to which new dialogs are assigned. */ private OptionDesigner currentOptionDesigner = new OptionDesigner(); /** * Main CardLevelTagsDesigner dialog to which new doDesigner dialogs are assigned. */ private CardLevelTagsDesigner currentDoDesigner = new CardLevelTagsDesigner(); /** * Main CardLevelTagsDesigner dialog to which new CardLevelTagsDesigner dialogs * are assigned. */ private CardLevelTagsDesigner currentTagsDesigner = new CardLevelTagsDesigner(); /** * The currently selected control, img, do, var, or other. If in a table then the * selected cell becomes the controlContainer. If no controls selected, then null. */ private JComponent controlContainer; /** * Stores the data of each individual card's card level tags. */ private Vector cardControls = new Vector(); /** * The main KeywordFinder used by this class. */ private KeywordFinder keywordFinder; /** * Used to indicate if the whole anchor tag text is properly selected. */ private boolean AnchorTagFound = false; /** * The current card level tags control */ private CardTags CardLevelTags = null; /** * Indicates the number of cards in the deck. */ private int CardCounter = -1; /** * The current controls, used when switching b/w cards to * maintain the state of the controls w/out having to regenerate * them from scratch everytime a change in cards occurs. Basically * its a vector of vectors. */ private Vector openData = new Vector(); /** * The previous card, important when switching cards and saving data. */ private int previndex = -1; /** * The type of border used by the control. SingleLineBorder or * BracketBorder. */ private Border theBorder; // Constants private static int LEFT_MOUSE_BUTTON = 16; private static int RIGHT_MOUSE_BUTTON = 4; /** * Constructor - creates a new TagHandler object. * @param JTextPane pane - the graphics pane. * @param JMenu menu - main menu of the application. * @param JToolbar tools - the applications's tools toolbar. * @paran JToolbar advancedtools - the application's advanced tools toolbar. * @param JTabbedPane cardtabs - the CardTabspane of the application. * @param JLabel Statusbar - the application's Statusbar. */ public TagHandler(JTextPane pane, JMenu m, JToolBar t , JToolBar at, JTabbedPane cardtabs, JLabel sb) { try { Menu = m; Tools = t; AdvancedTools = at; CardPane = cardtabs; Statusbar = sb; gp = pane; jbInit(); } catch(Exception e) { e.printStackTrace(); } } /** * initializes graphics components. */ private void jbInit() throws Exception { image1 = new ImageIcon(wapide.IDEFrame.class.getResource("cut.gif")); image2 = new ImageIcon(wapide.IDEFrame.class.getResource("copy.gif")); image3 = new ImageIcon(wapide.IDEFrame.class.getResource("paste.gif")); image4 = new ImageIcon(wapide.IDEFrame.class.getResource("dummy.gif")); image5 = new ImageIcon(wapide.IDEFrame.class.getResource("setvarTag.gif")); image6 = new ImageIcon(wapide.IDEFrame.class.getResource("doTag.gif")); ControlProperties.setIcon(image4); ControlProperties.setText("Properties"); ControlProperties.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { ControlProperties_actionPerformed(e); } }); ControlCut.setIcon(image1); ControlCut.setText("Cut"); ControlCut.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { ControlCut_actionPerformed(e); } }); ControlCopy.setIcon(image2); ControlCopy.setText("Copy"); ControlCopy.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { ControlCopy_actionPerformed(e); } }); ControlPaste.setIcon(image3); ControlPaste.setText("Paste"); ControlPaste.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { ControlPaste_actionPerformed(e); } }); ControlPopupMenu.addPopupMenuListener(new javax.swing.event.PopupMenuListener() { public void popupMenuWillBecomeVisible(PopupMenuEvent e) { ControlPopupMenu_popupMenuWillBecomeVisible(e); } public void popupMenuCanceled(PopupMenuEvent e) { } public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { ControlPopupMenu_popupMenuWillBecomeInvisible(e); } }); ControlInsertColumn.setText("Insert Column"); ControlInsertColumn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { ControlInsertColumn_actionPerformed(e); } }); ControlInsertRow.setText("Insert Row"); ControlInsertRow.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { ControlInsertRow_actionPerformed(e); } }); ControlDeleteColumn.setText("Delete Column"); ControlDeleteColumn.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { ControlDeleteColumn_actionPerformed(e); } }); ControlDeleteRow.setText("Delete Row"); ControlDeleteRow.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { ControlDeleteRow_actionPerformed(e); } }); ControlEditAnchor.setIcon(image4); ControlEditAnchor.setText("Edit Anchor Tag"); ControlEditAnchor.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { ControlEditAnchor_actionPerformed(e); } }); ControlPopupMenu.add(ControlCut); ControlPopupMenu.add(ControlCopy); ControlPopupMenu.add(ControlPaste); ControlPopupMenu.addSeparator(); ControlPopupMenu.add(ControlInsertColumn); ControlPopupMenu.add(ControlInsertRow); ControlPopupMenu.addSeparator(); ControlPopupMenu.add(ControlDeleteColumn); ControlPopupMenu.add(ControlDeleteRow); ControlPopupMenu.addSeparator(); ControlPopupMenu.add(ControlEditAnchor); ControlPopupMenu.addSeparator(); ControlPopupMenu.add(ControlProperties); } /////////////////////////////////////////////////////////////////////////// /////// Main Functions /////////////////////////////////////////////////////////////////////////// /** * Gets the text associated with the button pressed, i.e. an imgage button * pressed returns <img src="" alt=""/>. * @param ActionEvent e - the button event. * @return String text - the default text of the button pressed. */ public String getText(ActionEvent e) { String str = ""; String command = ""; try { JMenuItem mi = (JMenuItem) e.getSource(); command = mi.getActionCommand(); } catch (ClassCastException cce) { try { JButton mi = (JButton) e.getSource(); command = mi.getActionCommand(); } catch (ClassCastException cce2) { JComboBox mi = (JComboBox) e.getSource(); command = mi.getActionCommand(); } } if (!command.equals("")) { if (command.equals("<wml> Tag")) // cards & decks str = "<wml>"; if (command.equals("<head> Tag")) str = "<head></head>"; if (command.equals("<meta> Tag")) str = "<meta/>"; if (command.equals("<template> Tag")) str = "<template></template>"; if (command.equals("<card> Tag")) str = "<card id=\"id\" title=\"title\"></card>"; if (command.equals("<a> Tag")) // links str = "<a href=\"url\"></a>"; if (command.equals("<anchor> Tag")) str = "<anchor></anchor>"; if (command.equals("<do> Tag")) // actions str = "<do type=\"unknown\" label=\"title\"></do>"; if (command.equals("<go> Tag")) str = "<go href=\"url\"></go>"; if (command.equals("<noop> Tag")) str = "<noop/>"; if (command.equals("<prev> Tag")) str = "<prev/>"; if (command.equals("<refresh> Tag")) str = "<refresh></refresh>"; if (command.equals("<timer> Tag")) str = "<timer value=\"value\"/>"; if (command.equals("<onevent> Tag")) str = "<onevent type=\"type\"></onevent>"; if (command.equals("<big> Tag")) // font styles str = "<big></big>"; if (command.equals("<b> Tag")) str = "<b></b>"; if (command.equals("<em> Tag")) str = "<em></em>"; if (command.equals("<i> Tag")) str = "<i></i>"; if (command.equals("<small> Tag")) str = "<small></small>"; if (command.equals("<strong> Tag")) str = "<strong></strong>"; if (command.equals("<u> Tag")) str = "<u></u>"; if (command.equals("<br> Tag")) // text format str = "<br/>"; if (command.equals("<img> Tag")) str = "<img alt=\"\" src=\"source\"/>"; if (command.equals("<p> Tag")) str = "<p align=\"left\"></p>"; if (command.equals("<pre> Tag")) str = "<pre></pre>"; if (command.equals("<input> Tag")) // user input str = "<input name=\"var name\"/>"; if (command.equals("<optgroup> Tag")) str = "<optgroup title=\"title\"></optgroup>"; if (command.equals("<option> Tag")) str = "<option value=\"value\"></option>"; if (command.equals("<postfield> Tag"))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -