All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jwebmp.plugins.google.sourceprettify.JQSourceCodePrettify Maven / Gradle / Ivy

There is a newer version: 1.2.2.1-jre17
Show newest version
/*
 * Copyright (C) 2017 GedMarc
 *
 * 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 .
 */
package com.jwebmp.plugins.google.sourceprettify;

import com.jwebmp.core.base.html.PreFormattedText;
import com.jwebmp.core.base.html.interfaces.GlobalChildren;
import com.jwebmp.core.plugins.ComponentInformation;

import javax.validation.constraints.NotNull;

/**
 * Implements the Google Code Prettify JavaScript
 *
 * @param 
 *
 * @author MMagon
 * @version 1.0
 * @since 2014 09 28
 */
@ComponentInformation(name = "google-code-prettify ",
		description = "An embeddable script that makes source-code snippets in HTML prettier.",
		url = "https://code.google.com/archive/p/google-code-prettify")
public class JQSourceCodePrettify>
		extends PreFormattedText
		implements GlobalChildren
{
	@SuppressWarnings("FieldCanBeLocal")
	private final JQSourceCodePrettifyFeature feature = new JQSourceCodePrettifyFeature(this);
	private SourceCodeLanguages sourceCodeLanguage = SourceCodeLanguages.Java;
	private SourceCodePrettifyThemes sourceCodePrettifyTheme = SourceCodePrettifyThemes.Default;

	private boolean showLineNums;

	/**
	 * Constructs a new Source Code Prettify
	 */
	public JQSourceCodePrettify()
	{
		addFeature(feature);
	}

	/**
	 * Constructs the HTML required for prettify to work
	 *
	 * @return
	 */
	@Override
	protected StringBuilder renderBeforeTag()
	{
		StringBuilder sb = new StringBuilder();
		sb.append(getCurrentTabIndentString())
		  .append("");
		sb.append(getNewLine());
		return sb;
	}

	/**
	 * Gets the source code language in use
	 *
	 * @return
	 */
	public SourceCodeLanguages getSourceCodeLanguage()
	{
		return sourceCodeLanguage;
	}

	/**
	 * Sets the language programming for
	 *
	 * @param sourceCodeLanguage
	 */
	@SuppressWarnings("unchecked")
	@NotNull
	public J setSourceCodeLanguage(SourceCodeLanguages sourceCodeLanguage)
	{
		this.sourceCodeLanguage = sourceCodeLanguage;
		return (J) this;
	}

	/**
	 * If line numbers must be shown
	 *
	 * @return
	 */
	public boolean isShowLineNums()
	{
		return showLineNums;
	}

	/**
	 * Showing the line numbers
	 *
	 * @param showLineNums
	 *
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public J setShowLineNums(boolean showLineNums)
	{
		this.showLineNums = showLineNums;
		return (J) this;
	}

	/**
	 * Returns the current theme in place. Default is Sons of Obsidion
	 *
	 * @return
	 */
	public SourceCodePrettifyThemes getSourceCodePrettifyTheme()
	{
		return sourceCodePrettifyTheme;
	}

	/**
	 * Sets the displaying theme that this feature will use
	 *
	 * @param theme
	 * 		The theme to use
	 */
	@SuppressWarnings("unchecked")
	@NotNull
	public final J setTheme(SourceCodePrettifyThemes theme)
	{
		sourceCodePrettifyTheme = theme;
		if (sourceCodePrettifyTheme != null)
		{
			addCssReference(theme.getCssReference());
		}
		return (J) this;
	}

	@Override
	public int hashCode()
	{
		return super.hashCode();
	}

	@Override
	public boolean equals(Object o)
	{
		return super.equals(o);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy