📄 lwcomplexpan.java
字号:
sl3.setValues (0, 100, new int[0], 1, false); sl3.setLocation(20, 120);*/ root.add (sl1); root.add (sl2); root.add (sl3); root.add (sl4); root.add (sl5); root.add (sl6); root.add (sl7); root.add (lab1); return root; } private static LwContainer makeRoot() { LwContainer root = new LwPanel(); root.setLwLayout(new LwRasterLayout(LwRasterLayout.USE_PS_SIZE)); root.setOpaque(false); return root; } private static LwComponent makeImageLabel(String img, String lab) { LwPanel c = new LwPanel(); c.setInsets (2,2,2,2); c.setLwLayout(new LwFlowLayout()); c.add(new LwImage((LwImgRender)LwManager.getView(img))); c.add(new LwLabel(new Text(lab))); return c; } private static String readPropFile() throws Exception { BufferedReader buf = new BufferedReader(new InputStreamReader(LwToolkit.class.getResourceAsStream("rs/lw.properties"))); String res = "", line = null; while ((line = buf.readLine()) != null) res += (line + "\n"); return res; } private static LwLabel makeTitle(String s, int y) { LwLabel lab = new LwLabel(new Text(s)); lab.setBackground(Color.lightGray); lab.getTextRender().setFont(LwToolkit.BFONT); lab.setPSSize(480, -1); lab.setInsets(1,1,1,1); lab.setLocation(10, y); return lab; } private static LwLabel makeComment (String s, int x, int y, int w) { LwLabel l = new LwLabel(new Text(s)); l.setPSSize (w, -1); l.setLocation (x, y); l.setOpaque(false); l.getTextRender().setFont(LwToolkit.BFONT); l.getTextRender().setForeground(Color.darkGray); return l; } private static LwComponent makeNotebook(int o) { LwNotebook nb = new LwNotebook(o); for (int i=1; i<4; i++) { LwPanel pan = new LwPanel(); pan.setLwLayout(new LwBorderLayout()); pan.setInsets(4, 4, 4, 4); pan.add (LwBorderLayout.CENTER, new LwImage(new LwImgRender("rs/demo/cosmo" + i +".jpg", LwImgRender.STRETCH))); nb.addPage("Page " + i, pan); } nb.addPage("Disabled", new LwCanvas()); nb.enablePage(3, false); return nb; }}class TVPimplements LwViewProvider{ public LwView getView(Drawable d, Object obj) { String s = (String)((Item)obj).getValue(); if (s.indexOf ("Check")==0) { LwCheckbox ch = new LwCheckbox(s); ch.setOpaque(false); return new LwCompRender(ch); } else if (s.indexOf ("Image")==0) { LwContainer c = new LwPanel(); LwFlowLayout l = new LwFlowLayout(); l.setGaps(0, 0); c.setLwLayout(l); c.add (new LwImage((LwImgRender)LwManager.getView("paw"))); c.add (new LwLabel(s)); c.setOpaque(false); return new LwCompRender(c); } else if (s.indexOf ("Multi")==0) { LwTextRender tr = new LwTextRender(s); tr.setFont(LwToolkit.BFONT); return tr; } else if (s.indexOf("Bordered") == 0) { LwLabel lab = new LwLabel (s); lab.getViewMan(true).setBorder("br.etched"); return new LwCompRender(lab); } return new LwTextRender(s); }}class LwCustomBorderextends LwView{ private int size = 5; LwCustomBorder() { super(STRETCH); } public Insets getInsets () { return new Insets(size, size, size, size); } public void paint(Graphics g, int x, int y, int w, int h, Drawable d) { int xx = x, yy = y; int wc = w/size; for (int i = 0; i < wc; i++) { drawCross (g, xx, yy, size, size); drawCross (g, xx, yy + h - size - 1, size, size); xx+=size; } xx = x; yy = y + size; h -= (2*size); int hc = h/size; for (int i = 0; i < hc; i++) { drawCross (g, xx, yy, size, size); drawCross (g, xx + w - size - 1, yy, size, size); yy+=size; } } protected void drawCross (Graphics g, int x, int y, int w, int h) { g.setColor(Color.black); g.drawLine(x, y, x + w, y + h); g.drawLine(x + w, y, x, y + h); }}class LwCompViewsimplements LwGridViewProvider{ private LwCompRender render; public LwCompViews() { render = new LwCompRender(null); } public java.awt.Color getCellColor (int row, int col) { return null; } public int getXAlignment (int row, int col) { return Alignment.CENTER; } public int getYAlignment (int row, int col) { return Alignment.CENTER; } public LwView getView(int row, int col, Object o) { render.setTarget(o); return render; }}class LwCompEditorsimplements LwEditorProvider{ public LwComponent getEditor(int row, int col, Object o) { return (((LwComponent)o).canHaveFocus())?(LwComponent)o:null; } public Object fetchEditedValue (int row, int col, LwComponent editor) { return editor; } public boolean shouldStartEdit (int row, int col, LwAWTEvent e) { return true; }}class RgbMaskValidatorextends BasicMaskValidator{ public boolean isValidValue(MaskElement e, String v) { if (e.getType() == NUMERIC_TYPE) { try { int value = Integer.parseInt (v); return value > 0 && value < 256; } catch (NumberFormatException ee) { return false; } } return super.isValidValue(e, v); }}class LwGVextends LwDefViews{ public LwView getView(int row, int col, Object obj) { if (col == 3 || col == 4) { StringTokenizer st = new StringTokenizer((String)obj, ";"); int index = Integer.parseInt (st.nextToken()); while (index > 0) { st.nextToken(); index--; } obj = st.nextToken(); } LwView v = super.getView(row, col, obj); if (col == 0) ((LwTextRender)v).setFont(LwToolkit.BFONT); else ((LwTextRender)v).setFont(LwToolkit.FONT); return v; }}class WOALimplements LwActionListener{ private static int x = 120, y = 100; private LwButton opaque, trans, modal; WOAL (LwButton o, LwButton t, LwButton m) { opaque = o; trans = t; modal = m; } public void actionPerformed (LwActionEvent e) { LwWindow w = new LwWindow ("Demo window"); w.setSize (200, 200); w.setLocation(x+=20, y+=20); w.getRoot().setLwLayout (new LwBorderLayout()); w.getRoot().add (LwBorderLayout.CENTER, new LwTextField("Edit text here !")); //!!! LwCombo cc = new LwCombo(); cc.getList().add ("Item 1"); cc.getList().add ("Item 2"); cc.getList().add ("Item 3"); w.getRoot().add (LwBorderLayout.SOUTH, cc); if (e.getSource() == trans) { w.setOpaque (false); w.getTitlePanel().setOpaque(true); } LwToolkit.getDesktop((LwComponent)e.getSource()).getLayer(LwWinLayer.ID).add (e.getSource()==modal?LwWinLayer.MODAL_WIN:LwWinLayer.MDI_WIN, w); }}class LwGEextends LwDefEditors{ public LwComponent getEditor(int row, int col, Object o) { switch (col) { case 1: { LwComponent c = super.getEditor(row, col, o); c.getViewMan(true).setBorder((LwView)null); c.setBackground(Color.white); return c; } case 2: { LwCheckbox box = new LwCheckbox((LwComponent)null, LwCheckbox.CHECK); box.setBackground(Color.white); box.setState(o.equals("Yes")); return box; } case 3: { LwCombo box = new LwCombo(); box.setBackground(Color.white); StringTokenizer st = new StringTokenizer((String)o, ";"); int index = Integer.parseInt(st.nextToken()); for(;st.hasMoreTokens();) box.getList().add (st.nextToken()); box.getList().select(index); return box; } case 4: { LwCombo box = new LwCombo(); box.setBackground(Color.white); StringTokenizer st = new StringTokenizer((String)o, ";"); int index = Integer.parseInt(st.nextToken()); for(;st.hasMoreTokens();) box.getList().add (st.nextToken()); box.getList().select(index); return box; } } return null; } public Object fetchEditedValue (int row, int col, LwComponent editor) { switch (col) { case 1: return super.fetchEditedValue(row, col, editor); case 2: { LwCheckbox box = (LwCheckbox)editor; return box.getState()?"Yes":"No"; } case 3: { LwCombo box = (LwCombo)editor; box.setBackground(Color.white); String res = "" + box.getList().getSelectedIndex() + ";"; for (int i=0; i<box.getList().count(); i++) { if (i > 0) res += ";"; res += ((LwLabel)box.getList().get(i)).getText(); } return res; } case 4: { LwCombo box = (LwCombo)editor; box.setBackground(Color.white); String res = "" + box.getList().getSelectedIndex() + ";"; for (int i=0; i<box.getList().count(); i++) { if (i > 0) res += ";"; res += ((LwLabel)box.getList().get(i)).getText(); } return res; } } return ((LwTextField)editor).getTextModel().getText(); }}class TTIimplements TooltipInfo{ private LwComponent tooltip; private int type; TTI(int type) { this.type = type; if (type == 1) tooltip = LwTooltipMan.createTooltip(""); else if (type == 2) { tooltip = LwTooltipMan.createTooltip("Transparent and\nmultiline tooltip."); tooltip.setOpaque(false); tooltip.getViewMan(true).setBorder("br.dot"); ((LwLabel)tooltip).setInsets(5,5,5,5); ((LwLabel)tooltip).getTextRender().setForeground(Color.red); ((LwLabel)tooltip).getTextRender().setFont (LwToolkit.BFONT); } else if (type == 3) { LwPanel p = new LwPanel(); p.setLwLayout(new LwFlowLayout()); p.add (new LwImage((LwImgRender)LwManager.getView("paw"))); p.add (new LwLabel(new Text("This is more\ncomplex tooltip."))); tooltip = p; tooltip.getViewMan(true).setBorder("br.plain"); tooltip.setBackground(LwTooltipMan.tooltipBack); } } public LwComponent getTooltip(int x, int y) { if (type == 1) { ((LwLabel)tooltip).setText ("[x=" + x + ",y=" + y + "]"); return tooltip; } else return tooltip; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -