<commit_before>/*
 * Copyright 2000,2005 wingS development team.
 *
 * This file is part of wingS (http://wingsframework.org).
 *
 * wingS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1
 * of the License, or (at your option) any later version.
 *
 * Please see COPYING for the complete licence.
 */
package org.wings.plaf.css;


import org.wings.*;
import org.wings.io.Device;
import org.wings.plaf.css.script.OnPageRenderedScript;
import org.wings.session.ScriptManager;

import java.io.IOException;

public class DialogCG extends WindowCG implements org.wings.plaf.DialogCG {

    public void writeInternal(Device device, SComponent component) throws IOException {

        SDialog dialog = (SDialog) component;
        SRootContainer owner = dialog.getOwner();

        String name = dialog.getName();

        device.print("\n\n" +
                "<div id=\"" + name + "\">\n" +
                "  <div class=\"hd\">" + (dialog.getTitle() != null ? dialog.getTitle() : "&#160;") + "</div>\n" +
                "  <div class=\"bd\">");

        super.writeInternal(device, dialog);

        device.print("  </div>\n" +
                "</div>\n");

        StringBuilder sb = new StringBuilder();
        sb.append("dialog_").append(name).append(" = new wingS.dialog.SDialog(\"").append(name).append("\"")
                .append(", {");

        if (dialog.getX() > -1 && dialog.getY() > -1) {
        	sb.append("x:").append(dialog.getX()).append(",")
        	  .append("y:").append(dialog.getY()).append(",");
        }
        else {
        	sb.append("fixedcenter:true").append(",");
        }

        if (!(owner instanceof SFrame))
            sb.append("viewportelement:\"").append(owner.getName()).append("\",");

        if (dialog.getPreferredSize() != null) {
            sb.append("height:").append(dialog.getPreferredSize().getHeight()).append(",")
              .append("width:").append(dialog.getPreferredSize().getWidth()).append(",");<commit_msg>o fixed dimension problems with SDialog<commit_after>/*
 * Copyright 2000,2005 wingS development team.
 *
 * This file is part of wingS (http://wingsframework.org).
 *
 * wingS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1
 * of the License, or (at your option) any later version.
 *
 * Please see COPYING for the complete licence.
 */
package org.wings.plaf.css;


import org.wings.*;
import org.wings.io.Device;
import org.wings.plaf.css.script.OnPageRenderedScript;
import org.wings.session.ScriptManager;

import java.io.IOException;

public class DialogCG extends WindowCG implements org.wings.plaf.DialogCG {

    public void writeInternal(Device device, SComponent component) throws IOException {

        SDialog dialog = (SDialog) component;
        SRootContainer owner = dialog.getOwner();

        String name = dialog.getName();

        device.print("\n\n" +
                "<div id=\"" + name + "\">\n" +
                "  <div class=\"hd\">" + (dialog.getTitle() != null ? dialog.getTitle() : "&#160;") + "</div>\n" +
                "  <div class=\"bd sdf\">");
        
        SDimension outerDim = dialog.getPreferredSize();
        if (outerDim != null) {
            int outerHeight = outerDim.getHeightInt();
            String outerHeightUnit = outerDim.getHeightUnit();
            if (outerHeightUnit != null &&
                outerHeightUnit.equalsIgnoreCase("px") &&
                outerHeight != SDimension.AUTO_INT) {
                // The magic number 48 is hardcoded here which is obviously not good and should
                // be changed in the future. This must probably be done via JS since we need to
                // read out the width and height set via CSS. For the moment the calculation is
                // done like this: 48 px = 2 x 10px [padding] + 26px [header] + 2 x 1px [border]
                SDimension innerDim = new SDimension(outerDim.getWidthInt(), outerHeight - 48);
                dialog.setPreferredSize(innerDim);
            }
        }

        super.writeInternal(device, dialog);
        
        // Reset the actual dimension
        dialog.setPreferredSize(outerDim);

        device.print("  </div>\n" +
                "</div>\n");

        StringBuilder sb = new StringBuilder();
        sb.append("dialog_").append(name).append(" = new wingS.dialog.SDialog(\"").append(name).append("\"")
                .append(", {");

        if (dialog.getX() > -1 && dialog.getY() > -1) {
        	sb.append("x:").append(dialog.getX()).append(",")
        	  .append("y:").append(dialog.getY()).append(",");
        }
        else {
        	sb.append("fixedcenter:true").append(",");
        }

        if (!(owner instanceof SFrame))
            sb.append("viewportelement:\"").append(owner.getName()).append("\",");

        if (outerDim != null) {
            String width = outerDim.getWidth();
            if (width != SDimension.AUTO) {
                sb.append("width:\"").append(width).append("\",");
            }
            String height = outerDim.getHeight();
            if (height != SDimension.AUTO) {
                sb.append("height:\"").append(height).append("\",");
            }
{'fraction_non_alphanumeric': 0.15049797122832903, 'fraction_numerical': 0.007930652895610476, 'mean_word_length': 2.357894736842105, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2266747', 'n_tokens_mistral': 1566, 'n_tokens_neox': 1501, 'n_words': 395}