Thema: [Java] Popup
-
15.04.2011, 05:22 #1
- Registriert seit
- 06.11.2011
- Beiträge
- 418
Thanked 686 Times in 246 Posts[Java] Popup
Ist ein Snippet aus meinem Emulator, kann aber auch Client seitig genutzt werden. Ihr benötigt die PacketBuilder Klasse, hab ich hier aber auch schon released.
ComponentType.java
Code:/* Banana-Chat - The first Open Source Knuddels Emulator * Copyright (C) 2011 Flav <http://www.banana-coding.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package tools.popup; /** * * @author Flav */ public enum ComponentType { BUTTON('b'), TEXT_FIELD('f'), LABEL('l'), TEXT_AREA('t'); private int type; private ComponentType(int type) { this.type = type; } public int getValue() { return type; } }
Code:/* Banana-Chat - The first Open Source Knuddels Emulator * Copyright (C) 2011 Flav <http://www.banana-coding.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package tools.popup; /** * * @author Flav */ public interface Component { public ComponentType getType(); public int[] getForeground(); public void setForeground(int[] foreground); public int[] getBackground(); public void setBackground(int[] background); public String getText(); }
Code:/* Banana-Chat - The first Open Source Knuddels Emulator * Copyright (C) 2011 Flav <http://www.banana-coding.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package tools.popup; /** * * @author Flav */ public class Button implements Component { private int[] foreground, background; private String text; private boolean styled, colored; private boolean close; private boolean action; private String command; public Button(String text) { foreground = new int[] { 0x00, 0x00, 0x00 }; background = new int[] { 0xBE, 0xBC, 0xFB }; this.text = text; styled = false; close = true; action = false; command = null; } public ComponentType getType() { return ComponentType.BUTTON; } public int[] getForeground() { return foreground; } public void setForeground(int[] foreground) { this.foreground = foreground; } public int[] getBackground() { return background; } public void setBackground(int[] background) { this.background = background; } public String getText() { return text; } public boolean isStyled() { return styled; } public boolean isColored() { return colored; } public void setStyled(boolean colored) { styled = true; this.colored = colored; } public boolean isClose() { return close; } public void disableClose() { close = false; } public boolean isAction() { return action; } public void enableAction() { action = true; } public String getCommand() { return command; } public void setCommand(String command) { this.command = command; } }
Code:/* Banana-Chat - The first Open Source Knuddels Emulator * Copyright (C) 2011 Flav <http://www.banana-coding.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package tools.popup; /** * * @author Flav */ public class TextField implements Component { private int[] foreground, background; private String text; private byte width; public TextField(int width) { foreground = new int[] { 0x00, 0x00, 0x00 }; background = new int[] { 0xFF, 0xFF, 0xFF }; text = ""; this.width = (byte) width; } public ComponentType getType() { return ComponentType.TEXT_FIELD; } public int[] getForeground() { return foreground; } public void setForeground(int[] foreground) { this.foreground = foreground; } public int[] getBackground() { return background; } public void setBackground(int[] background) { this.background = background; } public String getText() { return text; } public void setText(String text) { this.text = text; } public byte getWidth() { return width; } }
Code:/* Banana-Chat - The first Open Source Knuddels Emulator * Copyright (C) 2011 Flav <http://www.banana-coding.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package tools.popup; /** * * @author Flav */ public class Label implements Component { private int[] foreground, background; private String text; public Label(String text) { foreground = new int[] { 0x00, 0x00, 0x00 }; background = new int[] { 0xBE, 0xBC, 0xFB }; this.text = text; } public ComponentType getType() { return ComponentType.LABEL; } public int[] getForeground() { return foreground; } public void setForeground(int[] foreground) { this.foreground = foreground; } public int[] getBackground() { return background; } public void setBackground(int[] background) { this.background = background; } public String getText() { return text; } }
Code:/* Banana-Chat - The first Open Source Knuddels Emulator * Copyright (C) 2011 Flav <http://www.banana-coding.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package tools.popup; /** * * @author Flav */ public class TextArea implements Component { private int[] foreground, background; private String text; private boolean editable; private byte scrollbars; private byte rows, columns; public TextArea(int rows, int columns) { foreground = new int[] { 0x00, 0x00, 0x00 }; background = new int[] { 0xFF, 0xFF, 0xFF }; text = ""; editable = true; scrollbars = 1; this.rows = (byte) rows; this.columns = (byte) columns; } public ComponentType getType() { return ComponentType.TEXT_AREA; } public int[] getForeground() { return foreground; } public void setForeground(int[] foreground) { this.foreground = foreground; } public int[] getBackground() { return background; } public void setBackground(int[] background) { this.background = background; } public String getText() { return text; } public void setText(String text) { this.text = text; } public boolean isEditable() { return editable; } public void disable() { editable = false; } public byte getScrollbars() { return scrollbars; } public void setScrollbars(int scrollbars) { this.scrollbars = (byte) scrollbars; } public byte getRows() { return rows; } public byte getColumns() { return columns; } }
Code:/* Banana-Chat - The first Open Source Knuddels Emulator * Copyright (C) 2011 Flav <http://www.banana-coding.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package tools.popup; import java.util.ArrayList; import java.util.List; /** * * @author Flav */ public class Panel { private List<Component> components; public Panel() { components = new ArrayList<Component>(); } public List<Component> getComponents() { return components; } public void addComponent(Component component) { components.add(component); } }
-
16.04.2011, 22:24 #2
- Registriert seit
- 06.11.2011
- Beiträge
- 418
Thanked 686 Times in 246 Posts[Java] Popup
Popup.java
Code:/* Banana-Chat - The first Open Source Knuddels Emulator * Copyright (C) 2011 Flav <http://www.banana-coding.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package tools.popup; import java.util.ArrayList; import java.util.List; import knuddels.SendOpcode; import tools.PacketBuilder; /** * * @author Flav */ public class Popup { private String title, subtitle, message; private int width, height; private List<Panel> panels; private String opcode, parameter; public Popup(String title, String subtitle, String message, int width, int height) { this.title = title; this.subtitle = subtitle; this.message = message; this.width = width; this.height = height; panels = new ArrayList<Panel>(); } public void addPanel(Panel panel) { panels.add(panel); } public void setOpcode(String opcode, String parameter) { this.opcode = opcode; this.parameter = parameter; } @Override public String toString() { PacketBuilder buffer = new PacketBuilder(SendOpcode.POPUP.getValue()); buffer.writeByte(0x00); addString(buffer, title); if (opcode != null) { buffer.writeByte('s'); addString(buffer, opcode); addString(buffer, parameter); } addForeground(buffer, new int[] { 0x00, 0x00, 0x00 }); addBackground(buffer, new int[] { 0xBE, 0xBC, 0xFB }); buffer.writeByte(0xE3); // border right buffer.writeByte('E'); buffer.writeByte('l'); addString(buffer, " "); addFontStyle(buffer, 'p', 5); addBackground(buffer, new int[] { 0xBE, 0xBC, 0xFB }); buffer.writeByte(0xE3); // border left buffer.writeByte('W'); buffer.writeByte('l'); addString(buffer, " "); addFontStyle(buffer, 'p', 5); addBackground(buffer, new int[] { 0xBE, 0xBC, 0xFB }); buffer.writeByte(0xE3); buffer.writeByte('C'); addLayout(buffer, 'B'); buffer.writeByte('N'); addLayout(buffer, 'B'); // border top buffer.writeByte('N'); buffer.writeByte('l'); addString(buffer, " "); addFontStyle(buffer, 'p', 5); addBackground(buffer, new int[] { 0xBE, 0xBC, 0xFB }); buffer.writeByte(0xE3); if (subtitle != null) { buffer.writeByte('C'); buffer.writeByte('l'); addString(buffer, subtitle); addFontStyle(buffer, 'b', 16); addForeground(buffer, new int[] { 0x00, 0x00, 0x00 }); addBackground(buffer, new int[] { 0xE5, 0xE5, 0xFF }); buffer.writeByte(0xE3); buffer.writeByte('S'); buffer.writeByte('l'); addString(buffer, " "); addFontStyle(buffer, 'p', 5); addBackground(buffer, new int[] { 0xBE, 0xBC, 0xFB }); buffer.writeByte(0xE3); } buffer.writeByte(0xE3); if (message != null) { buffer.writeByte('C'); buffer.writeByte('c'); addString(buffer, message); addFrameSize(buffer, width, height); addForeground(buffer, new int[] { 0x00, 0x00, 0x00 }); addBackground(buffer, new int[] { 0xBE, 0xBC, 0xFB }); addBackgroundImage(buffer, "pics/cloudsblue.gif", 17); buffer.writeByte(0xE3); } boolean useBorderLayouts = panels.size() > 1; int borderLayouts = 0; for (Panel panel : panels) { buffer.writeByte('S'); if (useBorderLayouts) { borderLayouts++; addLayout(buffer, 'B'); buffer.writeByte('N'); } addLayout(buffer, 'F'); for (Component component : panel.getComponents()) { ComponentType type = component.getType(); buffer.writeByte(type.getValue()); addString(buffer, component.getText()); if (type == ComponentType.BUTTON) { Button button = (Button) component; if (button.isStyled()) { buffer.writeByte('c'); if (button.isColored()) { buffer.writeByte('e'); } } if (button.isClose()) { buffer.writeByte('d'); } addFontStyle(buffer, 'p', 16); if (button.isAction()) { buffer.writeByte('s'); } if (button.getCommand() != null) { buffer.writeByte('u'); addString(buffer, button.getCommand()); } } else if (type == ComponentType.TEXT_FIELD) { addSize(buffer, ((TextField) component).getWidth()); } else if (type == ComponentType.LABEL) { addFontStyle(buffer, 'p', 16); } else if (type == ComponentType.TEXT_AREA) { TextArea textarea = (TextArea) component; addSize(buffer, textarea.getRows()); addSize(buffer, textarea.getColumns()); switch (textarea.getScrollbars()) { case 0: buffer.writeByte('b'); break; case 1: buffer.writeByte('s'); break; case 2: buffer.writeByte('w'); break; } if (textarea.isEditable()) { buffer.writeByte('e'); } } addForeground(buffer, component.getForeground()); addBackground(buffer, component.getBackground()); buffer.writeByte(0xE3); } buffer.writeByte(0xE3); } for (int i = 0; i < borderLayouts; i++) { buffer.writeByte(0xE3); } buffer.writeByte(0xE3); buffer.writeByte(0xE3); return buffer.toString(); } private static void addSize(PacketBuilder buffer, int size) { buffer.writeByte('A' + size); } private static void addString(PacketBuilder buffer, String str) { buffer.writeString(str); buffer.writeByte(0xF5); } private static void addFontStyle(PacketBuilder buffer, char weight, int size) { if (weight != 'p') { buffer.writeByte(weight); } buffer.writeByte('g'); addSize(buffer, size); } private static void addLayout(PacketBuilder buffer, char layout) { buffer.writeByte('p'); buffer.writeByte(layout); } private static void addFrameSize(PacketBuilder buffer, int width, int height) { buffer.writeByte('s'); buffer.writeShort(width); buffer.writeShort(height); } private static void addForeground(PacketBuilder buffer, int[] color) { buffer.writeByte('f'); buffer.write(color); } private static void addBackground(PacketBuilder buffer, int[] color) { buffer.writeByte('h'); buffer.write(color); } private static void addBackgroundImage(PacketBuilder buffer, String image, int position) { buffer.writeByte('i'); addString(buffer, image); buffer.writeShort(position); } }
Update
TextArea Komponente hinzugefügt
Panel System eingebaut um Komponenten untereinander darstellen zu können
Popup Paket zu 100% analysiert (es fehlen aber immer noch die zwei Komponenten Choice und Checkbox, folgen auch bald)
Ähnliche Themen
-
Win7 Java in Safari ausführen (Fehlermeldung Java nicht installiert)
Von Silverstar im Forum WindowsAntworten: 8Letzter Beitrag: 02.12.2013, 23:41 -
Popup Fenster (Newbie)
Von .MrsError im Forum Knuddels-NewsAntworten: 5Letzter Beitrag: 02.08.2012, 22:13 -
[Java] Popup
Von Flav im Forum SourcecodeAntworten: 7Letzter Beitrag: 27.05.2012, 13:00 -
Popup Hindergrundbild
Von uncopyable im Forum Knuddels ProgrammierungAntworten: 6Letzter Beitrag: 17.12.2011, 15:14 -
Popup Jugendschutztest 1 und 2
Von AFU im Forum Knuddels AllgemeinAntworten: 0Letzter Beitrag: 11.12.2011, 13:14
Diese Seite nutzt Cookies, um das Nutzererlebnis zu verbessern. Klicken Sie hier, um das Cookie-Tracking zu deaktivieren.