001/*
002 * This file is part of McIDAS-V
003 *
004 * Copyright 2007-2024
005 * Space Science and Engineering Center (SSEC)
006 * University of Wisconsin - Madison
007 * 1225 W. Dayton Street, Madison, WI 53706, USA
008 * https://www.ssec.wisc.edu/mcidas/
009 * 
010 * All Rights Reserved
011 * 
012 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
013 * some McIDAS-V source code is based on IDV and VisAD source code.  
014 * 
015 * McIDAS-V is free software; you can redistribute it and/or modify
016 * it under the terms of the GNU Lesser Public License as published by
017 * the Free Software Foundation; either version 3 of the License, or
018 * (at your option) any later version.
019 * 
020 * McIDAS-V is distributed in the hope that it will be useful,
021 * but WITHOUT ANY WARRANTY; without even the implied warranty of
022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
023 * GNU Lesser Public License for more details.
024 * 
025 * You should have received a copy of the GNU Lesser Public License
026 * along with this program.  If not, see https://www.gnu.org/licenses/.
027 */
028package edu.wisc.ssec.mcidasv.monitors.memory;
029
030import static javax.swing.GroupLayout.Alignment.LEADING;
031
032import javax.swing.GroupLayout;
033import javax.swing.JLabel;
034import javax.swing.JPanel;
035
036import edu.wisc.ssec.mcidasv.monitors.MonitorEvent;
037import edu.wisc.ssec.mcidasv.monitors.MonitorManager.MonitorType;
038import edu.wisc.ssec.mcidasv.monitors.Monitoring;
039
040@SuppressWarnings("serial")
041public class MemoryPanel extends JPanel implements Monitoring {
042    private final JLabel memoryLabel = new JLabel("");
043
044    public MemoryPanel() {
045        initComponents();
046    }
047
048    // runs in the EDT! be cautious!
049    public void monitorUpdated(final MonitorEvent event) {
050        if (event.getType() != MonitorType.MEMORY)
051            return;
052
053        MemoryMonitorEvent memEvent = (MemoryMonitorEvent)event;
054        memoryLabel.setText(memEvent.getReadout());
055        memoryLabel.setBackground(memEvent.getColor());
056        repaint();
057    }
058
059    private void initComponents() {
060        GroupLayout layout = new GroupLayout(this);
061        this.setLayout(layout);
062        layout.setHorizontalGroup(
063            layout.createParallelGroup(LEADING)
064            .addGroup(layout.createSequentialGroup()
065                .addContainerGap()
066                .addComponent(memoryLabel)
067                .addContainerGap()));
068
069        layout.setVerticalGroup(
070            layout.createParallelGroup(LEADING)
071            .addGroup(layout.createSequentialGroup()
072                .addComponent(memoryLabel)));
073
074        memoryLabel.setToolTipText("Used memory/Max used memory/Max memory");
075        memoryLabel.setOpaque(true);
076        memoryLabel.setBackground(MemoryMonitor.doColorThing(0));
077    }
078}