Permalink
Browse files

Implemented a command to view all device properties

  • Loading branch information...
1 parent f555dac commit 26229b6f784de89b8c94a4302fa8333733c92298 @ribomation committed Apr 11, 2012
@@ -27,7 +27,7 @@
public ImageDirectoryCommand() {
setLabel("Image Dir");
- setIcon("folder");
+ setIcon("imgfolder");
updateView(getApplication().getSettings().getImageDirectory());
}
@@ -13,11 +13,8 @@
package com.ribomation.droidAtScreen.cmd;
import com.ribomation.droidAtScreen.Application;
-import com.ribomation.droidAtScreen.cmd.CommandWithTarget;
import com.ribomation.droidAtScreen.gui.DeviceFrame;
-import javax.swing.*;
-
/**
* Flips the device-frame 90 degrees.
* <p/>
@@ -0,0 +1,137 @@
+/*
+ * Project: droidAtScreen
+ * File: PropertiesCommand.java
+ * Modified: 2012-04-11
+ *
+ * Copyright (C) 2011, Ribomation AB (Jens Riboe).
+ * http://blog.ribomation.com/
+ *
+ * You are free to use this software and the source code as you like.
+ * We do appreciate if you attribute were it came from.
+ */
+
+package com.ribomation.droidAtScreen.cmd;
+
+import com.ribomation.droidAtScreen.Application;
+import com.ribomation.droidAtScreen.gui.DeviceFrame;
+
+import javax.swing.*;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+import javax.swing.table.AbstractTableModel;
+import java.awt.*;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeSet;
+
+/**
+ * Shows a table with all device properties.
+ *
+ * @user Jens
+ * @date 2012-04-11, 09:46
+ */
+public class PropertiesCommand extends CommandWithTarget<DeviceFrame> {
+
+ public PropertiesCommand(DeviceFrame target) {
+ super(target);
+ updateButton(target);
+ }
+
+ @Override
+ protected void updateButton(DeviceFrame target) {
+ setIcon("list");
+ setTooltip("Shows all device properties");
+ }
+
+ @Override
+ protected void doExecute(Application app, DeviceFrame target) {
+ Map<String, String> properties = target.getDevice().getProperties();
+ final String toolTipText = "Click on a row to view the complete property value";
+
+ PropertiesModel model = new PropertiesModel(properties);
+ JTable tbl = new JTable(model) {
+ @Override
+ public String getToolTipText(MouseEvent event) { return toolTipText; }
+ };
+ tbl.getTableHeader().setToolTipText(toolTipText);
+ tbl.setRowSelectionAllowed(true);
+ tbl.getSelectionModel().addListSelectionListener(model);
+ tbl.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
+ tbl.setShowHorizontalLines(true);
+ tbl.setFillsViewportHeight(true);
+ tbl.setPreferredScrollableViewportSize(new Dimension(400, 200));
+
+ JScrollPane pane = new JScrollPane(tbl);
+ JOptionPane.showMessageDialog(app.getAppFrame(), pane, "Device Properties", JOptionPane.PLAIN_MESSAGE);
+ }
+
+ class PropertiesModel extends AbstractTableModel implements ListSelectionListener {
+ private List<String> names = new ArrayList<String>();
+ private List<String> values = new ArrayList<String>();
+
+ PropertiesModel(Map<String, String> properties) {
+ for (String name : new TreeSet<String>(properties.keySet())) {
+ names.add(name);
+ values.add(properties.get(name));
+ }
+ }
+
+ @Override
+ public void valueChanged(ListSelectionEvent e) {
+ if (e.getValueIsAdjusting()) return;
+ ListSelectionModel lsm = (ListSelectionModel) e.getSource();
+ if (lsm.isSelectionEmpty()) return;
+ int row = lsm.getMinSelectionIndex();
+
+ JTextArea txt = new JTextArea((String) getValueAt(row, 1));
+ txt.setRows(6);
+ txt.setColumns(36);
+ txt.setLineWrap(true);
+ txt.setWrapStyleWord(true);
+ txt.setEditable(false);
+
+ JOptionPane.showMessageDialog(getApplication().getAppFrame(), txt, (String) getValueAt(row, 0), JOptionPane.PLAIN_MESSAGE);
+ }
+
+ @Override
+ public Object getValueAt(int row, int col) {
+ if (col == 0) return names.get(row);
+ if (col == 1) return values.get(row);
+ return null;
+ }
+
+ @Override
+ public String getColumnName(int col) {
+ if (col == 0) return "Name";
+ if (col == 1) return "Value";
+ return "";
+ }
+
+ @Override
+ public int getRowCount() {
+ return names.size();
+ }
+
+ @Override
+ public int getColumnCount() {
+ return 2;
+ }
+
+ @Override
+ public boolean isCellEditable(int row, int col) {
+ return false;
+ }
+
+ @Override
+ public Class<?> getColumnClass(int col) {
+ if (col == 0) return String.class;
+ if (col == 1) return String.class;
+ return Object.class;
+ }
+
+ }
+
+
+}
@@ -102,9 +102,7 @@ public void run() {
long elapsed = System.currentTimeMillis() - start;
infoPane.setElapsed(elapsed, image);
infoPane.setStatus(device.getState().name().toUpperCase());
-
log.debug(String.format("Got screenshot %s, elapsed %d ms", image, elapsed));
-// log.debug(device.getProperties());
boolean fresh = canvas.getScreenshot() == null;
if (image != null) {
@@ -123,12 +121,13 @@ public void run() {
}
protected JComponent createToolBar() {
- JPanel buttons = new JPanel(new GridLayout(5, 1, 0, 8));
+ JPanel buttons = new JPanel(new GridLayout(6, 1, 0, 8));
buttons.add(new OrientationCommand(this).newButton());
buttons.add(new ScaleCommand(this).newButton());
buttons.add(new UpsideDownCommand(this).newButton());
buttons.add(new ScreenshotCommand(this).newButton());
buttons.add(new RecordingCommand(this).newButton());
+ buttons.add(new PropertiesCommand(this).newButton());
JPanel tb = new JPanel(new FlowLayout());
tb.setBorder(BorderFactory.createEmptyBorder());
@@ -261,19 +260,6 @@ protected void paintComponent(Graphics g) {
BufferedImage toLandscape(BufferedImage img) {
return rotate(3, img);
-// int q = 3;
-// int w = img.getWidth();
-// int h = img.getHeight();
-//
-// Point topLeft = new Point((q == 2 || q == 3) ? w : 0, (q == 1 || q == 2) ? h : 0);
-// Point2D origo = AffineTransform.getQuadrantRotateInstance(q, 0, 0).transform(topLeft, null);
-// BufferedImage result = new BufferedImage(h, w, img.getType());
-// Graphics2D g = result.createGraphics();
-// g.translate(0 - origo.getX(), 0 - origo.getY());
-// g.transform(AffineTransform.getQuadrantRotateInstance(q, 0, 0));
-// g.drawRenderedImage(img, null);
-//
-// return result;
}
BufferedImage rotate(int quadrants, BufferedImage img) {
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 26229b6

Please sign in to comment.