<commit_before>/*
*
* Copyright 2008,2009 Newcastle University
*
* This file is part of Workcraft.
*
* Workcraft 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.
*
* Workcraft 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 Workcraft.  If not, see <http://www.gnu.org/licenses/>.
*
*/

package org.workcraft.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;

import org.workcraft.Framework;
import org.workcraft.exceptions.NotSupportedException;
import org.workcraft.exceptions.OperationCancelledException;
import org.workcraft.gui.actions.Action;
import org.workcraft.gui.actions.ActionButton;
import org.workcraft.gui.actions.ScriptedActionListener;

@SuppressWarnings("serial")
public class DockableWindowContentPanel extends JPanel {

	static public class ViewAction extends Action {
		public static final int CLOSE_ACTION = 1;
		public static final int MINIMIZE_ACTION = 2;
		public static final int MAXIMIZE_ACTION = 3;

		private int windowID;
		private int actionType;

		public ViewAction (int windowID, int actionType) {
			this.actionType = actionType;
			this.windowID = windowID;
		}

		public String getText() {
			return null;
		}

		@Override
		public void run() {
			switch (actionType) {
			case CLOSE_ACTION:
				try {
					final Framework framework = Framework.getInstance();
					framework.getMainWindow().closeDockableWindow(windowID);
					} catch (OperationCancelledException e) {

					}
				break;
			case MAXIMIZE_ACTION:
				final Framework framework = Framework.getInstance();
				framework.getMainWindow().toggleDockableWindowMaximized(windowID);
				break;
			case MINIMIZE_ACTION:
				throw new NotSupportedException();
			}
		}
	}

	class DockableViewHeader extends JPanel {
		private ActionButton btnMin, btnMax, btnClose;
		private JLabel titleLabel = null;
		private JPanel buttonPanel = null;
		private boolean maximized = false;

		private ActionButton createHeaderButton(Icon icon, Action action, ScriptedActionListener actionListener) {
			ActionButton button = new ActionButton(action);
			button.addScriptedActionListener(actionListener);
			button.setPreferredSize(new Dimension(icon.getIconWidth(),icon.getIconHeight()));
			button.setFocusable(false);
			button.setBorder(null);
			button.setIcon(icon);
			return button;
		}

		public DockableViewHeader(String title, int options) {
			super();
			setLayout(new BorderLayout());

			Color c;
			if (UIManager.getLookAndFeel().getName().contains("Substance")) {
				c = getBackground();
				c = new Color( (int)(c.getRed() * 0.9), (int)(c.getGreen() * 0.9), (int)(c.getBlue() * 0.9) );
			} else {
				c = UIManager.getColor("InternalFrame.activeTitleBackground");
			}
			setBackground(c);

			if  (options != 0) {
				buttonPanel = new JPanel();
				buttonPanel.setBackground(c);
				buttonPanel.setLayout(new FlowLayout(FlowLayout.TRAILING, 4,2));
				buttonPanel.setFocusable(false);
				add(buttonPanel, BorderLayout.EAST);
			}

			int icons = 0;
			if ( (options & MINIMIZE_BUTTON) != 0) {
				btnMin = createHeaderButton(UIManager.getIcon("InternalFrame.minimizeIcon"),
						new ViewAction(id, ViewAction.MINIMIZE_ACTION), mainWindow.getDefaultActionListener());
				btnMin.setToolTipText("Toggle minimized");
				buttonPanel.add(btnMin);
				icons ++;
			}

			if ( (options & MAXIMIZE_BUTTON) != 0) {
				btnMax = createHeaderButton(UIManager.getIcon("InternalFrame.maximizeIcon"),
						new ViewAction(id, ViewAction.MAXIMIZE_ACTION), mainWindow.getDefaultActionListener());
				buttonPanel.add(btnMax);
				icons ++;
			}

			if ( (options & CLOSE_BUTTON) != 0) {
				//System.out.println (UIManager.getColor("InternalFrame.activeTitleGradient"));
				btnClose = createHeaderButton(UIManager.getIcon("InternalFrame.closeIcon"),
						new ViewAction(id, ViewAction.CLOSE_ACTION), mainWindow.getDefaultActionListener());
				btnClose.setToolTipText("Close window");
				buttonPanel.add(btnClose);
				icons ++;
			}

			if (icons != 0) {
				buttonPanel.setPreferredSize(new Dimension((UIManager.getIcon("InternalFrame.closeIcon").getIconWidth()+4) * icons,UIManager.getIcon("InternalFrame.closeIcon").getIconHeight()+4));
			}

			titleLabel = new JLabel(title);
			titleLabel.setOpaque(false);
			titleLabel.setForeground(UIManager.getColor("InternalFrame.activeTitleForeground"));
			titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD));
			add(titleLabel, BorderLayout.WEST);

			setMaximized(false);
		}

		public boolean isMaximized() {
			return maximized;
		}

		public void setMaximized(boolean maximized) {
			this.maximized = maximized;

			if (btnMax != null)<commit_msg>Empty border in DockableWindow title.<commit_after>/*
*
* Copyright 2008,2009 Newcastle University
*
* This file is part of Workcraft.
*
* Workcraft 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.
*
* Workcraft 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 Workcraft.  If not, see <http://www.gnu.org/licenses/>.
*
*/

package org.workcraft.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.border.Border;

import org.workcraft.Framework;
import org.workcraft.exceptions.NotSupportedException;
import org.workcraft.exceptions.OperationCancelledException;
import org.workcraft.gui.actions.Action;
import org.workcraft.gui.actions.ActionButton;
import org.workcraft.gui.actions.ScriptedActionListener;

@SuppressWarnings("serial")
public class DockableWindowContentPanel extends JPanel {

	static public class ViewAction extends Action {
		public static final int CLOSE_ACTION = 1;
		public static final int MINIMIZE_ACTION = 2;
		public static final int MAXIMIZE_ACTION = 3;

		private int windowID;
		private int actionType;

		public ViewAction (int windowID, int actionType) {
			this.actionType = actionType;
			this.windowID = windowID;
		}

		public String getText() {
			return null;
		}

		@Override
		public void run() {
			switch (actionType) {
			case CLOSE_ACTION:
				try {
					final Framework framework = Framework.getInstance();
					framework.getMainWindow().closeDockableWindow(windowID);
					} catch (OperationCancelledException e) {

					}
				break;
			case MAXIMIZE_ACTION:
				final Framework framework = Framework.getInstance();
				framework.getMainWindow().toggleDockableWindowMaximized(windowID);
				break;
			case MINIMIZE_ACTION:
				throw new NotSupportedException();
			}
		}
	}

	class DockableViewHeader extends JPanel {
		private final Border BORDER_TITLE = BorderFactory.createEmptyBorder(1, 3, 1, 1);
		private ActionButton btnMin, btnMax, btnClose;
		private JLabel titleLabel = null;
		private JPanel buttonPanel = null;
		private boolean maximized = false;

		private ActionButton createHeaderButton(Icon icon, Action action, ScriptedActionListener actionListener) {
			ActionButton button = new ActionButton(action);
			button.addScriptedActionListener(actionListener);
			button.setPreferredSize(new Dimension(icon.getIconWidth(),icon.getIconHeight()));
			button.setFocusable(false);
			button.setBorder(null);
			button.setIcon(icon);
			return button;
		}

		public DockableViewHeader(String title, int options) {
			super();
			setLayout(new BorderLayout());

			Color c;
			if (UIManager.getLookAndFeel().getName().contains("Substance")) {
				c = getBackground();
				c = new Color( (int)(c.getRed() * 0.9), (int)(c.getGreen() * 0.9), (int)(c.getBlue() * 0.9) );
			} else {
				c = UIManager.getColor("InternalFrame.activeTitleBackground");
			}
			setBackground(c);

			if  (options != 0) {
				buttonPanel = new JPanel();
				buttonPanel.setBackground(c);
				buttonPanel.setLayout(new FlowLayout(FlowLayout.TRAILING, 4,2));
				buttonPanel.setFocusable(false);
				add(buttonPanel, BorderLayout.EAST);
			}

			int icons = 0;
			if ( (options & MINIMIZE_BUTTON) != 0) {
				btnMin = createHeaderButton(UIManager.getIcon("InternalFrame.minimizeIcon"),
						new ViewAction(id, ViewAction.MINIMIZE_ACTION), mainWindow.getDefaultActionListener());
				btnMin.setToolTipText("Toggle minimized");
				buttonPanel.add(btnMin);
				icons ++;
			}

			if ( (options & MAXIMIZE_BUTTON) != 0) {
				btnMax = createHeaderButton(UIManager.getIcon("InternalFrame.maximizeIcon"),
						new ViewAction(id, ViewAction.MAXIMIZE_ACTION), mainWindow.getDefaultActionListener());
				buttonPanel.add(btnMax);
				icons ++;
			}

			if ( (options & CLOSE_BUTTON) != 0) {
				//System.out.println (UIManager.getColor("InternalFrame.activeTitleGradient"));
				btnClose = createHeaderButton(UIManager.getIcon("InternalFrame.closeIcon"),
						new ViewAction(id, ViewAction.CLOSE_ACTION), mainWindow.getDefaultActionListener());
				btnClose.setToolTipText("Close window");
				buttonPanel.add(btnClose);
				icons ++;
			}

			if (icons != 0) {
				buttonPanel.setPreferredSize(new Dimension((UIManager.getIcon("InternalFrame.closeIcon").getIconWidth()+4) * icons,UIManager.getIcon("InternalFrame.closeIcon").getIconHeight()+4));
			}

			titleLabel = new JLabel(title);
			titleLabel.setOpaque(false);
			titleLabel.setForeground(UIManager.getColor("InternalFrame.activeTitleForeground"));
			titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD));
			titleLabel.setBorder(BORDER_TITLE);
			add(titleLabel, BorderLayout.WEST);

			setMaximized(false);
		}

		public boolean isMaximized() {
			return maximized;
		}

		public void setMaximized(boolean maximized) {
			this.maximized = maximized;

			if (btnMax != null)
{'fraction_non_alphanumeric': 0.10757968865826538, 'fraction_numerical': 0.005559673832468495, 'mean_word_length': 4.569143446852425, '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': '6744033', 'n_tokens_mistral': 3750, 'n_tokens_neox': 3223, 'n_words': 774}