📄 anchortagdesigner.java
字号:
} /** * Adds a String with the neccessary "setvar" data to the list. */ private void SetVarButton_actionPerformed(ActionEvent e) { listData.add(new String("<setvar name=\"\" value=\"\"/>")); AdditionalActionList.setListData(listData); AdditionalActionList.setSelectedIndex(listData.size() - 1); } /** * Removes a selected list item from the list. */ private void DeleteButton_actionPerformed(ActionEvent e) { try { int index = AdditionalActionList.getSelectedIndex(); listData.remove(index); AdditionalActionList.setListData(listData); if (listData.size() > 0) { if (index > 0) AdditionalActionList.setSelectedIndex(index - 1); else AdditionalActionList.setSelectedIndex(0); } } catch (ArrayIndexOutOfBoundsException arrerr) {} } /** * Displays the properties dialog box of the currently selected ToggleButton. */ private void PropertiesButton_actionPerformed(ActionEvent e) { if (GoToggleButton.isSelected()) { GraphicalControlsProperties gcp = new GraphicalControlsProperties(); Vector properties = processGoProperties(); gcp.showGoPanel((String) properties.get(0), (String) properties.get(1), (String) properties.get(2), (String) properties.get(3), (String) properties.get(4), (String) properties.get(5), (String) properties.get(6)); gcp.show(); Vector dialogData = gcp.getData(); try { if (dialogData.size() > 0) processGoProperties(dialogData); } catch (NullPointerException nullerr) {} } else { JPanel p = new JPanel(); p.setName(PropertiesText.getText()); new SpecialAttributesProperties(p, false); PropertiesText.setText(p.getName()); } } /** * Process the properties listed in the PropertiesTextBox and puts them into a * Vector for further processing. * @return Vector properties - a Vector with the following structure:<br> * href - the url to link too.<br> * accept-charset<br> * method - with values as "N/A", "get", or "post."<br> * sendreferer - with values "N/A", "true", or "false."<br> * cache-control<br> * enctype - with values "N/A", and two other supported values.<br> * extra - the id, class, and xml:lang values.<br><br> * * If a value is not found an empty String is returned in its place. * */ private Vector processGoProperties() { String value = ""; String extra = ""; Vector v = new Vector(); String[] properties = {"href", "accept-charset", "method", "sendreferer", "cache-control", "enctype"}; String s = PropertiesText.getText(); int start = -1; for (int i = 0; i < 6; i++) { start = s.indexOf(properties[i]); if (start > -1) { start = s.indexOf("=" , start + 1); if (start > -1) { start = s.indexOf("\"" , start + 1); if (start > -1) { int end = s.indexOf("\"" , start + 1); if (end < 0) end = s.length(); value = s.substring(start + 1, end); } } } else { value = ""; } v.add(value); } start = s.indexOf("id=\""); if (start > -1) { start = start + 4; int end = s.indexOf("\"", start); extra = extra + " " + s.substring(start - 4, end + 1); } start = s.indexOf("class=\""); if (start > -1) { start = start + 7; int end = s.indexOf("\"", start); extra = extra + " " + s.substring(start - 7, end + 1); } start = s.indexOf("xml:lang=\""); if (start > -1) { start = start + 10; int end = s.indexOf("\"", start); extra = extra + " " + s.substring(start - 10, end + 1); } v.add(extra); return v; } /** * Similar to the previous processGoProperties, although this time * no searching for attributes takes place and the properties found * in the Vector are added as text to the PropertiesTextBox. * @param Vector data - the vector containing the properties to be processed. */ private void processGoProperties(Vector data) { String s = ""; String value = (String) data.get(0); if (!value.equals("")) s = s + "href=\"" + (String) data.get(0) + "\" "; value = (String) data.get(1); if (!value.equals("")) s = s + "accept-charset=\"" + (String) data.get(1) + "\" "; value = (String) data.get(2); if (!value.equals("N/A")) s = s + "method=\"" + (String) data.get(2) + "\" "; value = (String) data.get(3); if (!value.equals("N/A")) s = s + "sendreferer=\"" + (String) data.get(3) + "\" "; value = (String) data.get(4); if (!value.equals("N/A")) s = s + "cache-control=\"" + (String) data.get(4) + "\" "; value = (String) data.get(5); if (!value.equals("N/A")) s = s + "enctype=\"" + (String) data.get(5) + "\" "; value = (String) data.get(6); if (value.length() > 0) { s = s + " " + value; } s = s.trim(); PropertiesText.setText(s); } /** * A handler for the list's mouseClicked event. If the list box is double * clicked, the selected item's properties box is displayed. */ private void AdditionalActionList_mouseClicked(MouseEvent e) { if ((e.getModifiers() == LEFT_MOUSE_BUTTON) && (e.getClickCount() > 1)) { if (listData.size() > 0) { try { String oldtag = (String) AdditionalActionList.getSelectedValue(); // display the gcp window for this control based on what button is pressed GraphicalControlsProperties gcp = new GraphicalControlsProperties(); Vector properties = processProperties(); if (oldtag.indexOf("postfield") > -1) { // show the postfield pane gcp.showPostfieldPanel((String) properties.get(0), (String) properties.get(1), (String) properties.get(2)); gcp.show(); Vector dialogData = gcp.getData(); try { if (dialogData.size() > 0) processProperties(dialogData); } catch (NullPointerException nullerr) {} } else { // ahow the Setvar pane gcp.showSetvarPanel((String) properties.get(0), (String) properties.get(1), (String) properties.get(2)); gcp.show(); Vector dialogData = gcp.getData(); try { if (dialogData.size() > 0) processProperties(dialogData); } catch (NullPointerException nullerr) {} } } catch (ArrayIndexOutOfBoundsException arrerr) {} } } } /** * A method for processing the properties returned by the selected list * item's properties dialog. It distinguishes between the "postfield" * and "setvar" tags and then makes the neccessary changes to the selected * list item's text by applying the data gathered from the item's properties * dialog box. * @param Vector data - the data gathered from the properties dialog. */ private void processProperties(Vector data) { int selected = AdditionalActionList.getSelectedIndex(); String oldtag = (String) AdditionalActionList.getSelectedValue(); String s = "<"; if (oldtag.indexOf("postfield") > -1) s = s + "postfield "; else s = s + "setvar "; s = s + "value=\"" + (String) data.get(0) + "\" name=\"" + (String) data.get(1) + "\""; s = s.trim(); if (!(((String) data.get(2)).equals(""))) s = s + " " + (String) data.get(2); s = s + "/>"; listData.setElementAt(s, selected); AdditionalActionList.setListData(listData); } /** * Processes the properties of the selected list item into a vector for further * processing. * @return Vector properties - the properties of the selected item, the Vector * has the following structure:<br> * value<br> * name<br> * extra - id, class, and xml:lang (when supported by dtd in future)<br><br> * * Items not found in the slected list item are initlaized to empty strings. */ private Vector processProperties() { String value = ""; String name = ""; String extra = ""; String s = (String) listData.get(AdditionalActionList.getSelectedIndex()); int start = s.indexOf("value=\""); if (start > -1) { start = s.indexOf("=" , start + 1); if (start > -1) { start = s.indexOf("\"" , start + 1); if (start > -1) { int end = s.indexOf("\"" , start + 1); if (end < 0) end = s.length(); value = s.substring(start + 1, end); } } } start = s.indexOf("name=\""); if (start > -1) { start = s.indexOf("=" , start + 1); if (start > -1) { start = s.indexOf("\"" , start + 1); if (start > -1) { int end = s.indexOf("\"" , start + 1); if (end < 0) end = s.length(); name = s.substring(start + 1, end); } } } start = s.indexOf("id=\""); if (start > -1) { start = start + 4; int end = s.indexOf("\"", start); extra = extra + " " + s.substring(start - 4, end + 1); } start = s.indexOf("class=\""); if (start > -1) { start = start + 7; int end = s.indexOf("\"", start); extra = extra + " " + s.substring(start - 7, end + 1); } start = s.indexOf("xml:lang=\""); if (start > -1) { start = start + 10; int end = s.indexOf("\"", start); extra = extra + " " + s.substring(start - 10, end + 1); } Vector v = new Vector(); v.add(value); v.add(name); v.add(extra.trim()); return v; } /** * OK Button handler. If pressed calls getData(), sets the OKPressed variable to * true, and hides the dialog. */ private void OkButton_actionPerformed(ActionEvent e) { OkPressed = true; setVisible(false); getData(); } /** * Cancel Button handler. Just hides the dialog. */ private void CancelButton_actionPerformed(ActionEvent e) { setVisible(false); } /** * Use this to check if the OK Button was pressed before the dialog was hidden. * @return boolean OKPressed - true if the OK Button was pressed. */ public boolean getButtonPressed() { return OkPressed; } /** * Gathers all the data from the dialog, based on values set, and button states, * and collates it all into a SimpleAttributeSet so that it can be added to the * selected text. * @return SimpleAttributeSet set - the modified Anchor tag attributes. */ public SimpleAttributeSet getData() { if (!(NoneToggleButton.isSelected())) { SimpleAttributeSet control = new SimpleAttributeSet(); for (int x = 0; x < AdditionalActionList.getModel().getSize(); x++) { SimpleAttributeSet otherControls = getListAttributes(x); control.addAttributes(otherControls); } if (GoToggleButton.isSelected()) { SimpleAttributeSet attribs = processAttributes(); attribs.addAttributes(control); SimpleAttributeSet goControl = new SimpleAttributeSet(); goControl.addAttribute("go", attribs); return goControl; } if (PrevToggleButton.isSelected()) { SimpleAttributeSet attribs = processAttributes(); attribs.addAttributes(control); SimpleAttributeSet prevControl = new SimpleAttributeSet(); prevControl.addAttribute("prev", attribs); return prevControl; } if (RefreshToggleButton.isSelected()) { SimpleAttributeSet attribs = processAttributes(); attribs.addAttributes(control); SimpleAttributeSet refreshControl = new SimpleAttributeSet(); refreshControl.addAttribute("refresh", attribs); return refreshControl; } } return new SimpleAttributeSet(); } /** * Gets the Attributes from the dialog and collates them into a SimpleAttributeSet * for further processing. * This is used when the "Go" ToggleButton is selected.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -