1. #1
    Avatar von Mentos
    Registriert seit
    18.11.2011
    Beiträge
    451
    Thanked 498 Times in 240 Posts

    Standard [JAVA] KButton

    Hey,

    als ich heute meine /edit machen wollte, ist mir aufgefallen, dass es bei den Buttons, die nicht standardmäßig beim Popup implementiert sind, es Parameter gibt, die das Aussehen und die Eigenschaften beeinflussen.

    Ich habe mir die Eigenschaften(u.a. enable, visible, ...) aus dem akn-Applet rausgesucht und daraus eine Klasse gebaut.

    Das Prinzip ist relativ einfach:

    °>{button} Text||call|/Befehl |Parameter1|Value1|Parameter 2|Value2<°

    Dennoch ist es natürlich einfacher, wenn man eine Klasse dafür hat, damit man sich die Parameter nicht merken muss und das ganze einfach praktischer hat.

    Beispiel-Code (+Screen):

    PHP-Code:
    tools.objects.KButton testButton = new tools.objects.KButton("HEY KIDS!""/m -");
            
    testButton.setWidth(100);
            
    testButton.setHeight(40);
            
    testButton.setIcon("sm_00.gif");
            
    //testButton.setCursor(Cursor.HAND_CURSOR); 
    => Siehe Anhang!

    Klasse:
    PHP-Code:
    package tools.objects;

    import java.awt.Cursor;

    /**
     * Button Class for Knoedels.
     * http://creativecommons.org/licenses/by/3.0/
     * @author Mentos
     */
    public class KButton {

        private 
    String text;
        private 
    String command;
        private 
    String textColor//255,255,255
        
    private String disabledTextColor//255,255,255
        
    private String iconPath//sm_classic_yellow.gif
        
    private String images//button-blue~hoverbutton-blue~button-blue.mx_1.my_1<
        
    private String color//200,200,200
        
    private boolean enabled;
        private 
    boolean visible;
        private 
    boolean textBorder;
        private 
    boolean border;
        private 
    int width;
        private 
    int height;
        private 
    int textXPosition;
        private 
    int textYPosition;
        private 
    int disabledTimeout;
        private 
    int cursor;

        public 
    KButton(String textString command) {
            if(
    isNullOrEmpty(command)){
                
    command "/"//Sonst haut ihr eure Popups kaputt!
            
    }
            
    this.text text;
            
    this.command command;
            
    this.width = -1;
            
    this.height = -1;
            
    this.textXPosition = -1;
            
    this.textYPosition = -1;
            
    this.disabledTimeout = -1;
            
    this.visible true;
            
    this.enabled true;
            
    this.border true;
            
    this.cursor Cursor.DEFAULT_CURSOR;
        }

        
    /*GETTER*/
        
    public String getText() {
            return 
    text;
        }

        public 
    String getCommand() {
            return 
    command;
        }

        public 
    String getTextColor() {
            return 
    textColor;
        }

        public 
    String getDisabledTextColor() {
            return 
    disabledTextColor;
        }

        public 
    String getIconPath() {
            return 
    iconPath;
        }

        public 
    String getImages() {
            return 
    images;
        }

        public 
    String getColor() {
            return 
    color;
        }

        public 
    boolean isEnabled() {
            return 
    enabled;
        }

        public 
    boolean isVisible() {
            return 
    visible;
        }

        public 
    boolean hasTextBorder() {
            return 
    textBorder;
        }

        public 
    boolean hasBorder() {
            return 
    border;
        }

        public 
    int getWidth() {
            return 
    width;
        }

        public 
    int getHeight() {
            return 
    height;
        }

        public 
    int getTextXPosition() {
            return 
    textXPosition;
        }

        public 
    int getTextYPosition() {
            return 
    textYPosition;
        }

        public 
    int getDisabledTimeout() {
            return 
    disabledTimeout;
        }

        public 
    int getCursor() {
            return 
    cursor;
        }

        
    /*SETTER*/
        
    public void setEnabled(boolean enabled) {
            
    this.enabled enabled;
        }

        public 
    void setVisible(boolean visible) {
            
    this.visible visible;
        }

        public 
    void setTextBorder(boolean textBorder) {
            
    this.textBorder textBorder;
        }

        public 
    void setTextColor(String textColor) {
            
    this.textColor textColor;
        }

        public 
    void setDisabledTextColor(String disabledTextColor) {
            
    this.disabledTextColor disabledTextColor;
        }

        public 
    void setWidth(int width) {
            
    this.width width;
        }

        public 
    void setHeight(int height) {
            
    this.height height;
        }

        public 
    void setTextY(int yPosition) {
            
    this.textYPosition yPosition;
        }

        public 
    void setTextX(int xPosition) {
            
    this.textXPosition xPosition;
        }

        public 
    void setIcon(String iconPath) {
            
    this.iconPath iconPath;
        }

        public 
    void setImages(String image1String image2String image3) {
            
    this.images String.format("%s~%s~%s"image1image2image3);
            if (
    images.length() == 2) {
                
    images ""//Wenn nichts angegeben wird!
            
    }
        }

        public 
    void setColor(String color1String color2String color3) {
            
    this.color String.format("%s~%s~%s"color1color2color3);
            if (
    color.length() == 2) {
                
    color ""//Wenn nichts angegeben wird!
            
    }
        }

        public 
    void setBorder(boolean border) {
            
    this.border border;
        }

        public 
    void setDisabledTimeout(int disabledTimeout) {
            
    this.disabledTimeout disabledTimeout;
        }

        public 
    void setCursor(int cursor) {
            
    this.cursor cursor;
        }

        
    /*MAIN-FUNCTION*/
        
    @Override
        
    public String toString() {
            
    StringBuilder buttonBuilder = new StringBuilder();
            
    buttonBuilder.append("°>{button} ").append(text).append("||call|_r\\").append(command);

            if (!
    visible) {
                
    buttonBuilder.append("|visible|0");
            }
            if (!
    enabled) {
                
    buttonBuilder.append("|enabled|0");
            }
            if (!
    border) {
                
    buttonBuilder.append("|noborder|1");
            }
            if (
    textBorder) {
                
    buttonBuilder.append("|textborder|1");
            }


            if (!
    isNullOrEmpty(textColor)) {
                
    buttonBuilder.append("|textcolor|").append(textColor);
            }
            if (!
    isNullOrEmpty(disabledTextColor)) {
                
    buttonBuilder.append("|disabledtextcolor|").append(disabledTextColor);
            }
            if (!
    isNullOrEmpty(iconPath)) {
                
    buttonBuilder.append("|icon|").append(iconPath);
            }
            if (!
    isNullOrEmpty(images)) {
                
    buttonBuilder.append("|images|").append(images);
            }

            if (
    width != -1) {
                
    buttonBuilder.append("|width|").append(width);
            }
            if (
    height != -1) {
                
    buttonBuilder.append("|height|").append(height);
            }
            if (
    textXPosition != -1) {
                
    buttonBuilder.append("|tx|").append(textXPosition);
            }
            if (
    textYPosition != -1) {
                
    buttonBuilder.append("|ty|").append(textYPosition);
            }
            if (
    disabledTimeout != -1) {
                
    buttonBuilder.append("|disabledTimeout|").append(disabledTimeout);
            }

            if (
    cursor != Cursor.DEFAULT_CURSOR) {
                
    buttonBuilder.append("|cursor|").append(cursor);
            }

            
    buttonBuilder.append("<°");
            return 
    buttonBuilder.toString();

        }

        private 
    boolean isNullOrEmpty(String str) {
            return (
    str == null || str.isEmpty());
        }

        
    //Debugging only :)
        
    public static String createButton(String textString commandint widthint height) {
            
    KButton button = new KButton(textcommand);
            
    button.setWidth(width);
            
    button.setHeight(height);
            return 
    button.toString();
        }

    Hab Getter/Setter verwendet.
    Wenn ihr einen Wert wieder deaktivieren wollt einfach für int -1 einsetzen und fürn String halt null
    MfG
    Danke auch an PaT, der es geschafft hat, die Debugging-Funktion zu erstellen!
    Geändert von Mentos (04.04.2012 um 18:03 Uhr)
    „Es sind nicht unsere Fähigkeiten, die zeigen, wer wir wirklich sind, es sind unsere Entscheidungen.“
    - Albus Dumbledore, Harry Potter 2


    /guestchat registerGuest

Ähnliche Themen

  1. Antworten: 8
    Letzter Beitrag: 02.12.2013, 23:41
  2. Java EE 32 Bit?
    Von Pwned im Forum Java
    Antworten: 2
    Letzter Beitrag: 04.08.2012, 23:08
  3. Ubuntu Sun Java
    Von hYpercrites im Forum Linux
    Antworten: 3
    Letzter Beitrag: 20.06.2012, 15:17
  4. [SCR] KButton - Knuddels Button Control
    Von Devon im Forum Sourcecode
    Antworten: 4
    Letzter Beitrag: 02.03.2012, 00:43
  5. KButton
    Von DeKaDeNz im Forum Sourcecode
    Antworten: 0
    Letzter Beitrag: 07.02.2012, 21:57
Diese Seite nutzt Cookies, um das Nutzererlebnis zu verbessern. Klicken Sie hier, um das Cookie-Tracking zu deaktivieren.