Java Code Examples for com.alee.laf.label.WebLabel#CENTER

The following examples show how to use com.alee.laf.label.WebLabel#CENTER . 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: WebDocumentPaneExample.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns single tab content {@link JComponent}.
 *
 * @return single tab content {@link JComponent}
 */
@NotNull
protected JComponent createTabContent ()
{
    final WebStyledLabel content = new WebStyledLabel (
            DemoStyles.placeholderLabel,
            getExampleLanguageKey ( "data.content" ),
            WebLabel.CENTER
    );
    content.setFocusable ( true );
    content.addMouseListener ( new MouseAdapter ()
    {
        @Override
        public void mousePressed ( final MouseEvent e )
        {
            content.requestFocusInWindow ();
        }
    } );
    return content;
}
 
Example 2
Source File: GroupPaneExample.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
@NotNull
@Override
protected List<? extends JComponent> createPreviewElements ()
{
    // First row
    final WebComboBox e1 = new WebComboBox ( new String[]{ "First", "Second", "Third" } );
    final WebButton e2 = new WebButton ( "Second" );
    final WebTextField e3 = new WebTextField ( "Third" );

    // Second row
    final WebPanel e4 = new WebPanel ( StyleId.panelDecorated, new WebLabel ( "First", WebLabel.CENTER ) );
    final WebTextField e5 = new WebTextField ( "Second" );
    final WebButton e6 = new WebButton ( "Third" );

    // Third row
    final WebSpinner e7 = new WebSpinner ( new SpinnerNumberModel ( 100, 0, 100, 1 ) );
    final WebButton e8 = new WebButton ( "Second" );
    final WebPasswordField e9 = new WebPasswordField ( "Third" );

    final GroupPane groupPane = new GroupPane ( getStyleId (), 3, 3, e1, e2, e3, e4, e5, e6, e7, e8, e9 );
    SwingUtils.equalizeComponentsWidth ( groupPane.getComponents () );
    return CollectionUtils.asList ( groupPane );
}
 
Example 3
Source File: TabbedPaneTooltipExample.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns single tab content {@link JComponent}.
 *
 * @return single tab content {@link JComponent}
 */
@NotNull
protected JComponent createTabContent ()
{
    final WebStyledLabel content = new WebStyledLabel (
            DemoStyles.placeholderLabel,
            getExampleLanguageKey ( "data.content" ),
            WebLabel.CENTER
    );
    content.setFocusable ( true );
    content.addMouseListener ( new MouseAdapter ()
    {
        @Override
        public void mousePressed ( final MouseEvent e )
        {
            content.requestFocusInWindow ();
        }
    } );
    return content;
}
 
Example 4
Source File: JTabbedPaneExample.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns single tab content {@link JComponent}.
 *
 * @return single tab content {@link JComponent}
 */
@NotNull
protected JComponent createTabContent ()
{
    final WebStyledLabel content = new WebStyledLabel (
            DemoStyles.placeholderLabel,
            getExampleLanguageKey ( "data.content" ),
            WebLabel.CENTER
    );
    content.setFocusable ( true );
    content.addMouseListener ( new MouseAdapter ()
    {
        @Override
        public void mousePressed ( final MouseEvent e )
        {
            content.requestFocusInWindow ();
        }
    } );
    return content;
}
 
Example 5
Source File: NotesTabPanel.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public void initializeUI() {
	uiDone = true;
	
	// Initialize location header.
	WebPanel titlePane = new WebPanel(new FlowLayout(FlowLayout.CENTER));
	topContentPanel.add(titlePane);

	WebLabel titleLabel = new WebLabel(Msg.getString("NotesTabPanel.title"), WebLabel.CENTER); //$NON-NLS-1$
	titleLabel.setFont(new Font("Serif", Font.BOLD, 16));
	// titleLabel.setForeground(new Color(102, 51, 0)); // dark brown
	titlePane.add(titleLabel);
	
	// Create notes panel
	WebPanel notesPanel = new WebPanel(new BorderLayout(5, 5));
	notesPanel.setBorder(new MarsPanelBorder());
	notesPanel.setBorder(new EmptyBorder(1, 1, 1, 1));
	centerContentPanel.add(notesPanel);
	
	notesCache = unit.getNotes();
	
	textArea = new WebTextArea(StyleId.textareaDecorated);
	notesPanel.add(textArea);
	
	if (notesCache == null || notesCache.equals(""))
		textArea.setInputPrompt("Enter Here");
	else {
		textArea.append(notesCache);
	}

}
 
Example 6
Source File: TabPanelMaintenance.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
		 * Constructor.
		 * 
		 * @param malfunction the malfunction for the panel.
		 * @param building    the building the malfunction is in.
		 */
		public BuildingMalfunctionPanel(Malfunction malfunction, Building building) {
			// Use WebPanel constructor
			super();

			// Initialize data members
			this.malfunction = malfunction;

			// Set layout and border.
			setLayout(new GridLayout(5, 1, 0, 0));
//			setBorder(new MarsPanelBorder());

			// Prepare the building label.
			WebLabel buildingLabel = new WebLabel(building.getNickName(), WebLabel.LEFT);
			buildingLabel.setFont(new Font("Serif", Font.BOLD, 14));
			add(buildingLabel);

			// Prepare the malfunction label.
			malfunctionLabel = new WebLabel(malfunction.getName(), WebLabel.LEFT);
			malfunctionLabel.setForeground(Color.red);
			add(malfunctionLabel);

			workLabel = new WebLabel("", WebLabel.LEFT);
//			workLabel.setFont(new Font("Serif", Font.ITALIC, 12));
//			workLabel.setForeground(Color.LIGHT_GRAY);
//			workLabel.setBackground(Color.DARK_GRAY);
			add(workLabel);
			
			// Progress bar panel.
			WebPanel progressBarPanel = new WebPanel(new BorderLayout(0, 0));
			add(progressBarPanel, BorderLayout.CENTER);

			// Prepare progress bar.
			JProgressBar progressBar = new JProgressBar();
			progressBarModel = progressBar.getModel();
			progressBar.setStringPainted(true);
			progressBarPanel.add(progressBar, BorderLayout.CENTER);

			// Set initial value for repair progress bar.
			progressBarModel.setValue(0);

			// Prepare parts label.
			partsLabel = new WebLabel(getPartsString(malfunction.getRepairParts(), false), WebLabel.CENTER);
			partsLabel.setPreferredSize(new Dimension(-1, -1));
			add(partsLabel);

			// Add tooltip.
//			setToolTipText(getToolTipString());
			TooltipManager.setTooltip(this, getToolTipString(), TooltipWay.up);
			
			update();
		}
 
Example 7
Source File: NavigatorWindow.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
	 * Pops out a small panel for showing additional info
	 * 
	 * @param landmark
	 * @param event
	 */
	public void startPopOver(Landmark landmark, int x, int y, MouseEvent event) {
//		final WebPopup<?> popup = new WebPopup(desktop.getMainWindow().getMainPane());
//        popup.setPadding(5);
//        popup.setResizable(false);
//        popup.setDraggable(true);
//
//        final WebPanel container = new WebPanel(StyleId.panelTransparent, new BorderLayout(5, 5));
//
//        final WebLabel label = new WebLabel(landmark.getLandmarkLandingLocation(), WebLabel.CENTER);
//        container.add(label, BorderLayout.NORTH);
//
////        final String text = LM.get ( getExampleLanguagePrefix () + "text" );
////        final WebTextField field = new WebTextField ( text, 20 );
////        field.setHorizontalAlignment ( WebTextField.CENTER );
////        container.add ( field, BorderLayout.CENTER );
//
//        popup.add(container);
//
////        popup.pack();
//        popup.showPopup(event.getComponent(), x + 5, y + 5);
        
         final WebPopOver popOver = new WebPopOver(desktop.getMainWindow().getMainPane());
//         popOver.setIconImages ();
         popOver.setCloseOnFocusLoss(true);
         popOver.setPadding(2);
         popOver.setTitle(landmark.getLandmarkName());
         
         final WebPanel c = new WebPanel(StyleId.panelTransparent, new BorderLayout(5,5));

         final WebLabel l = new WebLabel(landmark.getLandmarkLandingLocation(), WebLabel.CENTER);
         c.add(l, BorderLayout.NORTH);

//         final String text = LM.get ( getExampleLanguagePrefix () + "text" );
//         final WebTextField field = new WebTextField ( text, 20 );
//         field.setHorizontalAlignment ( WebTextField.CENTER );
//         container.add ( field, BorderLayout.CENTER );

         popOver.add(c);
         popOver.show(event.getComponent(), x + 5, y + 5, PopOverDirection.down);
	}
 
Example 8
Source File: MalfunctionPanel.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
	 * Constructs a MalfunctionPanel object with a name prefix.
	 * @param malfunction the malfunction to display
	 */
	public MalfunctionPanel(Malfunction malfunction) {

		// Call JPanel constructor.
		super();

		// Initialize data members.
		this.malfunction = malfunction;

		// Set layout
		setLayout(new GridLayout(3, 1, 0, 0));

		// Set border
		setBorder(new MarsPanelBorder());
		setOpaque(false);
		setBackground(new Color(0,0,0,128));

		// Prepare name label.
		nameLabel = new WebLabel(malfunction.getName(), WebLabel.CENTER);
		if (!malfunction.isEmergencyRepairDone()) {
			nameLabel.setText(malfunction.getName() + " - Emergency");
			nameLabel.setForeground(Color.red);
		}
		add(nameLabel);

		// Prepare repair pane.
		WebPanel repairPane = new WebPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
		add(repairPane);

		// Prepare repair progress bar.
		WebProgressBar repairBar = new WebProgressBar();
		repairBarModel = repairBar.getModel();
		repairBar.setStringPainted(true);
		repairPane.add(repairBar);

		// Set initial value for repair progress bar.
//		double totalRequiredWork = malfunction.getEmergencyWorkTime() + malfunction.getGeneralWorkTime()
//				+ malfunction.getEVAWorkTime();
//		double totalCompletedWork = malfunction.getCompletedEmergencyWorkTime() +
//				malfunction.getCompletedGeneralWorkTime() + malfunction.getCompletedEVAWorkTime();
//		int percentComplete = 0;
//		if (totalRequiredWork > 0D) percentComplete = (int) (100D * (totalCompletedWork / totalRequiredWork));
		repairBarModel.setValue((int)malfunction.getPercentageFixed());

		// Prepare repair parts label.
		partsLabel = new WebLabel(getPartsString(), WebLabel.CENTER);
		partsLabel.setPreferredSize(new Dimension(-1, -1));
		add(partsLabel);

		// Add tooltip.
		setToolTipText(getToolTipString());
	}
 
Example 9
Source File: BuildingPanelResourceProcessing.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
	 * Constructor.
	 * @param processor the resource processing building this panel is for.
	 * @param desktop The main desktop.
	 */
	public BuildingPanelResourceProcessing(ResourceProcessing processor, MainDesktopPane desktop) {

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

		// Initialize variables.
		this.processor = processor;

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

		// Prepare resource processes label
		// 2014-11-21 Changed font type, size and color and label text
		// 2014-11-21 Added internationalization for labels
		WebLabel resourceProcessesLabel = new WebLabel(Msg.getString("BuildingPanelResourceProcessing.title"), WebLabel.CENTER);
		resourceProcessesLabel.setFont(new Font("Serif", Font.BOLD, 16));
		//resourceProcessesLabel.setForeground(new Color(102, 51, 0)); // dark brown
		add(resourceProcessesLabel, BorderLayout.NORTH);

		WebLabel supportedProcessesLabel = new WebLabel(Msg.getString("BuildingPanelResourceProcessing.supportedProcesses"), WebLabel.CENTER);
		add(supportedProcessesLabel, BorderLayout.CENTER);

		// Get all processes at building.
		List<ResourceProcess> processes = processor.getProcesses();
		int size = processes.size();
		// Prepare resource processes list panel.
//		WebPanel resourceProcessesListPanel = new WebPanel(new GridLayout(processes.size(), 2, 10, 3));
//		resourceProcessesListPanel.setBorder(new EmptyBorder(3, 20, 3, 20)); //(int top, int left, int bottom, int right)
		//resourceProcessesListPanel.setOpaque(false);
		//resourceProcessesListPanel.setBackground(new Color(0,0,0,128));

		WebTextArea processesTA = new WebTextArea();
		processesTA.setEditable(false);
		processesTA.setFont(new Font("SansSerif", Font.ITALIC, 12));
		processesTA.setColumns(12);

		// For each specialty, add specialty name panel.
		for (ResourceProcess p : processes) {
			processesTA.append(" " + p.getProcessName()+ " ");
			if (!p.equals(processes.get(size-1)))
				//if it's NOT the last one
				processesTA.append("\n");
			
//			if (p.isProcessRunning()) {
//				processLabel.setIcon(greenDot);
//				processLabel.setToolTipText(p.getProcessName() + " process is running.");
//			}
//			else {
//				processLabel.setIcon(redDot);
//				processLabel.setToolTipText(p.getProcessName() + " process is not running.");
//			}
			
		}

		WebPanel listPanel = new WebPanel(new FlowLayout(FlowLayout.CENTER));
		listPanel.add(processesTA);
		processesTA.setBorder(new MarsPanelBorder());
//		resourceProcessesListPanel.setBorder(new MarsPanelBorder());
//		listPanel.add(resourceProcessesListPanel);
		add(listPanel, BorderLayout.SOUTH);
		//listPanel.setOpaque(false);
		//listPanel.setBackground(new Color(0,0,0,128));

		// Load green and red dots.
//		greenDot = new ImageIcon("images/GreenDot.png", "Process is running.");
//		redDot = new ImageIcon("images/RedDot.png", "Process is not running");

		// For each resource process, add a label.
//		processLabels = new ArrayList<WebLabel>(processes.size());
//		Iterator<ResourceProcess> i = processes.iterator();
//		while (i.hasNext()) {
//			ResourceProcess process = i.next();
//			WebLabel processLabel = new WebLabel(process.getProcessName(), WebLabel.LEFT);
//			//processLabel.setForeground(Color.DARK_GRAY);
//			//processLabel.setBackground(Color.WHITE);
//			processLabel.setFont(new Font("SansSerif", Font.ITALIC, 12));
//
//			if (process.isProcessRunning()) {
//				processLabel.setIcon(greenDot);
//				processLabel.setToolTipText(process.getProcessName() + " process is running.");
//			}
//			else {
//				processLabel.setIcon(redDot);
//				processLabel.setToolTipText(process.getProcessName() + " process is not running.");
//			}
//
////			resourceProcessesListPanel.add(processLabel);
//			processLabels.add(processLabel);
//		}
	}
 
Example 10
Source File: TabPanelMaintenance.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
		 * Constructor.
		 * 
		 * @param building the building to display.
		 */
		public BuildingMaintenancePanel(Building building) {
			// User WebPanel constructor.
			super();

			manager = building.getMalfunctionManager();

			setLayout(new GridLayout(4, 1, 0, 0));
//			setBorder(new MarsPanelBorder());

			WebLabel buildingLabel = new WebLabel(building.getNickName(), WebLabel.LEFT);
			buildingLabel.setFont(new Font("Serif", Font.BOLD, 14));
			add(buildingLabel);

			// Add wear condition cache and label.
			wearConditionCache = (int) Math.round(manager.getWearCondition());
			wearConditionLabel = new WebLabel(
					Msg.getString("BuildingPanelMaintenance.wearCondition", wearConditionCache),
					WebLabel.CENTER);
			TooltipManager.setTooltip(wearConditionLabel, 
					Msg.getString("BuildingPanelMaintenance.wear.toolTip"),
					TooltipWay.down);
			// wearConditionLabel.setMargin (4);
//			add(wearConditionLabel);

			WebPanel mainPanel = new WebPanel(new BorderLayout(0, 0));
			add(mainPanel);

			lastCompletedCache = (int) (manager.getTimeSinceLastMaintenance() / 1000D);
			lastLabel = new WebLabel("Last completed : " + lastCompletedCache + " sols ago", WebLabel.LEFT);
			mainPanel.add(lastLabel, BorderLayout.WEST);
			// lastLabel.setToolTipText(getToolTipString());
			TooltipManager.setTooltip(lastLabel, getToolTipString(), TooltipWay.down);

			// Prepare progress bar panel.
			WebPanel progressBarPanel = new WebPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
//			mainPanel.add(progressBarPanel, BorderLayout.CENTER);
			add(progressBarPanel);
			
			mainPanel.add(wearConditionLabel, BorderLayout.CENTER);
			
			// Prepare progress bar.
			JProgressBar progressBar = new JProgressBar();
			progressBarModel = progressBar.getModel();
			progressBar.setStringPainted(true);
			progressBar.setPreferredSize(new Dimension(240, 15));
			progressBarPanel.add(progressBar);

			// Set initial value for progress bar.
			double completed = manager.getMaintenanceWorkTimeCompleted();
			double total = manager.getMaintenanceWorkTime();
			int percentDone = (int) (100D * (completed / total));
			progressBarModel.setValue(percentDone);

			// Prepare parts label.
			Map<Integer, Integer> parts = manager.getMaintenanceParts();
			partsLabel = new WebLabel(getPartsString(parts, false), WebLabel.CENTER);
			partsLabel.setPreferredSize(new Dimension(-1, -1));
			add(partsLabel);

			TooltipManager.setTooltip(partsLabel, getPartsString(parts, false), TooltipWay.down);
		}
 
Example 11
Source File: TabPanelCrew.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
public void initializeUI() {
		uiDone = true;
		
		// Prepare title label.
		WebPanel titlePanel = new WebPanel(new FlowLayout(FlowLayout.CENTER));
		WebLabel titleLabel = new WebLabel(Msg.getString("TabPanelCrew.title"), WebLabel.CENTER); //$NON-NLS-1$
		titleLabel.setFont(new Font("Serif", Font.BOLD, 16));
		titlePanel.add(titleLabel);
		topContentPanel.add(titlePanel);

		// Create crew count panel
		WebPanel crewCountPanel = new WebPanel(new GridLayout(2, 1, 0, 0));
//		crewCountPanel.setBorder(new MarsPanelBorder());
		topContentPanel.add(crewCountPanel);

		// Create crew num label
		crewNumCache = crewable.getCrewNum();
		crewNumLabel = new WebLabel(Msg.getString("TabPanelCrew.crew", crewNumCache), WebLabel.CENTER); //$NON-NLS-1$
		crewCountPanel.add(crewNumLabel);

		// Create crew capacity label
		crewCapacityCache = crewable.getCrewCapacity();
		crewCapLabel = new WebLabel(Msg.getString("TabPanelCrew.crewCapacity", crewCapacityCache), WebLabel.CENTER); //$NON-NLS-1$
		crewCountPanel.add(crewCapLabel);

		// Create crew display panel
		WebPanel crewDisplayPanel = new WebPanel(new FlowLayout(FlowLayout.LEFT));
//		crewDisplayPanel.setBorder(new MarsPanelBorder());
		topContentPanel.add(crewDisplayPanel);

		// Create scroll panel for crew list.
		WebScrollPane crewScrollPanel = new WebScrollPane();
		crewScrollPanel.setPreferredSize(new Dimension(175, 200));
		crewDisplayPanel.add(crewScrollPanel);

		// Create crew list model
		crewListModel = new DefaultListModel<Person>();
		//crewListModel = new DefaultListModel<Unit>();
		crewCache = crewable.getCrew();
		//crewCache = crewable.getUnitCrew();
		Iterator<Person> i = crewCache.iterator();
		//Iterator<Unit> i = crewCache.iterator();
		while (i.hasNext()) crewListModel.addElement(i.next());

		// Create crew list
		crewList = new JList<Person>(crewListModel);
		//crewList = new JList<Unit>(crewListModel);
		crewList.addMouseListener(this);
		crewScrollPanel.setViewportView(crewList);

		// Create crew monitor button
		WebButton monitorButton = new WebButton(ImageLoader.getIcon(Msg.getString("img.monitor"))); //$NON-NLS-1$
		monitorButton.setMargin(new Insets(1, 1, 1, 1));
		monitorButton.addActionListener(this);
		monitorButton.setToolTipText(Msg.getString("TabPanelCrew.tooltip.monitor")); //$NON-NLS-1$
		crewDisplayPanel.add(monitorButton);
	}
 
Example 12
Source File: BuildingPanelVehicleMaintenance.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructor.
 * @param garage the vehicle maintenance function
 * @param desktop the main desktop
 */
public BuildingPanelVehicleMaintenance(VehicleMaintenance garage, MainDesktopPane desktop) {

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

	// Initialize data members
	this.garage = garage;

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

	// Create label panel
	WebPanel labelPanel = new WebPanel(new GridLayout(3, 1, 0, 0));
	add(labelPanel, BorderLayout.NORTH);
	labelPanel.setOpaque(false);
	labelPanel.setBackground(new Color(0,0,0,128));
	
	// Create vehicle maintenance label
	// 2014-11-21 Changed font type, size and color and label text
	// 2014-11-21 Added internationalization for labels
	WebLabel vehicleMaintenanceLabel = new WebLabel(Msg.getString("BuildingPanelVehicleMaintenance.title"), WebLabel.CENTER);
	vehicleMaintenanceLabel.setFont(new Font("Serif", Font.BOLD, 16));
	//vehicleMaintenanceLabel.setForeground(new Color(102, 51, 0)); // dark brown
	labelPanel.add(vehicleMaintenanceLabel);

	// Create vehicle number label
	vehicleNumberCache = garage.getCurrentVehicleNumber();
	vehicleNumberLabel = new WebLabel(Msg.getString("BuildingPanelVehicleMaintenance.numberOfVehicles",
			vehicleNumberCache), WebLabel.CENTER);
	labelPanel.add(vehicleNumberLabel);

	// Create vehicle capacity label
	int vehicleCapacity = garage.getVehicleCapacity();
	WebLabel vehicleCapacityLabel = new WebLabel(Msg.getString("BuildingPanelVehicleMaintenance.vehicleCapacity",
			vehicleCapacity), WebLabel.CENTER);
	labelPanel.add(vehicleCapacityLabel);	

	// Create vehicle list panel
	WebPanel vehicleListPanel = new WebPanel(new FlowLayout(FlowLayout.CENTER));
	add(vehicleListPanel, BorderLayout.CENTER);
	vehicleListPanel.setOpaque(false);
	vehicleListPanel.setBackground(new Color(0,0,0,128));
	
	// Create scroll panel for vehicle list
	WebScrollPane vehicleScrollPanel = new WebScrollPane();
	vehicleScrollPanel.setPreferredSize(new Dimension(160, 60));
	vehicleListPanel.add(vehicleScrollPanel);
	vehicleScrollPanel.setOpaque(false);
	vehicleScrollPanel.setBackground(new Color(0,0,0,128));
	vehicleScrollPanel.getViewport().setOpaque(false);
	vehicleScrollPanel.getViewport().setBackground(new Color(0,0,0,128));
	
	// Create vehicle list model
	vehicleListModel = new DefaultListModel<Vehicle>();
	vehicleCache = new ArrayList<Vehicle>(garage.getVehicles());
	Iterator<Vehicle> i = vehicleCache.iterator();
	while (i.hasNext()) vehicleListModel.addElement(i.next());

	// Create vehicle list
	vehicleList = new JList<Vehicle>(vehicleListModel);
	vehicleList.addMouseListener(this);
	vehicleScrollPanel.setViewportView(vehicleList);
}
 
Example 13
Source File: TabPanelGoods.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
public void initializeUI() {
		uiDone = true;
		
		// Prepare goods label panel.
		WebPanel goodsLabelPanel = new WebPanel(new FlowLayout(FlowLayout.CENTER));
		topContentPanel.add(goodsLabelPanel);

		// Prepare goods label.
		WebLabel titleLabel = new WebLabel(Msg.getString("TabPanelGoods.label"), WebLabel.CENTER); //$NON-NLS-1$
		titleLabel.setFont(new Font("Serif", Font.BOLD, 16));
		//titleLabel.setForeground(new Color(102, 51, 0)); // dark brown
		goodsLabelPanel.add(titleLabel);

		// Create scroll panel for the outer table panel.
		WebScrollPane goodsScrollPane = new WebScrollPane();
		goodsScrollPane.setPreferredSize(new Dimension(250, 300));
		// increase vertical mousewheel scrolling speed for this one
		goodsScrollPane.getVerticalScrollBar().setUnitIncrement(16);
		centerContentPanel.add(goodsScrollPane);

		// Prepare goods table model.
		goodsTableModel = new GoodsTableModel(((Settlement) unit).getGoodsManager());

		// Prepare goods table.
		goodsTable = new ZebraJTable(goodsTableModel);
		goodsScrollPane.setViewportView(goodsTable);
		goodsTable.setRowSelectionAllowed(true);
		
		// Override default cell renderer for formatting double values.
		goodsTable.setDefaultRenderer(Double.class, new NumberCellRenderer(2, true));
		
		goodsTable.getColumnModel().getColumn(0).setPreferredWidth(140);
		goodsTable.getColumnModel().getColumn(1).setPreferredWidth(80);
		
		// Added the two methods below to make all heatTable columns
		// Resizable automatically when its Panel resizes
		goodsTable.setPreferredScrollableViewportSize(new Dimension(225, -1));
		//goodsTable.setAutoResizeMode(WebTable.AUTO_RESIZE_ALL_COLUMNS);

		// Align the preference score to the center of the cell
		DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
		renderer.setHorizontalAlignment(SwingConstants.RIGHT);
		goodsTable.getColumnModel().getColumn(0).setCellRenderer(renderer);
//		goodsTable.getColumnModel().getColumn(1).setCellRenderer(renderer);

		// Added sorting
		goodsTable.setAutoCreateRowSorter(true);

		TableStyle.setTableStyle(goodsTable);

     	// Added goodsSearchable
     	TableSearchable searchable = SearchableUtils.installSearchable(goodsTable);
        searchable.setPopupTimeout(5000);
     	searchable.setCaseSensitive(false);
        searchable.setMainIndex(0); // -1 = search for all columns

	}
 
Example 14
Source File: TabPanelAttribute.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
public void initializeUI() {
		uiDone = true;

		// Create attribute label panel.
		WebPanel attributeLabelPanel = new WebPanel(new FlowLayout(FlowLayout.CENTER));
		topContentPanel.add(attributeLabelPanel);

		// Create attribute label
		WebLabel attributeLabel = new WebLabel(Msg.getString("TabPanelAttribute.label"), WebLabel.CENTER); //$NON-NLS-1$
		attributeLabel.setFont(new Font("Serif", Font.BOLD, 16));
		attributeLabelPanel.add(attributeLabel);

		// Create attribute scroll panel
		WebScrollPane attributeScrollPanel = new WebScrollPane();
//		attributeScrollPanel.setBorder(new MarsPanelBorder());
		centerContentPanel.add(attributeScrollPanel);

		// Create attribute table model
		if (person != null)
			attributeTableModel = new AttributeTableModel(person);
		else
			attributeTableModel = new AttributeTableModel(robot);
		
		// Create attribute table
		attributeTable = new ZebraJTable(attributeTableModel); //new JTable(attributeTableModel);//
		attributeTable.setPreferredScrollableViewportSize(new Dimension(225, 100));
		attributeTable.getColumnModel().getColumn(0).setPreferredWidth(100);
		attributeTable.getColumnModel().getColumn(1).setPreferredWidth(70);
		attributeTable.setRowSelectionAllowed(true);
//		attributeTable.setDefaultRenderer(Integer.class, new NumberCellRenderer());
		
		attributeScrollPanel.setViewportView(attributeTable);

		attributeTable.setAutoCreateRowSorter(true);
 
		// Align the content to the center of the cell
        // Note: DefaultTableCellRenderer does NOT work well with nimrod
		DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
		renderer.setHorizontalAlignment(SwingConstants.LEFT);
		attributeTable.getColumnModel().getColumn(0).setCellRenderer(renderer);
		attributeTable.getColumnModel().getColumn(1).setCellRenderer(renderer);

        TableStyle.setTableStyle(attributeTable);
        update();
        
        //attributeTableModel.update();
	}
 
Example 15
Source File: BuildingPanelStorage.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructor.
 * @param storage the storage building function.
 * @param desktop the main desktop.
 */
public BuildingPanelStorage(Storage storage, MainDesktopPane desktop) {

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

	setLayout(new BorderLayout(0, 0));

	// Create storage label.
	WebLabel storageLabel = new WebLabel(Msg.getString("BuildingPanelStorage.title"), WebLabel.CENTER);
	storageLabel.setFont(new Font("Serif", Font.BOLD, 16));
	//storageLabel.setForeground(new Color(102, 51, 0)); // dark brown

	WebPanel titlePanel = new WebPanel(new GridLayout(2,1,0,0));
	add(titlePanel, BorderLayout.NORTH);
	titlePanel.add(storageLabel);
	titlePanel.setOpaque(false);
	titlePanel.setBackground(new Color(0,0,0,128));

	WebLabel maxCapLabel = new WebLabel(Msg.getString("BuildingPanelStorage.maxCap"), WebLabel.CENTER);
	titlePanel.add(maxCapLabel);

	Map<Integer, Double> resourceStorage = storage.getResourceStorageCapacity();

	// Create resource storage panel.
	WebPanel resourceStoragePanel = new WebPanel(new GridLayout(resourceStorage.size(), 2, 0, 0));
	add(resourceStoragePanel, BorderLayout.CENTER);
	resourceStoragePanel.setOpaque(false);
	resourceStoragePanel.setBackground(new Color(0,0,0,128));

	SortedSet<Integer> keys = new TreeSet<Integer>(resourceStorage.keySet());
	for (Integer resource : keys) { 
		// Create resource label.
		WebLabel resourceLabel = new WebLabel(
				Conversion.capitalize(ResourceUtil.findAmountResourceName(resource)) 
				+ ":", WebLabel.LEFT);
		resourceStoragePanel.add(resourceLabel);

		double capacity = resourceStorage.get(resource);
		WebLabel capacityLabel = new WebLabel((int) capacity + " kg", WebLabel.RIGHT);
		resourceStoragePanel.add(capacityLabel);
	}
}
 
Example 16
Source File: BuildingPanelThermal.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructor.
 * @param The panel for the Heating System
 * @param The main desktop
 */
//2014-10-28 mkung: Modified the structure of the constructor 
public BuildingPanelThermal(ThermalGeneration furnace, MainDesktopPane desktop) {
	super(furnace.getBuilding(), desktop);
	// Use BuildingFunctionPanel constructor
	//super(building, desktop);
	
	this.furnace = furnace;
	this.building = furnace.getBuilding();
	
	furnace = building.getThermalGeneration();//(ThermalGeneration) building.getFunction(BuildingFunction.THERMAL_GENERATION);	
		
	// Check if the building is a heat producer.
	hasFurnace = building.hasFunction(FunctionType.THERMAL_GENERATION);

	// If heat producer, prepare heat producer label.
	if (hasFurnace) {
		 setLayout(new GridLayout(3, 1, 0, 0));
		
		// 2014-11-21 Changed font type, size and color and label text
		WebLabel titleLabel = new WebLabel(
				Msg.getString("BuildingPanelThermal.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);
		
		// Prepare heat status label.
		heatStatusCache = building.getHeatMode();
		heatStatusLabel = new WebLabel(
			Msg.getString("BuildingPanelThermal.heatStatus", heatStatusCache.getName()), //$NON-NLS-1$
			WebLabel.CENTER
		);
		add(heatStatusLabel);	
			
		productionCache = furnace.getGeneratedHeat();		
		productionLabel = new WebLabel(	
			Msg.getString("BuildingPanelThermal.heatProduced", formatter.format(productionCache)), //$NON-NLS-1$
			WebLabel.CENTER
		);
		add(productionLabel);
	}
}
 
Example 17
Source File: BuildingPanelAstronomicalObservation.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
	 * Constructor.
	 * @param observatory the astronomical observatory building function.
	 * @param desktop the main desktop.
	 */
	public BuildingPanelAstronomicalObservation(AstronomicalObservation observatory, 
			MainDesktopPane desktop) {
		// User BuildingFunctionPanel constructor.
		super(observatory.getBuilding(), desktop);

		function = observatory;
		currentObserversAmount = function.getObserverNum();

		// Set panel layout
		setLayout(new BorderLayout());
		
		// Prepare label panelAstronomicalObservation
		WebPanel labelPanel = new WebPanel(new GridLayout(5, 1, 0, 0));
		add(labelPanel, BorderLayout.NORTH);

		// Astronomy top label
		// 2014-11-21 Changed font type, size and color and label text
		WebLabel astronomyLabel = new WebLabel(Msg.getString("BuildingPanelAstronomicalObservation.title"), WebLabel.CENTER); //$NON-NLS-1$
		astronomyLabel.setFont(new Font("Serif", Font.BOLD, 16));
		//astronomyLabel.setForeground(new Color(102, 51, 0)); // dark brown
		labelPanel.add(astronomyLabel);

		// Observer number label
		// 2014-11-21 Fixed currentObserversAmount
		observersLabel = new WebLabel(Msg.getString("BuildingPanelAstronomicalObservation.numberOfObservers", currentObserversAmount), WebLabel.CENTER); //$NON-NLS-1$
		observersLabel.setHorizontalAlignment(WebLabel.CENTER);
		update();
		labelPanel.add(observersLabel);

		// Observer capacityLabel
		WebLabel observerCapacityLabel = new WebLabel(
			Msg.getString(
				"BuildingPanelAstronomicalObservation.observerCapacity", //$NON-NLS-1$
				function.getObservatoryCapacity()
			),WebLabel.CENTER
		);
		labelPanel.add(observerCapacityLabel);
		
		labelPanel.setOpaque(false);
		labelPanel.setBackground(new Color(0,0,0,128));
		astronomyLabel.setOpaque(false);
		astronomyLabel.setBackground(new Color(0,0,0,128));
		observersLabel.setOpaque(false);
		observersLabel.setBackground(new Color(0,0,0,128));
		
      	// Create the button panel.
		WebPanel buttonPane = new WebPanel(new FlowLayout(FlowLayout.CENTER));
		
		// Create the orbit viewer button.
		WebButton button = new WebButton("Orbit Viewer");
		
		//balloonToolTip.createBalloonTip(button, "Click to open the solar system orbit viewer"); 
		//button.setToolTipText("Click to open the solar system orbit viewer");
		button.addActionListener(
			new ActionListener() {
				public void actionPerformed(ActionEvent e) {
//					openOrbitViewer();
				}
			});
		buttonPane.add(button);
		labelPanel.add(buttonPane);
	}
 
Example 18
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
	}
 
Example 19
Source File: TabPanelSocial.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
public void initializeUI() {
		uiDone = true;
		// Create relationship label panel.
		WebPanel relationshipLabelPanel = new WebPanel(new FlowLayout(FlowLayout.CENTER));
		topContentPanel.add(relationshipLabelPanel);

		// Create relationship label
		WebLabel relationshipLabel = new WebLabel(Msg.getString("TabPanelSocial.label"), WebLabel.CENTER); //$NON-NLS-1$
		relationshipLabel.setFont(new Font("Serif", Font.BOLD, 16));
		relationshipLabelPanel.add(relationshipLabel);

		// Create relationship scroll panel
		WebScrollPane relationshipScrollPanel = new WebScrollPane();
//		relationshipScrollPanel.setBorder(new MarsPanelBorder());
		centerContentPanel.add(relationshipScrollPanel);

		// Create relationship table model
		relationshipTableModel = new RelationshipTableModel(person);

		// Create relationship table
		relationshipTable = new ZebraJTable(relationshipTableModel);
		relationshipTable.setPreferredScrollableViewportSize(new Dimension(225, 100));
		relationshipTable.getColumnModel().getColumn(0).setPreferredWidth(80);
		relationshipTable.getColumnModel().getColumn(1).setPreferredWidth(80);
		relationshipTable.getColumnModel().getColumn(2).setPreferredWidth(40);
		relationshipTable.setRowSelectionAllowed(true);
		
		// For single clicking on a person to pop up his person window.
		//relationshipTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);	
		//relationshipTable.getSelectionModel().addListSelectionListener(this); 

		// Add a mouse listener to hear for double-clicking a person (rather than single click using valueChanged()
		relationshipTable.addMouseListener(new MouseAdapter() {
		    public void mousePressed(MouseEvent me) {
		    	JTable table =(JTable) me.getSource();
		        Point p = me.getPoint();
		        int row = table.rowAtPoint(p);
		        int col = table.columnAtPoint(p);
		        if (me.getClickCount() == 2) {
		            if (row > 0 && col > 0) {
		    			Person selectedPerson = (Person) relationshipTable.getValueAt(row, 1);  			
		    			if (selectedPerson != null) desktop.openUnitWindow(selectedPerson, false);
		    	    }
		        }
		    }
		});
		
		relationshipScrollPanel.setViewportView(relationshipTable);

		// Align the content to the center of the cell
		DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
		renderer.setHorizontalAlignment(SwingConstants.RIGHT);
		relationshipTable.getColumnModel().getColumn(0).setCellRenderer(renderer);
		relationshipTable.getColumnModel().getColumn(1).setCellRenderer(renderer);
		relationshipTable.getColumnModel().getColumn(2).setCellRenderer(renderer);
		
		// Added sorting
		relationshipTable.setAutoCreateRowSorter(true); // in conflict with valueChanged(), throw exception if clicking on a person

		TableStyle.setTableStyle(relationshipTable);
	}
 
Example 20
Source File: TabPanelCredit.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
public void initializeUI() {
		uiDone = true;
		
		// Prepare credit label panel.
		WebPanel creditLabelPanel = new WebPanel(new FlowLayout(FlowLayout.CENTER));
		topContentPanel.add(creditLabelPanel);

		// Prepare credit label.
		WebLabel creditLabel = new WebLabel(Msg.getString("TabPanelCredit.label"), WebLabel.CENTER); //$NON-NLS-1$
		creditLabel.setFont(new Font("Serif", Font.BOLD, 16));
		//creditLabel.setForeground(new Color(102, 51, 0)); // dark brown
		creditLabelPanel.add(creditLabel);

		// Create scroll panel for the outer table panel.
		WebScrollPane creditScrollPanel = new WebScrollPane();
		creditScrollPanel.setPreferredSize(new Dimension(280, 280));
		centerContentPanel.add(creditScrollPanel);

		// Prepare credit table model.
		CreditTableModel creditTableModel = new CreditTableModel((Settlement) unit);

		// Prepare credit table.
		creditTable = new ZebraJTable(creditTableModel);
		creditScrollPanel.setViewportView(creditTable);
		creditTable.setRowSelectionAllowed(true);
		
		creditTable.setDefaultRenderer(Double.class, new NumberCellRenderer(2, true));
		
		creditTable.getColumnModel().getColumn(0).setPreferredWidth(100);
		creditTable.getColumnModel().getColumn(1).setPreferredWidth(120);
		creditTable.getColumnModel().getColumn(2).setPreferredWidth(50);
		
		// Added the two methods below to make all heatTable columns
		// Resizable automatically when its Panel resizes
		creditTable.setPreferredScrollableViewportSize(new Dimension(225, -1));
		//creditTable.setAutoResizeMode(WebTable.AUTO_RESIZE_ALL_COLUMNS);
		// Added sorting
		creditTable.setAutoCreateRowSorter(true);

		// Align the preference score to the center of the cell
		DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
		renderer.setHorizontalAlignment(SwingConstants.RIGHT);
		creditTable.getColumnModel().getColumn(0).setCellRenderer(renderer);
//		creditTable.getColumnModel().getColumn(1).setCellRenderer(renderer);
		creditTable.getColumnModel().getColumn(2).setCellRenderer(renderer);
		
		TableStyle.setTableStyle(creditTable);

	}