📄 buttonbar.java
字号:
} String descr = setup.sval; // This is the hash key. token = setup.nextToken(); if (token == StreamTokenizer.TT_EOF) { ButtonBar.this.error("unexpected end of file"); } else { String value = setup.sval; if (isKeyword(value)) { // Missing command - complain but continue System.err.println(descr + ": missing choice command"); setup.pushBack(); break; } System.out.println("choice: name='" + descr + "', value='" + value); list.add(descr, new JLabel(descr)); choices.put(ident + descr, value); } } ButtonBar.this.error("choices hash: " + choices); } else if (setup.sval.equals("input")) { if ((token = setup.nextToken()) != StreamTokenizer.TT_EOF) { String descr = setup.sval; if ((token = setup.nextToken()) == StreamTokenizer.TT_NUMBER) { int size = (int) setup.nval; String init = "", command = ""; token = setup.nextToken(); if (isKeyword(setup.sval)) setup.pushBack(); else command = setup.sval; token = setup.nextToken(); if (isKeyword(setup.sval)) { setup.pushBack(); init = command; } else init = setup.sval; JTextField t = new JTextField(init, size); if (!init.equals(command)) { buttons.put(t, command); t.addActionListener(ButtonBar.this); } fields.put(descr, t); l.setConstraints(t, constraints(c, setup)); panel.add(t); } else ButtonBar.this.error(descr + ": missing field size"); } else ButtonBar.this.error("unexpected end of file"); } break; default: ButtonBar.this.error("syntax error at line " + setup.lineno()); } } } catch (IOException e) { ButtonBar.this.error("unexpected error while reading setup: " + e); } panel.validate(); } }); } private GridBagConstraints constraints(GridBagConstraints c, StreamTokenizer setup) throws IOException { if (setup.nextToken() == StreamTokenizer.TT_WORD) if (setup.sval.equals("break")) c.gridwidth = GridBagConstraints.REMAINDER; else if (setup.sval.equals("stretch")) c.weightx = 1.0; else setup.pushBack(); else setup.pushBack(); return c; } public void valueChanged(ListSelectionEvent evt) { String tmp, ident; if ((ident = (String) choices.get(evt.getSource())) != null) { // It's a choice - get the text from the selected item JList list = (JList) evt.getSource(); tmp = (String) choices.get(ident + list.getSelectedValue()); if (tmp != null) processEvent(tmp); } } public void actionPerformed(ActionEvent evt) { String tmp; if ((tmp = (String) buttons.get(evt.getSource())) != null) processEvent(tmp); } private void processEvent(String tmp) { String cmd = "", function = null; int idx = 0, oldidx = 0; while ((idx = tmp.indexOf('\\', oldidx)) >= 0 && ++idx <= tmp.length()) { cmd += tmp.substring(oldidx, idx - 1); switch (tmp.charAt(idx)) { case 'b': cmd += "\b"; break; case 'e': cmd += ""; break; case 'n': cmd += "\n"; break; case 'r': cmd += "\r"; break; case '$': { int ni = tmp.indexOf('(', idx + 1); if (ni < idx) { error("ERROR: Function: missing '('"); break; } if (ni == ++idx) { error("ERROR: Function: missing name"); break; } function = tmp.substring(idx, ni); idx = ni + 1; ni = tmp.indexOf(')', idx); if (ni < idx) { error("ERROR: Function: missing ')'"); break; } tmp = tmp.substring(idx, ni); idx = oldidx = 0; continue; } case '@': { int ni = tmp.indexOf('@', idx + 1); if (ni < idx) { error("ERROR: Input Field: '@'-End Marker not found"); break; } if (ni == ++idx) { error("ERROR: Input Field: no name specified"); break; } String name = tmp.substring(idx, ni); idx = ni; JTextField t; if (fields == null || (t = (JTextField) fields.get(name)) == null) { error("ERROR: Input Field: requested input \"" + name + "\" does not exist"); break; } cmd += t.getText(); if (clearFields) t.setText(""); break; } default : cmd += tmp.substring(idx, ++idx); } oldidx = ++idx; } if (oldidx <= tmp.length()) cmd += tmp.substring(oldidx, tmp.length()); if (function != null) { if (function.equals("break")) { bus.broadcast(new TelnetCommandRequest((byte) 243)); // BREAK return; } if (function.equals("exit")) { try { System.exit(0); } catch (Exception e) { error("cannot exit: " + e); } } if (function.equals("connect")) { String address = null; int port = -1; try { if ((idx = cmd.indexOf(",")) >= 0) { try { port = Integer.parseInt(cmd.substring(idx + 1, cmd.length())); } catch (Exception e) { port = -1; } cmd = cmd.substring(0, idx); } if (cmd.length() > 0) address = cmd; if (address != null) if (port != -1) bus.broadcast(new SocketRequest(address, port)); else bus.broadcast(new SocketRequest(address, 23)); else error("connect: no address"); } catch (Exception e) { error("connect(): failed"); e.printStackTrace(); } } else if (function.equals("disconnect")) bus.broadcast(new SocketRequest()); else if (function.equals("detach")) { error("detach not implemented yet"); } else error("ERROR: function not implemented: \"" + function + "\""); return; } // cmd += tmp.substring(oldidx, tmp.length()); if (cmd.length() > 0) try { write(cmd.getBytes()); } catch (IOException e) { error("send: " + e); } } public JComponent getPluginVisual() { return panel; } public JMenu getPluginMenu() { return null; } FilterPlugin source; public void setFilterSource(FilterPlugin source) { this.source = source; } public FilterPlugin getFilterSource() { return source; } public int read(byte[] b) throws IOException { return source.read(b); } public void write(byte[] b) throws IOException { source.write(b); } private static boolean isKeyword(String txt) { return ( txt.equals("button") || txt.equals("label") || txt.equals("input") || txt.equals("stretch") || txt.equals("choice") || txt.equals("break") ); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -