<commit_before>/*******************************************************************************
 * Copyright (C) 2013 Mentor Graphics
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     <NAME> - initial API and implementation
 *******************************************************************************/
package com.mentor.swt.experiments;

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.TextLayout;
import org.eclipse.swt.layout.*;

/* In SWT, a label with SWT.WRAP flag will still report full unwrapped width as size hint.
 * Therefore, putting wrapping label with long text inside a dialog can make it unreasonably
 * wide. It is possible to set a hardcoded size for the dialog, but it's better solved at
 * the level of label, which is what this test code tries to implement.
 * 
 * Another SWT deficiency is that shell.pack just sets the size to initial 
 * 
 * */
public class SwtLabelWrapping {
	
	// Different ways to compute label size hint
	enum LabelHint { 
		DEFAULT_HINT,  // Use default SWT implementation 
		REDUCED_WIDTH, // Return width of 1 
		PROPORTIONAL   // Try to make rectangle of reasonable proportions 
	};
	static LabelHint labelHint = LabelHint.REDUCED_WIDTH;
	
	// For PROPORTIONAL mode, use heuristic from Qt library.
	static boolean USE_QT_HEURISTIC = true;
	
	// If true, do a second iteration of packing, with width set.
	static boolean DOUBLE_PACK = true;
	
	
	public static final class WrappingLabel extends Label {
		private WrappingLabel(Composite parent, int style) {
			super(parent, style);
		}

		@Override
		public Point computeSize(int wHint, int hHint, boolean changed) {
			
			Point p = super.computeSize(wHint, hHint, changed);
			
			if (labelHint == LabelHint.DEFAULT_HINT) {
				// Do nothing.				<commit_msg>Use proportial Qt layout by default.<commit_after>/*******************************************************************************
 * Copyright (C) 2013 Mentor Graphics
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     <NAME> - initial API and implementation
 *******************************************************************************/
package com.mentor.swt.experiments;

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.graphics.TextLayout;
import org.eclipse.swt.layout.*;

/* In SWT, a label with SWT.WRAP flag will still report full unwrapped width as size hint.
 * Therefore, putting wrapping label with long text inside a dialog can make it unreasonably
 * wide. It is possible to set a hardcoded size for the dialog, but it's better solved at
 * the level of label, which is what this test code tries to implement.
 * 
 * Another SWT deficiency is that shell.pack just sets the size to initial 
 * 
 * */
public class SwtLabelWrapping {
	
	// Different ways to compute label size hint
	enum LabelHint { 
		DEFAULT_HINT,  // Use default SWT implementation 
		REDUCED_WIDTH, // Return width of 1 
		PROPORTIONAL   // Try to make rectangle of reasonable proportions 
	};
	static LabelHint labelHint = LabelHint.PROPORTIONAL;
	
	// For PROPORTIONAL mode, use heuristic from Qt library.
	static boolean USE_QT_HEURISTIC = true;
	
	// If true, do a second iteration of packing, with width set.
	static boolean DOUBLE_PACK = true;
	
	
	public static final class WrappingLabel extends Label {
		private WrappingLabel(Composite parent, int style) {
			super(parent, style);
		}

		@Override
		public Point computeSize(int wHint, int hHint, boolean changed) {
			
			Point p = super.computeSize(wHint, hHint, changed);
			
			if (labelHint == LabelHint.DEFAULT_HINT) {
				// Do nothing.				
{'fraction_non_alphanumeric': 0.1445755787562415, 'fraction_numerical': 0.0040853381752156154, 'mean_word_length': 4.094797687861272, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3866432', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1162, 'n_words': 457}