Mercurial > hg > release > thermostat-1.2
changeset 1359:62e2419dee05
Add cpu and memory dial to host pane
review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-November/008878.html
reviewed-by: omajid
line wrap: on
line diff
--- a/client/swing-components/pom.xml Fri Nov 22 14:02:33 2013 -0500 +++ b/client/swing-components/pom.xml Mon Nov 25 13:28:50 2013 +0100 @@ -23,6 +23,16 @@ <artifactId>thermostat-common-core</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>com.redhat.thermostat</groupId> + <artifactId>thermostat-client-core</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>com.redhat.thermostat</groupId> + <artifactId>thermostat-client-swing</artifactId> + <version>${project.version}</version> + </dependency> <dependency> <groupId>junit</groupId> @@ -54,7 +64,8 @@ <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> <Bundle-SymbolicName>com.redhat.thermostat.client.swing.components</Bundle-SymbolicName> <Export-Package> - com.redhat.thermostat.swing.components.experimental + com.redhat.thermostat.swing.components.experimental, + com.redhat.thermostat.swing.components.experimental.dial, </Export-Package> <!-- Do not autogenerate uses clauses in Manifests --> <_nouses>true</_nouses>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/swing-components/src/main/java/com/redhat/thermostat/swing/components/experimental/dial/BackgroundRadialMark.java Mon Nov 25 13:28:50 2013 +0100 @@ -0,0 +1,92 @@ +/* + * Copyright 2012, 2013 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat 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 2, or (at your + * option) any later version. + * + * Thermostat 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 Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.swing.components.experimental.dial; + +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.RenderingHints; +import java.awt.geom.Arc2D; + +import com.redhat.thermostat.client.ui.Palette; + +@SuppressWarnings("serial") +class BackgroundRadialMark extends CenterRadialComponent { + + public BackgroundRadialMark(int percentage, int zorder) { + super(percentage, zorder); + setForeground(Palette.LIGHT_GRAY.getColor()); + } + + @Override + protected void paintBackBufferAndMask() { + + if (!checkBuffers()) { + return; + } + + Rectangle rect = new Rectangle(0, 0, getWidth(), getHeight()); + + int diameter = rect.width; + if (rect.width > rect.height) { + diameter = rect.height; + } + + float x = rect.width/2 - diameter/2; + float y = rect.height/2 - diameter/2; + + Graphics2D graphics = (Graphics2D) buffer.getGraphics(); + Graphics2D maskGraphics = (Graphics2D) mask.getGraphics(); + + graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + graphics.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + + graphics.setColor(Palette.ADWAITA_BLU.getColor()); + Arc2D.Float circle = new Arc2D.Float(x, y, diameter, diameter, 312, 275, Arc2D.PIE); + graphics.fill(circle); + + maskGraphics.setColor(Palette.BLACK.getColor()); + maskGraphics.fill(circle); + + circle = new Arc2D.Float(x + 5, y + 5, diameter - 10, diameter - 10, 315, 269, Arc2D.PIE); + graphics.setColor(getForeground()); + graphics.fill(circle); + + graphics.dispose(); + maskGraphics.dispose(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/swing-components/src/main/java/com/redhat/thermostat/swing/components/experimental/dial/CenterRadialComponent.java Mon Nov 25 13:28:50 2013 +0100 @@ -0,0 +1,132 @@ +/* + * Copyright 2012, 2013 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat 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 2, or (at your + * option) any later version. + * + * Thermostat 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 Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.swing.components.experimental.dial; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.RenderingHints; +import java.awt.geom.Arc2D; +import java.awt.image.BufferedImage; + +import com.redhat.thermostat.client.ui.Palette; + +@SuppressWarnings("serial") +class CenterRadialComponent extends RadialComponent { + + protected boolean needRepaint; + + public CenterRadialComponent(int percentage, int zorder) { + super(percentage, zorder); + needRepaint = false; + } + + @Override + public void setForeground(Color fg) { + super.setForeground(fg); + needRepaint = true; + } + + @Override + public void setBackground(Color bg) { + super.setBackground(bg); + needRepaint = true; + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + needRepaint = false; + } + + protected boolean checkBuffers() { + if (buffer == null || + buffer.getWidth() != getWidth() || + buffer.getHeight() != getHeight()) + { + buffer = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); + mask = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_BYTE_BINARY); + + Graphics2D maskGraphics = (Graphics2D) mask.getGraphics(); + maskGraphics.setColor(Palette.WHITE.getColor()); + maskGraphics.fillRect(0, 0, mask.getWidth(), mask.getHeight()); + maskGraphics.dispose(); + + needRepaint = true; + } + + return needRepaint; + } + + @Override + protected void paintBackBufferAndMask() { + + if (!checkBuffers()) { + return; + } + + Rectangle rect = new Rectangle(0, 0, getWidth(), getHeight()); + + int diameter = rect.width; + if (rect.width > rect.height) { + diameter = rect.height; + } + + float x = rect.width/2 - diameter/2; + float y = rect.height/2 - diameter/2; + + Graphics2D graphics = (Graphics2D) buffer.getGraphics(); + Graphics2D maskGraphics = (Graphics2D) mask.getGraphics(); + + graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + + graphics.setColor(getBackground()); + Arc2D.Float circle = new Arc2D.Float(x, y, diameter, diameter, 0, 360, Arc2D.OPEN); + graphics.fill(circle); + + maskGraphics.setColor(Palette.BLACK.getColor()); + maskGraphics.fill(circle); + + circle = new Arc2D.Float(x + 5, y + 5, diameter - 10, diameter - 10, 0, 360, Arc2D.OPEN); + graphics.setColor(getForeground()); + graphics.fill(circle); + + graphics.dispose(); + maskGraphics.dispose(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/swing-components/src/main/java/com/redhat/thermostat/swing/components/experimental/dial/CenterStackingLayout.java Mon Nov 25 13:28:50 2013 +0100 @@ -0,0 +1,96 @@ +/* + * Copyright 2012, 2013 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat 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 2, or (at your + * option) any later version. + * + * Thermostat 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 Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.swing.components.experimental.dial; + +import java.awt.Container; +import java.awt.Rectangle; +import java.awt.geom.Point2D; +import java.util.List; + +import com.redhat.thermostat.client.swing.components.AbstractLayout; + +class CenterStackingLayout extends AbstractLayout { + + private float baseMultiplierX; + private float baseMultiplierY; + + public CenterStackingLayout(float baseMultiplierX, float baseMultiplierY) { + this.baseMultiplierX = baseMultiplierX; + this.baseMultiplierY = baseMultiplierY; + } + + public CenterStackingLayout() { + this(0.5f, 0.5f); + } + + @Override + protected void doLayout(Container parent) { + + if (! (parent instanceof RadialComponentPane)) { + // can't layout anything else! + throw new IllegalArgumentException("can only layout on a " + + "RadialComponentPane"); + } + + RadialComponentPane pane = (RadialComponentPane) parent; + List<RadialComponent> components = pane.getRadialComponents(); + + int totalWidth = pane.getWidth(); + int totalHeight = pane.getHeight(); + + float centerX = totalWidth * baseMultiplierX; + float centerY = totalHeight * baseMultiplierY; + + Point2D.Float center = new Point2D.Float(centerX, centerY); + + for (RadialComponent component : components) { + + float percent = component.getAreaPercentage(); + + float width = (percent * totalWidth)/100; + float height = (percent * totalHeight)/100; + + float x = centerX - (width/2); + float y = centerY - (height/2); + + Rectangle bounds = new Rectangle((int) x, (int) y, (int) width, (int) height); + + component.setBounds(bounds); + component.setRadialCenter(center); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/swing-components/src/main/java/com/redhat/thermostat/swing/components/experimental/dial/RadialComponent.java Mon Nov 25 13:28:50 2013 +0100 @@ -0,0 +1,108 @@ +/* + * Copyright 2012, 2013 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat 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 2, or (at your + * option) any later version. + * + * Thermostat 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 Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.swing.components.experimental.dial; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.geom.Point2D; +import java.awt.image.BufferedImage; + +import javax.swing.JComponent; + +import com.redhat.thermostat.client.swing.GraphicsUtils; +import com.redhat.thermostat.client.ui.Palette; + +@SuppressWarnings("serial") +abstract class RadialComponent extends JComponent implements RadialOrder { + + protected BufferedImage mask; + protected BufferedImage buffer; + + private int percentage; + private int zorder; + + private Point2D.Float center; + + protected RadialComponent(int percentage, int zorder) { + this.percentage = percentage; + this.zorder = zorder; + } + + @Override + public int getOrderValue() { + return zorder; + } + + @Override + public int getAreaPercentage() { + return percentage; + } + + public void setRadialCenter(Point2D.Float center) { + this.center = center; + } + + public Point2D.Float getRadialCenter() { + return center; + } + + @Override + protected void paintComponent(Graphics g) { + + paintBackBufferAndMask(); + + Graphics2D graphics = GraphicsUtils.getInstance().createAAGraphics(g); + + graphics.drawImage(buffer, 0, 0, null); + + graphics.dispose(); + } + + protected abstract void paintBackBufferAndMask(); + + protected boolean isTargetForEvents() { + return true; + } + + public BufferedImage getMask() { + paintBackBufferAndMask(); + return mask; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/swing-components/src/main/java/com/redhat/thermostat/swing/components/experimental/dial/RadialComponentPane.java Mon Nov 25 13:28:50 2013 +0100 @@ -0,0 +1,177 @@ +/* + * Copyright 2012, 2013 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat 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 2, or (at your + * option) any later version. + * + * Thermostat 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 Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.swing.components.experimental.dial; + +import java.awt.AWTEvent; +import java.awt.Component; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Toolkit; +import java.awt.event.AWTEventListener; +import java.awt.event.MouseEvent; +import java.awt.image.BufferedImage; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.swing.JPanel; + +import com.redhat.thermostat.client.ui.Palette; +import com.redhat.thermostat.common.OrderedComparator; + +/** + * A pane that only accept {@link RadialComponent}s. + */ +@SuppressWarnings("serial") +class RadialComponentPane extends JPanel { + + private List<RadialComponent> radialComponentsZOrder; + private List<RadialComponent> radialComponents; + + private RadialComponent lastSelected; + + public RadialComponentPane() { + this(0.5f, 0.5f); + } + + public RadialComponentPane(float baseX, float baseY) { + setLayout(new CenterStackingLayout(baseX, baseY)); + setBackground(Palette.WHITE.getColor()); + setUpEventFiltering(); + + radialComponentsZOrder = new ArrayList<>(); + radialComponents = new ArrayList<>(); + } + + public void addRadialComponentSelectedListener(RadialComponentSelectedListener l) { + listenerList.add(RadialComponentSelectedListener.class, l); + } + + public void removeRadialComponentSelectedListener(RadialComponentSelectedListener l) { + listenerList.remove(RadialComponentSelectedListener.class, l); + } + + private void fireRadialComponentSelectedEvent(RadialComponent source) { + + Object[] listeners = listenerList.getListenerList(); + + RadialComponentSelectedEvent event = new RadialComponentSelectedEvent(source, lastSelected); + + for (int i = listeners.length - 2; i >= 0; i -= 2) { + if (listeners[i] == RadialComponentSelectedListener.class) { + ((RadialComponentSelectedListener) listeners[i + 1]).componentSelected(event); + } + } + } + + private void setUpEventFiltering() { + long eventMask = AWTEvent.MOUSE_EVENT_MASK; + Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { + @Override + public void eventDispatched(AWTEvent awtEvent) { + + // we know this, since it's the mask above, but in case + if ( !(awtEvent instanceof MouseEvent)) { + return; + } + + MouseEvent event = (MouseEvent) awtEvent; + if (event.getID() != MouseEvent.MOUSE_CLICKED) { + return; + } + + Point coordinates = event.getPoint(); + + // check which component will be the target for this event + for (RadialComponent component : radialComponentsZOrder) { + + if (!component.isTargetForEvents()) { + continue; + } + + // check the bounding box first + Rectangle bounds = component.getBounds(); + if (bounds.contains(coordinates)) { + int x = coordinates.x - bounds.x; + int y = coordinates.y - bounds.y; + + // maybe that's it, maybe it passes through + // so let's check the + BufferedImage mask = component.getMask(); + int pixel = mask.getRGB(x, y); + if (pixel == 0xFF000000) { + // fire event and return + fireRadialComponentSelectedEvent(component); + lastSelected = component; + + break; + } + } + } + } + }, eventMask); + } + + @Override + protected void addImpl(Component comp, Object constraints, int index) { + if (comp instanceof RadialComponent) { + super.addImpl(comp, constraints, index); + + radialComponents.add((RadialComponent) comp); + + radialComponentsZOrder.add((RadialComponent) comp); + Collections.sort(radialComponentsZOrder, + new OrderedComparator<RadialComponent>()); + + // now need to get the correct painting order + int zorder = 0; + for (RadialComponent component : radialComponentsZOrder) { + setComponentZOrder(component, zorder++); + } + } else { + throw new IllegalArgumentException(""); + } + } + + public List<RadialComponent> getRadialComponents() { + return radialComponents; + } + + public List<RadialComponent> getRadialComponentsZOrder() { + return radialComponentsZOrder; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/swing-components/src/main/java/com/redhat/thermostat/swing/components/experimental/dial/RadialComponentSelectedEvent.java Mon Nov 25 13:28:50 2013 +0100 @@ -0,0 +1,68 @@ +/* + * Copyright 2012, 2013 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat 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 2, or (at your + * option) any later version. + * + * Thermostat 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 Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.swing.components.experimental.dial; + +import java.util.EventObject; + +/** + * + */ +@SuppressWarnings("serial") +class RadialComponentSelectedEvent extends EventObject { + + private RadialComponent oldSelected; + + public RadialComponentSelectedEvent(RadialComponent source, + RadialComponent oldSelected) + { + super(source); + this.oldSelected = oldSelected; + } + + public RadialComponent getOldSelected() { + return oldSelected; + } + + public RadialComponent getSelected() { + return getSource(); + } + + @Override + public RadialComponent getSource() { + return (RadialComponent) super.getSource(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/swing-components/src/main/java/com/redhat/thermostat/swing/components/experimental/dial/RadialComponentSelectedListener.java Mon Nov 25 13:28:50 2013 +0100 @@ -0,0 +1,46 @@ +/* + * Copyright 2012, 2013 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat 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 2, or (at your + * option) any later version. + * + * Thermostat 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 Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.swing.components.experimental.dial; + +import java.util.EventListener; + +/** + * + */ +interface RadialComponentSelectedListener extends EventListener { + public void componentSelected(RadialComponentSelectedEvent event); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/swing-components/src/main/java/com/redhat/thermostat/swing/components/experimental/dial/RadialControl.java Mon Nov 25 13:28:50 2013 +0100 @@ -0,0 +1,78 @@ +/* + * Copyright 2012, 2013 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat 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 2, or (at your + * option) any later version. + * + * Thermostat 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 Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.swing.components.experimental.dial; + +import java.awt.BorderLayout; + +import javax.swing.JPanel; + +import com.redhat.thermostat.client.ui.Palette; + +/** + * + */ +@SuppressWarnings("serial") +public class RadialControl extends JPanel { + + private RadialProgressIndicator currentIndicator; + + public RadialControl() { + + setLayout(new BorderLayout()); + + RadialComponentPane pane = new RadialComponentPane(0.5f, 0.60f); + pane.setForeground(Palette.EARL_GRAY.getColor()); + + CenterRadialComponent center = new CenterRadialComponent(30, RadialOrder.CENTER); + pane.add(center); + + BackgroundRadialMark background = new BackgroundRadialMark(80, RadialOrder.THIRD); + pane.add(background); + + RadialTicks ticks = new RadialTicks(100, RadialOrder.FOURTH, background); + pane.add(ticks); + + currentIndicator = new RadialProgressIndicator(60, RadialOrder.SECOND); + pane.add(currentIndicator); + + add(pane); + } + + public void setProgressPercentage(float percent) { + currentIndicator.setProgressPercentage(percent); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/swing-components/src/main/java/com/redhat/thermostat/swing/components/experimental/dial/RadialOrder.java Mon Nov 25 13:28:50 2013 +0100 @@ -0,0 +1,55 @@ +/* + * Copyright 2012, 2013 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat 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 2, or (at your + * option) any later version. + * + * Thermostat 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 Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.swing.components.experimental.dial; + +import com.redhat.thermostat.common.Ordered; + +interface RadialOrder extends Ordered { + + public static final int CENTER = 0; + + public static final int FIRST = 1; + public static final int SECOND = 2; + public static final int THIRD = 3; + public static final int FOURTH = 4; + public static final int FIFTH = 5; + + public static final int INNER = CENTER; + public static final int OUTER = Integer.MAX_VALUE; + + int getAreaPercentage(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/swing-components/src/main/java/com/redhat/thermostat/swing/components/experimental/dial/RadialProgressIndicator.java Mon Nov 25 13:28:50 2013 +0100 @@ -0,0 +1,115 @@ +/* + * Copyright 2012, 2013 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat 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 2, or (at your + * option) any later version. + * + * Thermostat 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 Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.swing.components.experimental.dial; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.RenderingHints; +import java.awt.geom.Arc2D; + +import com.redhat.thermostat.client.ui.Palette; + +@SuppressWarnings("serial") +class RadialProgressIndicator extends CenterRadialComponent { + + private float percent; + + public RadialProgressIndicator(int percentage, int zorder) { + super(percentage, zorder); + } + + public void setProgressPercentage(float percent) { + if (percent > 100.f) { + percent = 100.f; + + } else if (percent < 0.f) { + percent = 0.f; + } + + if (this.percent != percent) { + this.percent = percent; + needRepaint = true; + repaint(); + } + } + + @Override + protected void paintBackBufferAndMask() { + + if (!checkBuffers()) { + return; + } + + Rectangle rect = new Rectangle(0, 0, getWidth(), getHeight()); + + int diameter = rect.width; + if (rect.width > rect.height) { + diameter = rect.height; + } + + float startAngle = 225; + + float teta = 270 * percent/100; + + Graphics2D graphics = (Graphics2D) buffer.getGraphics(); + graphics.setBackground(new Color(255, 255, 255, 0)); + graphics.clearRect(0, 0, buffer.getWidth(), buffer.getHeight()); + + Graphics2D maskGraphics = (Graphics2D) mask.getGraphics(); + maskGraphics.setBackground(Color.WHITE); + maskGraphics.clearRect(0, 0, buffer.getWidth(), buffer.getHeight()); + + graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + graphics.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + + graphics.setColor(Palette.GREEN.getColor()); + + float x = rect.width/2 - diameter/2; + float y = rect.height/2 - diameter/2; + + Arc2D.Float circle = new Arc2D.Float(x, y, diameter, diameter, startAngle, -teta, Arc2D.PIE); + graphics.fill(circle); + + maskGraphics.setColor(Palette.BLACK.getColor()); + maskGraphics.fill(circle); + + graphics.dispose(); + maskGraphics.dispose(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/swing-components/src/main/java/com/redhat/thermostat/swing/components/experimental/dial/RadialTicks.java Mon Nov 25 13:28:50 2013 +0100 @@ -0,0 +1,132 @@ +/* + * Copyright 2012, 2013 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat 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 2, or (at your + * option) any later version. + * + * Thermostat 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 Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.swing.components.experimental.dial; + +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.RenderingHints; +import java.awt.geom.Arc2D; + +import com.redhat.thermostat.client.ui.Palette; + +/** + * + */ +@SuppressWarnings("serial") +class RadialTicks extends BackgroundRadialMark { + + private BackgroundRadialMark background; + + public RadialTicks(int percentage, int zorder, BackgroundRadialMark background) { + super(percentage, zorder); + this.background = background; + setForeground(Palette.EARL_GRAY.getColor()); + } + + @Override + protected boolean isTargetForEvents() { + return false; + } + + @Override + protected void paintBackBufferAndMask() { + if (!checkBuffers()) { + return; + } + + // we won't paint the mask here, since this isn't target for events + Graphics2D graphics = (Graphics2D) buffer.getGraphics(); + + graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + graphics.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + + Rectangle rect = new Rectangle(0, 0, getWidth(), getHeight()); + + int parentDiameter = background.getWidth(); + int diameter = rect.width; + if (rect.width > rect.height) { + parentDiameter = background.getHeight(); + diameter = rect.height; + } + + float x = rect.width/2 - diameter/2; + float y = rect.height/2 - diameter/2; + graphics.setColor(Palette.ADWAITA_BLU.getColor()); + + Arc2D.Float circle = new Arc2D.Float(x, y, diameter, diameter, 312, 275, Arc2D.PIE); + graphics.fill(circle); + + float radius = diameter / 2; + float parentRadius = parentDiameter / 2; + + float delta = (radius - parentRadius)/2; + + parentRadius += delta; + + float centerX = (float) getWidth()/2; + float centerY = (float) getHeight()/2; + + int the100W = graphics.getFontMetrics().stringWidth("100") / 4; + int the100H = graphics.getFontMetrics().getHeight() / 6; + + graphics.translate(centerX - the100W, centerY - the100H); + graphics.setColor(Palette.LIGHT_GRAY.getColor()); + + int j = 0; + + // TODO: those should be exported + double teta = 225; + double endAngle = 315; + + double increment = Math.abs((360 + teta - endAngle) / 10); + for (int i = 0; i < 11; i++) { + + double tetaRadiants = Math.toRadians(teta); + + x = parentRadius * (float) Math.cos(tetaRadiants); + y = parentRadius * (float) Math.sin(tetaRadiants); + + graphics.drawString("" + j, x, -y); + j += 10; + + teta -= increment; + } + + graphics.dispose(); + } +}
--- a/client/swing/pom.xml Fri Nov 22 14:02:33 2013 -0500 +++ b/client/swing/pom.xml Mon Nov 25 13:28:50 2013 +0100 @@ -62,11 +62,6 @@ <version>${project.version}</version> </dependency> <dependency> - <groupId>com.redhat.thermostat</groupId> - <artifactId>thermostat-swing-components</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope>
--- a/host-overview/client-core/pom.xml Fri Nov 22 14:02:33 2013 -0500 +++ b/host-overview/client-core/pom.xml Mon Nov 25 13:28:50 2013 +0100 @@ -87,5 +87,15 @@ <version>${project.version}</version> <scope>test</scope> </dependency> + <dependency> + <groupId>com.redhat.thermostat</groupId> + <artifactId>thermostat-host-cpu-common</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>com.redhat.thermostat</groupId> + <artifactId>thermostat-host-memory-common</artifactId> + <version>${project.version}</version> + </dependency> </dependencies> </project>
--- a/host-overview/client-core/src/main/java/com/redhat/thermostat/host/overview/client/core/HostOverviewView.java Fri Nov 22 14:02:33 2013 -0500 +++ b/host-overview/client-core/src/main/java/com/redhat/thermostat/host/overview/client/core/HostOverviewView.java Mon Nov 25 13:28:50 2013 +0100 @@ -59,5 +59,8 @@ public abstract void setInitialNetworkTableData(Object[][] table); public abstract void updateNetworkTableData(int row, int column, String data); + + public abstract void setCPUPercentage(float percentage); + public abstract void setMemoryPercentage(float percentage); }
--- a/host-overview/client-core/src/main/java/com/redhat/thermostat/host/overview/client/core/internal/Activator.java Fri Nov 22 14:02:33 2013 -0500 +++ b/host-overview/client-core/src/main/java/com/redhat/thermostat/host/overview/client/core/internal/Activator.java Mon Nov 25 13:28:50 2013 +0100 @@ -50,6 +50,8 @@ import com.redhat.thermostat.common.Constants; import com.redhat.thermostat.common.MultipleServiceTracker; import com.redhat.thermostat.common.MultipleServiceTracker.Action; +import com.redhat.thermostat.host.cpu.common.CpuStatDAO; +import com.redhat.thermostat.host.memory.common.MemoryStatDAO; import com.redhat.thermostat.host.overview.client.core.HostOverviewService; import com.redhat.thermostat.host.overview.client.core.HostOverviewViewProvider; import com.redhat.thermostat.storage.core.HostRef; @@ -67,7 +69,9 @@ HostInfoDAO.class, NetworkInterfaceInfoDAO.class, ApplicationService.class, - HostOverviewViewProvider.class + HostOverviewViewProvider.class, + CpuStatDAO.class, + MemoryStatDAO.class, }; tracker = new MultipleServiceTracker(context, deps, new Action() { @@ -85,7 +89,16 @@ .get(HostOverviewViewProvider.class.getName()); Objects.requireNonNull(viewProvider); - HostOverviewService service = new HostOverviewServiceImpl(appSvc, hostInfoDAO, networkInfoDAO, viewProvider); + CpuStatDAO cpuDao = (CpuStatDAO) services.get(CpuStatDAO.class.getName()); + Objects.requireNonNull(cpuDao); + + MemoryStatDAO memoryDao = (MemoryStatDAO) services.get(MemoryStatDAO.class.getName()); + Objects.requireNonNull(memoryDao); + + HostOverviewService service = + new HostOverviewServiceImpl(appSvc, hostInfoDAO, + networkInfoDAO, cpuDao, + memoryDao, viewProvider); Dictionary<String, String> properties = new Hashtable<>(); properties.put(Constants.GENERIC_SERVICE_CLASSNAME, HostRef.class.getName()); properties.put(InformationService.KEY_SERVICE_ID, HostOverviewService.SERVICE_ID);
--- a/host-overview/client-core/src/main/java/com/redhat/thermostat/host/overview/client/core/internal/HostOverviewController.java Fri Nov 22 14:02:33 2013 -0500 +++ b/host-overview/client-core/src/main/java/com/redhat/thermostat/host/overview/client/core/internal/HostOverviewController.java Mon Nov 25 13:28:50 2013 +0100 @@ -36,6 +36,7 @@ package com.redhat.thermostat.host.overview.client.core.internal; +import java.lang.reflect.Member; import java.util.ArrayList; import java.util.List; import java.util.Vector; @@ -51,6 +52,10 @@ import com.redhat.thermostat.common.Size; import com.redhat.thermostat.common.Timer; import com.redhat.thermostat.common.Timer.SchedulingType; +import com.redhat.thermostat.host.cpu.common.CpuStatDAO; +import com.redhat.thermostat.host.cpu.common.model.CpuStat; +import com.redhat.thermostat.host.memory.common.MemoryStatDAO; +import com.redhat.thermostat.host.memory.common.model.MemoryStat; import com.redhat.thermostat.host.overview.client.core.HostOverviewView; import com.redhat.thermostat.host.overview.client.core.HostOverviewViewProvider; import com.redhat.thermostat.host.overview.client.locale.LocaleResources; @@ -70,11 +75,20 @@ private final NetworkInterfaceInfoDAO networkInfoDAO; private final Timer backgroundUpdateTimer; + private final Timer statsTimer; + private final List<String> knownNetworkIfaces = new ArrayList<>(); private final HostOverviewView view; - public HostOverviewController(ApplicationService appSvc, HostInfoDAO hostInfoDAO, NetworkInterfaceInfoDAO networkInfoDAO, final HostRef ref, HostOverviewViewProvider provider) { + public HostOverviewController(ApplicationService appSvc, + HostInfoDAO hostInfoDAO, + NetworkInterfaceInfoDAO networkInfoDAO, + final CpuStatDAO cpuDao, + final MemoryStatDAO memoryDao, + final HostRef ref, + HostOverviewViewProvider provider) + { this.hostInfoDAO = hostInfoDAO; this.networkInfoDAO = networkInfoDAO; @@ -150,14 +164,57 @@ } } }); + + statsTimer = appSvc.getTimerFactory().createTimer(); + statsTimer.setDelay(500); + statsTimer.setInitialDelay(0); + statsTimer.setTimeUnit(TimeUnit.MILLISECONDS); + statsTimer.setSchedulingType(SchedulingType.FIXED_RATE); + statsTimer.setAction(new Runnable() { + @Override + public void run() { + List<CpuStat> cpuStats = cpuDao.getLatestCpuStats(ref, System.currentTimeMillis() - 5000); + if (!cpuStats.isEmpty()) { + CpuStat stat = cpuStats.get(0); + double [] cpuUsage = stat.getPerProcessorUsage(); + // dumb average + int cpus = cpuUsage.length; + double total = 0; + for (double thisCPU : cpuUsage) { + total += thisCPU; + } + total = total/cpus; + view.setCPUPercentage((float) total); + } + + List<MemoryStat> memoryStats = + memoryDao.getLatestMemoryStats(ref, System.currentTimeMillis() - 5000); + if (!memoryStats.isEmpty()) { + MemoryStat stat = memoryStats.get(0); + + long total = stat.getTotal(); + long buffered = stat.getBuffers(); + long cached = stat.getCached(); + long free = stat.getFree(); + long used = total - free; + + long usedMemory = (used - (buffered + cached)); + + float usedMemoryPercent = (float) usedMemory/total*100; + view.setMemoryPercentage(usedMemoryPercent); + } + } + }); } private void start() { backgroundUpdateTimer.start(); + statsTimer.start(); } private void stop() { backgroundUpdateTimer.stop(); + statsTimer.stop(); } public UIComponent getView() {
--- a/host-overview/client-core/src/main/java/com/redhat/thermostat/host/overview/client/core/internal/HostOverviewServiceImpl.java Fri Nov 22 14:02:33 2013 -0500 +++ b/host-overview/client-core/src/main/java/com/redhat/thermostat/host/overview/client/core/internal/HostOverviewServiceImpl.java Mon Nov 25 13:28:50 2013 +0100 @@ -40,6 +40,8 @@ import com.redhat.thermostat.client.core.NameMatchingRefFilter; import com.redhat.thermostat.client.core.controllers.InformationServiceController; import com.redhat.thermostat.common.ApplicationService; +import com.redhat.thermostat.host.cpu.common.CpuStatDAO; +import com.redhat.thermostat.host.memory.common.MemoryStatDAO; import com.redhat.thermostat.host.overview.client.core.HostOverviewService; import com.redhat.thermostat.host.overview.client.core.HostOverviewViewProvider; import com.redhat.thermostat.storage.core.HostRef; @@ -55,14 +57,22 @@ private HostInfoDAO hostInfoDAO; private NetworkInterfaceInfoDAO networkInfoDAO; private HostOverviewViewProvider viewProvider; + private CpuStatDAO cpuDao; + private MemoryStatDAO memoryDao; public HostOverviewServiceImpl(ApplicationService appSvc, - HostInfoDAO hostInfoDAO, NetworkInterfaceInfoDAO networkInfoDAO, - HostOverviewViewProvider viewProvider) { + HostInfoDAO hostInfoDAO, + NetworkInterfaceInfoDAO networkInfoDAO, + CpuStatDAO cpuDao, + MemoryStatDAO memoryDao, + HostOverviewViewProvider viewProvider) + { this.appSvc = appSvc; this.hostInfoDAO = hostInfoDAO; this.networkInfoDAO = networkInfoDAO; this.viewProvider = viewProvider; + this.cpuDao = cpuDao; + this.memoryDao = memoryDao; } @Override @@ -71,9 +81,10 @@ } @Override - public InformationServiceController<HostRef> getInformationServiceController( - HostRef ref) { - return new HostOverviewController(appSvc, hostInfoDAO, networkInfoDAO, ref, viewProvider); + public InformationServiceController<HostRef> getInformationServiceController(HostRef ref) + { + return new HostOverviewController(appSvc, hostInfoDAO, networkInfoDAO, + cpuDao, memoryDao, ref, viewProvider); } @Override
--- a/host-overview/client-core/src/test/java/com/redhat/thermostat/host/overview/client/core/internal/ActivatorTest.java Fri Nov 22 14:02:33 2013 -0500 +++ b/host-overview/client-core/src/test/java/com/redhat/thermostat/host/overview/client/core/internal/ActivatorTest.java Mon Nov 25 13:28:50 2013 +0100 @@ -45,6 +45,8 @@ import com.redhat.thermostat.client.core.InformationService; import com.redhat.thermostat.common.ApplicationService; +import com.redhat.thermostat.host.cpu.common.CpuStatDAO; +import com.redhat.thermostat.host.memory.common.MemoryStatDAO; import com.redhat.thermostat.host.overview.client.core.HostOverviewViewProvider; import com.redhat.thermostat.storage.dao.HostInfoDAO; import com.redhat.thermostat.storage.dao.NetworkInterfaceInfoDAO; @@ -73,11 +75,15 @@ NetworkInterfaceInfoDAO networkInfoDAO = mock(NetworkInterfaceInfoDAO.class); ApplicationService appSvc = mock(ApplicationService.class); HostOverviewViewProvider viewProvider = mock(HostOverviewViewProvider.class); + CpuStatDAO cpuStat = mock(CpuStatDAO.class); + MemoryStatDAO memoryStat = mock(MemoryStatDAO.class); context.registerService(HostInfoDAO.class, hostInfoDAO, null); context.registerService(NetworkInterfaceInfoDAO.class, networkInfoDAO, null); context.registerService(ApplicationService.class, appSvc, null); context.registerService(HostOverviewViewProvider.class, viewProvider, null); + context.registerService(CpuStatDAO.class, cpuStat, null); + context.registerService(MemoryStatDAO.class, memoryStat, null); Activator activator = new Activator(); @@ -88,7 +94,7 @@ activator.stop(context); assertEquals(0, context.getServiceListeners().size()); - assertEquals(4, context.getAllServices().size()); + assertEquals(6, context.getAllServices().size()); } }
--- a/host-overview/client-core/src/test/java/com/redhat/thermostat/host/overview/client/core/internal/HostOverviewControllerTest.java Fri Nov 22 14:02:33 2013 -0500 +++ b/host-overview/client-core/src/test/java/com/redhat/thermostat/host/overview/client/core/internal/HostOverviewControllerTest.java Mon Nov 25 13:28:50 2013 +0100 @@ -60,6 +60,8 @@ import com.redhat.thermostat.common.Timer; import com.redhat.thermostat.common.Timer.SchedulingType; import com.redhat.thermostat.common.TimerFactory; +import com.redhat.thermostat.host.cpu.common.CpuStatDAO; +import com.redhat.thermostat.host.memory.common.MemoryStatDAO; import com.redhat.thermostat.host.overview.client.core.HostOverviewView; import com.redhat.thermostat.host.overview.client.core.HostOverviewViewProvider; import com.redhat.thermostat.storage.core.HostRef; @@ -79,8 +81,10 @@ private static final String NETWORK_INTERFACE = "iface0"; private static final String IPV4_ADDR = "0xcafef00d"; private static final String IPV6_ADDR = "HOME_SWEET_HOME"; + + private Timer timer; + private Timer timer2; - private Timer timer; private Runnable timerAction; private HostOverviewView view; private ActionListener<HostOverviewView.Action> listener; @@ -90,14 +94,19 @@ public void setUp() { // Setup timer timer = mock(Timer.class); + timer2 = mock(Timer.class); + ArgumentCaptor<Runnable> timerActionCaptor = ArgumentCaptor.forClass(Runnable.class); doNothing().when(timer).setAction(timerActionCaptor.capture()); - + TimerFactory timerFactory = mock(TimerFactory.class); - when(timerFactory.createTimer()).thenReturn(timer); + when(timerFactory.createTimer()).thenReturn(timer).thenReturn(timer2); ApplicationService appSvc = mock(ApplicationService.class); when(appSvc.getTimerFactory()).thenReturn(timerFactory); + CpuStatDAO cpuStat = mock(CpuStatDAO.class); + MemoryStatDAO memoryStat = mock(MemoryStatDAO.class); + // Setup DAOs HostInfo hostInfo = new HostInfo("foo", HOST_NAME, OS_NAME, KERNEL_NAME, CPU_MODEL, CPU_COUNT, TOTAL_MEMORY); @@ -123,7 +132,9 @@ when(viewProvider.createView()).thenReturn(view); @SuppressWarnings("unused") - HostOverviewController controller = new HostOverviewController(appSvc, hostInfoDao, networkInfoDao, ref, viewProvider); + HostOverviewController controller = + new HostOverviewController(appSvc, hostInfoDao, networkInfoDao, + cpuStat, memoryStat, ref, viewProvider); listener = listenerCaptor.getValue(); timerAction = timerActionCaptor.getValue();
--- a/host-overview/client-swing/pom.xml Fri Nov 22 14:02:33 2013 -0500 +++ b/host-overview/client-swing/pom.xml Mon Nov 25 13:28:50 2013 +0100 @@ -80,6 +80,12 @@ </dependency> <dependency> <groupId>com.redhat.thermostat</groupId> + <artifactId>thermostat-swing-components</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>com.redhat.thermostat</groupId> <artifactId>thermostat-common-test</artifactId> <version>${project.version}</version> <scope>test</scope>
--- a/host-overview/client-swing/src/main/java/com/redhat/thermostat/host/overview/client/swing/internal/HostOverviewPanel.java Fri Nov 22 14:02:33 2013 -0500 +++ b/host-overview/client-swing/src/main/java/com/redhat/thermostat/host/overview/client/swing/internal/HostOverviewPanel.java Mon Nov 25 13:28:50 2013 +0100 @@ -60,9 +60,18 @@ import com.redhat.thermostat.host.overview.client.core.HostOverviewView; import com.redhat.thermostat.host.overview.client.locale.LocaleResources; import com.redhat.thermostat.shared.locale.Translate; +import com.redhat.thermostat.swing.components.experimental.dial.RadialControl; +import javax.swing.border.TitledBorder; +import javax.swing.border.LineBorder; +import java.awt.Color; +import javax.swing.JLabel; +import javax.swing.SwingConstants; public class HostOverviewPanel extends HostOverviewView implements SwingComponent { + RadialControl radialControl; + RadialControl radialControl_1; + private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); private JPanel visiblePanel; @@ -232,6 +241,7 @@ private void initializePanel() { visiblePanel = new JPanel(); + visiblePanel.setBackground(Color.WHITE); SectionHeader overviewSection = new SectionHeader(translator.localize(LocaleResources.HOST_OVERVIEW_SECTION_BASICS)); LabelField hostnameLabel = new LabelField(translator.localize(LocaleResources.HOST_INFO_HOSTNAME)); SectionHeader hardwareSection = new SectionHeader(translator.localize(LocaleResources.HOST_OVERVIEW_SECTION_HARDWARE)); @@ -244,16 +254,20 @@ LabelField osKernelLabel = new LabelField(translator.localize(LocaleResources.HOST_INFO_OS_KERNEL)); JPanel panel = new JPanel(); + + JPanel radialSummaryPanel = new JPanel(); + radialSummaryPanel.setBackground(Color.WHITE); GroupLayout gl_visiblePanel = new GroupLayout(visiblePanel); gl_visiblePanel.setHorizontalGroup( gl_visiblePanel.createParallelGroup(Alignment.LEADING) - .addGroup(gl_visiblePanel.createSequentialGroup() + .addGroup(Alignment.TRAILING, gl_visiblePanel.createSequentialGroup() .addContainerGap() - .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING) - .addComponent(hardwareSection, GroupLayout.DEFAULT_SIZE, 620, Short.MAX_VALUE) - .addComponent(overviewSection, GroupLayout.DEFAULT_SIZE, 620, Short.MAX_VALUE) - .addGroup(gl_visiblePanel.createSequentialGroup() + .addGroup(gl_visiblePanel.createParallelGroup(Alignment.TRAILING) + .addComponent(radialSummaryPanel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 647, Short.MAX_VALUE) + .addComponent(hardwareSection, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 647, Short.MAX_VALUE) + .addComponent(overviewSection, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 647, Short.MAX_VALUE) + .addGroup(Alignment.LEADING, gl_visiblePanel.createSequentialGroup() .addGroup(gl_visiblePanel.createParallelGroup(Alignment.TRAILING, false) .addGroup(gl_visiblePanel.createSequentialGroup() .addGap(12) @@ -266,13 +280,13 @@ .addComponent(networkLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING) - .addComponent(panel, GroupLayout.DEFAULT_SIZE, 462, Short.MAX_VALUE) + .addComponent(panel, GroupLayout.DEFAULT_SIZE, 495, Short.MAX_VALUE) .addComponent(cpuCount, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(cpuModel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(hostname, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(totalMemory, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) - .addComponent(softwareSection, GroupLayout.DEFAULT_SIZE, 620, Short.MAX_VALUE) - .addGroup(gl_visiblePanel.createSequentialGroup() + .addComponent(softwareSection, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 647, Short.MAX_VALUE) + .addGroup(Alignment.LEADING, gl_visiblePanel.createSequentialGroup() .addGap(12) .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING, false) .addComponent(osKernelLabel, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) @@ -320,8 +334,49 @@ .addGroup(gl_visiblePanel.createParallelGroup(Alignment.LEADING) .addComponent(osKernelLabel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(osKernel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)) - .addGap(128)) + .addGap(18) + .addComponent(radialSummaryPanel, GroupLayout.DEFAULT_SIZE, 196, Short.MAX_VALUE) + .addContainerGap()) ); + + radialControl = new RadialControl(); + + radialControl_1 = new RadialControl(); + + JLabel lblCpu = new JLabel("CPU"); + lblCpu.setHorizontalAlignment(SwingConstants.CENTER); + + JLabel lblMemory = new JLabel("Memory"); + lblMemory.setHorizontalAlignment(SwingConstants.CENTER); + GroupLayout gl_radialSummaryPanel = new GroupLayout(radialSummaryPanel); + gl_radialSummaryPanel.setHorizontalGroup( + gl_radialSummaryPanel.createParallelGroup(Alignment.LEADING) + .addGroup(gl_radialSummaryPanel.createSequentialGroup() + .addContainerGap() + .addGroup(gl_radialSummaryPanel.createParallelGroup(Alignment.TRAILING, false) + .addGroup(gl_radialSummaryPanel.createSequentialGroup() + .addGap(6) + .addComponent(lblCpu, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(radialControl, Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 361, GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(ComponentPlacement.RELATED) + .addGroup(gl_radialSummaryPanel.createParallelGroup(Alignment.LEADING, false) + .addComponent(lblMemory, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(radialControl_1, GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE)) + .addContainerGap(32, Short.MAX_VALUE)) + ); + gl_radialSummaryPanel.setVerticalGroup( + gl_radialSummaryPanel.createParallelGroup(Alignment.LEADING) + .addGroup(gl_radialSummaryPanel.createSequentialGroup() + .addGroup(gl_radialSummaryPanel.createParallelGroup(Alignment.LEADING) + .addComponent(radialControl, GroupLayout.PREFERRED_SIZE, 331, GroupLayout.PREFERRED_SIZE) + .addComponent(radialControl_1, GroupLayout.PREFERRED_SIZE, 331, GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(ComponentPlacement.RELATED) + .addGroup(gl_radialSummaryPanel.createParallelGroup(Alignment.BASELINE) + .addComponent(lblCpu) + .addComponent(lblMemory)) + .addContainerGap(23, Short.MAX_VALUE)) + ); + radialSummaryPanel.setLayout(gl_radialSummaryPanel); panel.setLayout(new BorderLayout(0, 0)); @@ -334,5 +389,24 @@ scrollPane = new JScrollPane(visiblePanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); } + + @Override + public void setCPUPercentage(final float percent) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + radialControl.setProgressPercentage(percent); + } + }); + } + + @Override + public void setMemoryPercentage(final float percent) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + radialControl_1.setProgressPercentage(percent); + } + }); + } }