001    /*
002     * Copyright (C) 2008 Adam Cornett This program is free software; you can
003     * redistribute it and/or modify it under the terms of the GNU General Public
004     * License as published by the Free Software Foundation; either version 3 of the
005     * License, or (at your option) any later version. This program is distributed
006     * in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
007     * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
008     * See the GNU General Public License for more details. You should have received
009     * a copy of the GNU General Public License along with this program; if not, see
010     * <http://www.gnu.org/licenses>.
011     */
012    
013    package net.codescore.ui.components.parts;
014    
015    import org.zkforge.codepress.Codepress;
016    
017    import net.codescore.dbo.Language;
018    import net.codescore.dbo.Submission;
019    
020    public class SourceBox extends Codepress {
021            private static final long serialVersionUID = 5723491914385545964L;
022    
023            private static String getCodePresLang(final Language l) {
024                    String lang = "text";
025                    final String l1 = l.getName();
026                    if (l1.equals("Java"))
027                            lang = "java";
028                    else if (l1.equals("C or C++"))
029                            lang = "java";
030                    return lang;
031            }
032    
033            public SourceBox() {
034                    setAutocomplete(false);
035                    setLinenumbers(true);
036                    setValue("\n\n\n");
037                    setStyle("width:100%; height:150px");
038            }
039    
040            public SourceBox(final String source, final Language lang) {
041                    setAutocomplete(false);
042                    setLanguage(SourceBox.getCodePresLang(lang));
043                    setReadonly(true);
044                    setValue(source);
045                    setLinenumbers(true);
046                    setStyle("width:100%; height:150px");
047            }
048    
049            public SourceBox(final String source, final String lang) {
050                    setAutocomplete(false);
051                    setLanguage(lang);
052                    setReadonly(true);
053                    setValue(source);
054                    setLinenumbers(true);
055                    setStyle("width:100%; height:150px");
056            }
057    
058            public SourceBox(final Submission s) {
059                    this(s.getSource(), s.getLanguage());
060            }
061    }