Commits

Anonymous committed b87ba32

Nicer UI, especially concerning the buttons on K3/K4 devices

Comments (0)

Files changed (8)

 
 product.filename=KindleLauncher
 product.extension=azw2
-product.name=Kindle Launcher
-product.version=0.4
+product.name=KUAL
+product.version=0.4.1
 product.vendor=twobob ixtab stepk
 product.mainclass=com.mobileread.ixtab.kindlelauncher.LauncherKindlet
 product.image=KindleLauncher.jpg

src/com/mobileread/ixtab/kindlelauncher/LauncherKindlet.java

 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
-import java.util.HashMap;
 import java.util.Map;
 import java.util.Map.Entry;
 
 import com.amazon.kindle.kindlet.KindletContext;
 import com.mobileread.ixtab.kindlelauncher.resources.ResourceLoader;
+import com.mobileread.ixtab.kindlelauncher.ui.GapComponent;
 import com.mobileread.ixtab.kindlelauncher.ui.UIAdapter;
 
 public class LauncherKindlet extends SuicidalKindlet implements ActionListener {
 
 	private void initializeUI() {
 		Container root = context.getRootContainer();
+		int gap = getUI().getGap();
 		root.removeAll();
-		root.setLayout(new BorderLayout());
-
-		root.add(prevPageButton, BorderLayout.WEST);
-		root.add(nextPageButton, BorderLayout.EAST);
+		
+		
+		root.setLayout(new BorderLayout(gap,gap));
+		Container main = getUI().newPanel(new BorderLayout(gap,gap));
+		
+		// this is a horrible workaround to simulate adding a border around
+		// the main container. It has to be done this way because we have
+		// to support different framework versions.
+		root.add(main, BorderLayout.CENTER);
+		root.add(new GapComponent(0), BorderLayout.NORTH);
+		root.add(new GapComponent(0), BorderLayout.EAST);
+		root.add(new GapComponent(0), BorderLayout.SOUTH);
+		root.add(new GapComponent(0), BorderLayout.WEST);
+
+		main.add(prevPageButton, BorderLayout.WEST);
+		main.add(nextPageButton, BorderLayout.EAST);
 		status = getUI().newLabel("Status");
-		root.add(status, BorderLayout.SOUTH);
+		main.add(status, BorderLayout.SOUTH);
 
-		GridLayout grid = new GridLayout(getPageSize(), 1);
+		GridLayout grid = new GridLayout(getPageSize(), 1, gap, gap);
 		entriesPanel = getUI().newPanel(grid);
 
-		root.add(entriesPanel, BorderLayout.CENTER);
+		main.add(entriesPanel, BorderLayout.CENTER);
 
 		// FOR TESTING ONLY, if a specific number of entries is needed.
 		// for (int i = 0; i < 25; ++i) {
 		// executablesMap.put("TEST-" + i, "touch /tmp/test-" + i + ".tmp");
 		// }
-
+		
 		updateDisplayedLaunchers();
 
 	}
 			}
 			entriesPanel.add(button);
 		}
+		
 		// weird shit: it's actually the setStatus() which prevents the Kindle
 		// Touch from simply showing an empty list. WTF?!
-		setStatus("Items " + (offset + 1) + " - " + end + " of "
+		setStatus("Entries " + (offset + 1) + " - " + end + " of "
 				+ executablesMap.size());
 		boolean enableButtons = getPageSize() < executablesMap.size();
 		prevPageButton.setEnabled(enableButtons);

src/com/mobileread/ixtab/kindlelauncher/Util.java

 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.List;
-//import java.util.StringTokenizer;
 
 public class Util {
-/*
-	public static String[] splitLine(String input, String delim) {
-		StringTokenizer st = new StringTokenizer(input, delim);
-		List result = new ArrayList();
-		while (st.hasMoreElements()) {
-			result.add(st.nextElement());
-		}
-		String[] split = new String[result.size()];
-		for (int i = 0; i < split.length; ++i) {
-			split[i] = (String) result.get(i);
-		}
-		return split;
-
-	}
-*/
+	
 	public static void copy(InputStream is, OutputStream os) throws IOException {
 		byte[] buffer = new byte[4096];
 		int bytesRead;

src/com/mobileread/ixtab/kindlelauncher/ui/GapComponent.java

+package com.mobileread.ixtab.kindlelauncher.ui;
+
+import java.awt.Component;
+import java.awt.Dimension;
+
+/**
+ * This is a really ugly way of defining a UI component which doesn't do
+ * anything, but wants some space on the screen. It's a workaround for not being
+ * able to use borders -- essentially, putting one of these on every side
+ * (NORTH, EAST, SOUTH, WEST) of a BorderLayout'ed container is roughly the same
+ * as surrounding the CENTER'ed component with an appropriate border.
+ * 
+ * @author ixtab
+ * 
+ */
+public class GapComponent extends Component {
+	private static final long serialVersionUID = 1L;
+
+	private final Dimension size;
+
+	public GapComponent(int size) {
+		this.size = new Dimension(size, size);
+		this.setEnabled(false);
+		this.setFocusable(false);
+	}
+
+	public Dimension getSize() {
+		return size;
+	}
+
+	public Dimension getSize(Dimension rv) {
+		return size;
+	}
+
+	public Dimension getPreferredSize() {
+		return size;
+	}
+
+	public Dimension getMinimumSize() {
+		return size;
+	}
+
+	public Dimension getMaximumSize() {
+		return size;
+	}
+}

src/com/mobileread/ixtab/kindlelauncher/ui/UIAdapter.java

 	public abstract void suicide(KindletContext context);
 
 	public abstract int getDefaultPageSize();
+
+	public int getGap() {
+		return 5;
+	}
 }

src/com/mobileread/ixtab/kindlelauncher/ui/v1/KUIAdapter.java

 	}
 
 	public Component newButton(String text, ActionListener listener) {
-		KButton button = new KButton(text);
+		KButton button = new KualButton(text);
 		if (listener != null) {
 			button.setName(text);
 			button.addActionListener(listener);
 		// these are non-touch models, so it's tedious to scroll.
 		return 5;
 	}
-	
 }

src/com/mobileread/ixtab/kindlelauncher/ui/v1/KualButton.java

+package com.mobileread.ixtab.kindlelauncher.ui.v1;
+
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+
+import com.amazon.kindle.kindlet.ui.KButton;
+
+public class KualButton extends KButton {
+
+	private static final long serialVersionUID = 1L;
+
+	private static final Color COLOR_FOREGROUND = Color.BLACK;
+	private static final Color COLOR_BACKGROUND = Color.WHITE;
+	private static final Color COLOR_DISABLED = Color.LIGHT_GRAY;
+	private static final int BORDER_PX = 2;
+	private static final int GAP_PX = 0;
+	private static final int ARC_PX = 15;
+
+	public KualButton(String text) {
+		super(text);
+	}
+
+	public void paint(Graphics g) {
+		Color foreground = isEnabled() ? COLOR_FOREGROUND : COLOR_DISABLED;
+		Color background = COLOR_BACKGROUND;
+
+		int width = getWidth();
+		int height = getHeight();
+		Font font = getFont();
+		FontMetrics fm = this.getFontMetrics(font);
+
+		g.setColor(foreground);
+		g.fillRoundRect(GAP_PX, GAP_PX, width - GAP_PX * 2, height
+				- GAP_PX * 2, ARC_PX, ARC_PX);
+
+		if (hasFocus()) {
+			background = foreground;
+			foreground = getBackground();
+		} else {
+			g.setColor(background);
+			g.fillRoundRect(GAP_PX + BORDER_PX, GAP_PX + BORDER_PX,
+					width - (GAP_PX + BORDER_PX) * 2, height
+							- (GAP_PX + BORDER_PX) * 2, ARC_PX, ARC_PX);
+		}
+
+		String text = getLabel();
+
+		int tx = (width / 2) - (fm.stringWidth(text) / 2);
+		int ty = (height / 2) + (fm.getHeight() / 2);
+
+		g.setColor(foreground);
+		g.setFont(font);
+		g.drawString(text, tx, ty);
+	}
+
+}

src/com/mobileread/ixtab/kindlelauncher/ui/v2/JUIAdapter.java

 		// these are Touch models, so having more information on one page seems reasonable.
 		return 10;
 	}
-
 }