Java Code Examples for com.alee.laf.text.WebTextField#setColumns()

The following examples show how to use com.alee.laf.text.WebTextField#setColumns() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BuildingPanelPowerStorage.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructor.
 * @param storage The power storage building function.
 * @param desktop The main desktop.
 */
public BuildingPanelPowerStorage(PowerStorage storage, MainDesktopPane desktop) {

	// Use BuildingFunctionPanel constructor
	super(storage.getBuilding(), desktop);

	this.storage = storage;

	// Set the layout
	setLayout(new BorderLayout());

	// 2014-11-21 Changed font type, size and color and label text
	WebLabel titleLabel = new WebLabel(
			Msg.getString("BuildingPanelPowerStorage.title"), //$NON-NLS-1$
			WebLabel.CENTER);		
	titleLabel.setFont(new Font("Serif", Font.BOLD, 16));
	//titleLabel.setForeground(new Color(102, 51, 0)); // dark brown
	add(titleLabel, BorderLayout.NORTH);
	
	WebPanel springPanel = new WebPanel(new SpringLayout());
	add(springPanel, BorderLayout.CENTER);
	
	// Create capacity label.
	capacityCache = Math.round(storage.getCurrentMaxCapacity() *10.0)/10.0;;
	capacityLabel = new WebLabel(
			Msg.getString("BuildingPanelPowerStorage.cap"), //$NON-NLS-1$
			WebLabel.CENTER);		
	springPanel.add(capacityLabel);
	
	WebPanel wrapper1 = new WebPanel(new FlowLayout(0, 0, FlowLayout.LEADING));
	capTF = new WebTextField(formatter.format(capacityCache) + kWh);
	capTF.setEditable(false);
	capTF.setColumns(7);
	capTF.setPreferredSize(new Dimension(120, 25));
	wrapper1.add(capTF);
	springPanel.add(wrapper1);
	
	// Create stored label.
	storedCache = Math.round(storage.getkWattHourStored() *10.0)/10.0;;
	storedLabel = new WebLabel(
			Msg.getString("BuildingPanelPowerStorage.stored"), //$NON-NLS-1$
			WebLabel.CENTER);
	springPanel.add(storedLabel);
	
	WebPanel wrapper2 = new WebPanel(new FlowLayout(0, 0, FlowLayout.LEADING));
	storedTF = new WebTextField(storedCache + kWh);
	storedTF.setEditable(false);
	storedTF.setColumns(7);
	storedTF.setPreferredSize(new Dimension(120, 25));
	wrapper2.add(storedTF);
	springPanel.add(wrapper2);
	
	SpringUtilities.makeCompactGrid(springPanel,
               2, 2, 			//rows, cols
               75, 10,        //initX, initY
               3, 1);       //xPad, yPad
}
 
Example 2
Source File: BuildingPanelPower.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructor.
 * @param building the building the panel is for.
 * @param desktop The main desktop.
 */
public BuildingPanelPower(Building building, MainDesktopPane desktop) {

	// Use BuildingFunctionPanel constructor
	super(building, desktop);

	// Check if the building is a power producer.
	isProducer = building.hasFunction(FunctionType.POWER_GENERATION);
	generator = building.getPowerGeneration();
	
	// Set the layout
	setLayout(new BorderLayout());

	// 2014-11-21 Changed font type, size and color and label text
	WebLabel titleLabel = new WebLabel(
			Msg.getString("BuildingPanelPower.title"), //$NON-NLS-1$
			WebLabel.CENTER);		
	titleLabel.setFont(new Font("Serif", Font.BOLD, 16));
	//titleLabel.setForeground(new Color(102, 51, 0)); // dark brown
	add(titleLabel, BorderLayout.NORTH);
	
	WebPanel springPanel = new WebPanel(new SpringLayout());
	add(springPanel, BorderLayout.CENTER);
	
	// Prepare power status label.
	powerStatusCache = building.getPowerMode();
	powerStatusLabel = new WebLabel(
			Msg.getString("BuildingPanelPower.powerStatus"), //$NON-NLS-1$
			WebLabel.RIGHT);
	springPanel.add(powerStatusLabel);
	
	WebPanel wrapper1 = new WebPanel(new FlowLayout(0, 0, FlowLayout.LEADING));
	statusTF = new WebTextField(powerStatusCache.getName());
	statusTF.setEditable(false);
	statusTF.setColumns(7);
	statusTF.setPreferredSize(new Dimension(120, 25));
	wrapper1.add(statusTF);
	springPanel.add(wrapper1);

	// If power producer, prepare power producer label.
	if (isProducer) {
		//PowerGeneration generator = building.getPowerGeneration();//(PowerGeneration) building.getFunction(FunctionType.POWER_GENERATION);
		powerCache = generator.getGeneratedPower();
		powerLabel = new WebLabel(
			Msg.getString("BuildingPanelPower.powerProduced"), //$NON-NLS-1$
			WebLabel.RIGHT);
		
		springPanel.add(powerLabel);
		
		WebPanel wrapper2 = new WebPanel(new FlowLayout(0, 0, FlowLayout.LEADING));
		producedTF = new WebTextField(formatter.format(powerCache) + kW);
		producedTF.setEditable(false);
		producedTF.setColumns(7);
		producedTF.setPreferredSize(new Dimension(120, 25));
		wrapper2.add(producedTF);
		springPanel.add(wrapper2);
	}

	// Prepare power used label.
	if (powerStatusCache == PowerMode.FULL_POWER) 
		usedCache = building.getFullPowerRequired();
	else if (powerStatusCache == PowerMode.POWER_DOWN) 
		usedCache = building.getPoweredDownPowerRequired();
	else usedCache = 0D;
	
	usedLabel = new WebLabel(
		Msg.getString("BuildingPanelPower.powerUsed"), //$NON-NLS-1$
		WebLabel.RIGHT
	);
	
	springPanel.add(usedLabel);
	
	WebPanel wrapper3 = new WebPanel(new FlowLayout(0, 0, FlowLayout.LEADING));
	usedTF = new WebTextField(formatter.format(usedCache) + kW);
	usedTF.setEditable(false);
	usedTF.setColumns(7);
	usedTF.setPreferredSize(new Dimension(120, 25));
	wrapper3.add(usedTF);
	springPanel.add(wrapper3);
	
	//Lay out the spring panel.
	if (isProducer) {
		SpringUtilities.makeCompactGrid(springPanel,
	                                3, 2, //rows, cols
	                                75, 10,        //initX, initY
	                                3, 1);       //xPad, yPad
	}
	else
		SpringUtilities.makeCompactGrid(springPanel,
                   2, 2, //rows, cols
                   75, 10,        //initX, initY
                   3, 1);       //xPad, yPad
	}