浏览代码

Perform miscellaneous cleanup.

Sam Jaffe 5 年之前
父节点
当前提交
d5a19395b3

+ 19 - 0
src/main/lombok/org/leumasjaffe/recipe/RecipeManager.java

@@ -1,13 +1,32 @@
 package org.leumasjaffe.recipe;
 
+import java.awt.Font;
+import java.util.Enumeration;
+
+import javax.swing.UIManager;
+import javax.swing.plaf.FontUIResource;
+
 import org.leumasjaffe.recipe.view.RecipeManagerFrame;
 
 import lombok.experimental.UtilityClass;
 
 @UtilityClass
 public class RecipeManager {
+	
+	public static void setUIFont(FontUIResource f){
+		Enumeration<Object> keys = UIManager.getDefaults().keys();
+		while (keys.hasMoreElements()) {
+			Object key = keys.nextElement();
+			Object value = UIManager.get(key);
+			if (value instanceof FontUIResource) {
+				UIManager.put(key, f);
+			}
+		}
+	} 
+
 
 	public void main(String[] args) {
+		setUIFont(new FontUIResource("Verdana",Font.PLAIN,10));
 		new RecipeManagerFrame().setVisible(true);
 	}
 

+ 1 - 1
src/main/lombok/org/leumasjaffe/recipe/view/AutoGrowPanel.java

@@ -78,7 +78,7 @@ public class AutoGrowPanel extends JPanel {
 	@SafeVarargs
 	public <T, C extends Component & DocumentListenable> AutoGrowPanel(Function<T, C> function,
 			Supplier<T> newItem, Consumer<? super T> onData, IntConsumer onDelete, T...ts) {
-		setLayout(new VerticalLayout(5));
+		setLayout(new VerticalLayout());
 		
 		T next = newItem.get();
 		this.onDelete = onDelete;

+ 2 - 1
src/main/lombok/org/leumasjaffe/recipe/view/DurationPanel.java

@@ -26,7 +26,7 @@ public class DurationPanel extends JPanel {
 		gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE};
 		setLayout(gridBagLayout);
 		
-		JLabel lblName = new JLabel(name + ": ");
+		JLabel lblName = new JLabel(name);
 		GridBagConstraints gbc_lblName = new GridBagConstraints();
 		gbc_lblName.insets = new Insets(0, 0, 0, 5);
 		gbc_lblName.gridx = 0;
@@ -34,6 +34,7 @@ public class DurationPanel extends JPanel {
 		add(lblName, gbc_lblName);
 		
 		txtTime = new JFormattedTextField(new DurationFormatter());
+		txtTime.setColumns(8);
 		GridBagConstraints gbc_txtTime = new GridBagConstraints();
 		gbc_txtTime.gridx = 1;
 		gbc_txtTime.gridy = 0;

+ 0 - 4
src/main/lombok/org/leumasjaffe/recipe/view/IngredientPanel.java

@@ -19,7 +19,6 @@ import lombok.Getter;
 import lombok.experimental.FieldDefaults;
 
 import javax.swing.JFormattedTextField;
-import java.awt.Font;
 import javax.swing.JLabel;
 
 @SuppressWarnings("serial")
@@ -49,7 +48,6 @@ public class IngredientPanel extends JPanel implements AutoGrowPanel.DocumentLis
 		add(label, gbc_label);
 		
 		txtName = new JTextField();
-		txtName.setFont(new Font("Source Code Pro", Font.PLAIN, 10));
 		GridBagConstraints gbc_txtName = new GridBagConstraints();
 		gbc_txtName.fill = GridBagConstraints.HORIZONTAL;
 		gbc_txtName.insets = new Insets(0, 0, 0, 5);
@@ -59,7 +57,6 @@ public class IngredientPanel extends JPanel implements AutoGrowPanel.DocumentLis
 		txtName.setColumns(10);
 		
 		txtAmount = new JFormattedTextField(new AmountFormatter());
-		txtAmount.setFont(new Font("Source Code Pro", Font.PLAIN, 10));
 		GridBagConstraints gbc_txtAmount = new GridBagConstraints();
 		gbc_txtAmount.fill = GridBagConstraints.HORIZONTAL;
 		gbc_txtAmount.insets = new Insets(0, 0, 0, 5);
@@ -69,7 +66,6 @@ public class IngredientPanel extends JPanel implements AutoGrowPanel.DocumentLis
 		txtAmount.setColumns(11);
 		
 		txtPreparation = new JTextField();
-		txtPreparation.setFont(new Font("Source Code Pro", Font.PLAIN, 10));
 		GridBagConstraints gbc_txtPreparation = new GridBagConstraints();
 		gbc_txtPreparation.anchor = GridBagConstraints.ABOVE_BASELINE;
 		gbc_txtPreparation.fill = GridBagConstraints.HORIZONTAL;

+ 0 - 4
src/main/lombok/org/leumasjaffe/recipe/view/IngredientPreparationPanel.java

@@ -16,7 +16,6 @@ import lombok.Getter;
 import lombok.experimental.FieldDefaults;
 
 import javax.swing.JFormattedTextField;
-import java.awt.Font;
 import javax.swing.JLabel;
 
 @SuppressWarnings("serial")
@@ -46,7 +45,6 @@ public class IngredientPreparationPanel extends JPanel {
 		
 		txtName = new JTextField();
 		txtName.setEditable(false);
-		txtName.setFont(new Font("Source Code Pro", Font.PLAIN, 10));
 		GridBagConstraints gbc_txtName = new GridBagConstraints();
 		gbc_txtName.fill = GridBagConstraints.HORIZONTAL;
 		gbc_txtName.insets = new Insets(0, 0, 0, 5);
@@ -57,7 +55,6 @@ public class IngredientPreparationPanel extends JPanel {
 		
 		txtAmount = new JFormattedTextField(new AmountFormatter());
 		txtAmount.setEditable(false);
-		txtAmount.setFont(new Font("Source Code Pro", Font.PLAIN, 10));
 		GridBagConstraints gbc_txtAmount = new GridBagConstraints();
 		gbc_txtAmount.fill = GridBagConstraints.HORIZONTAL;
 		gbc_txtAmount.insets = new Insets(0, 0, 0, 5);
@@ -68,7 +65,6 @@ public class IngredientPreparationPanel extends JPanel {
 		
 		txtPreparation = new JTextField();
 		txtPreparation.setEditable(false);
-		txtPreparation.setFont(new Font("Source Code Pro", Font.PLAIN, 10));
 		GridBagConstraints gbc_txtPreparation = new GridBagConstraints();
 		gbc_txtPreparation.anchor = GridBagConstraints.ABOVE_BASELINE;
 		gbc_txtPreparation.fill = GridBagConstraints.HORIZONTAL;

+ 3 - 4
src/main/lombok/org/leumasjaffe/recipe/view/PreparationPanel.java

@@ -58,27 +58,26 @@ public class PreparationPanel extends JPanel {
 		JLabel lblIndex = new JLabel("Prep");
 		GridBagConstraints gbc_lblIndex = new GridBagConstraints();
 		gbc_lblIndex.fill = GridBagConstraints.HORIZONTAL;
-		gbc_lblIndex.insets = new Insets(0, 0, 5, 5);
+		gbc_lblIndex.insets = new Insets(0, 0, 0, 5);
 		gbc_lblIndex.gridx = 0;
 		gbc_lblIndex.gridy = 0;
 		panelLeft.add(lblIndex, gbc_lblIndex);
 		
 		Component horizontalGlue = Box.createHorizontalGlue();
 		GridBagConstraints gbc_horizontalGlue = new GridBagConstraints();
-		gbc_horizontalGlue.insets = new Insets(0, 0, 5, 5);
+		gbc_horizontalGlue.insets = new Insets(0, 0, 0, 5);
 		gbc_horizontalGlue.gridx = 1;
 		gbc_horizontalGlue.gridy = 0;
 		panelLeft.add(horizontalGlue, gbc_horizontalGlue);
 		
 		DurationPanel panelDuration = new DurationPanel("Requires", Duration.ZERO);
 		GridBagConstraints gbc_panelDuration = new GridBagConstraints();
-		gbc_panelDuration.insets = new Insets(0, 0, 5, 0);
 		gbc_panelDuration.gridx = 2;
 		gbc_panelDuration.gridy = 0;
 		panelLeft.add(panelDuration, gbc_panelDuration);
 		
 		JPanel panelIngredients = new JPanel();
-		panelIngredients.setLayout(new VerticalLayout(5));
+		panelIngredients.setLayout(new VerticalLayout());
 		GridBagConstraints gbc_panelIngredients = new GridBagConstraints();
 		gbc_panelIngredients.gridwidth = 3;
 		gbc_panelIngredients.insets = new Insets(0, 0, 0, 5);

+ 2 - 3
src/main/lombok/org/leumasjaffe/recipe/view/StepPanel.java

@@ -63,21 +63,20 @@ public class StepPanel extends JPanel implements AutoGrowPanel.DocumentListenabl
 		lblIndex = new JLabel("");
 		GridBagConstraints gbc_lblIndex = new GridBagConstraints();
 		gbc_lblIndex.fill = GridBagConstraints.HORIZONTAL;
-		gbc_lblIndex.insets = new Insets(0, 0, 5, 5);
+		gbc_lblIndex.insets = new Insets(0, 0, 0, 5);
 		gbc_lblIndex.gridx = 0;
 		gbc_lblIndex.gridy = 0;
 		panelLeft.add(lblIndex, gbc_lblIndex);
 		
 		Component horizontalGlue = Box.createHorizontalGlue();
 		GridBagConstraints gbc_horizontalGlue = new GridBagConstraints();
-		gbc_horizontalGlue.insets = new Insets(0, 0, 5, 5);
+		gbc_horizontalGlue.insets = new Insets(0, 0, 0, 5);
 		gbc_horizontalGlue.gridx = 1;
 		gbc_horizontalGlue.gridy = 0;
 		panelLeft.add(horizontalGlue, gbc_horizontalGlue);
 		
 		DurationPanel panelDuration = new DurationPanel("Requires", step.getDuration());
 		GridBagConstraints gbc_panelDuration = new GridBagConstraints();
-		gbc_panelDuration.insets = new Insets(0, 0, 5, 0);
 		gbc_panelDuration.gridx = 2;
 		gbc_panelDuration.gridy = 0;
 		panelLeft.add(panelDuration, gbc_panelDuration);

+ 13 - 0
src/main/lombok/org/leumasjaffe/recipe/view/formatter/AmountFormatter.java

@@ -1,5 +1,6 @@
 package org.leumasjaffe.recipe.view.formatter;
 
+import java.text.DecimalFormat;
 import java.text.ParseException;
 
 import javax.swing.text.DefaultFormatter;
@@ -15,6 +16,7 @@ public class AmountFormatter extends DefaultFormatter {
 	
 	public AmountFormatter() {
 		setCommitsOnValidEdit(false);
+		setOverwriteMode(false);
 	}
 
 	@Override
@@ -30,5 +32,16 @@ public class AmountFormatter extends DefaultFormatter {
 		// the validity of the unit type.
 		return new Amount(text);
 	}
+	
+	@Override
+	public String valueToString(Object value) throws ParseException {
+		final Amount amt = Amount.class.cast(value);
+		if (amt == null) {
+			return "";
+		}
+		final DecimalFormat df = new DecimalFormat("0");
+		df.setMaximumFractionDigits(2);
+		return df.format(amt.getValue()) + " " + amt.unitName();
+	}
 
 }

+ 1 - 0
src/main/lombok/org/leumasjaffe/recipe/view/formatter/DurationFormatter.java

@@ -15,6 +15,7 @@ public class DurationFormatter extends DefaultFormatter {
 	
 	public DurationFormatter() {
 		setCommitsOnValidEdit(false);
+		setOverwriteMode(false);
 	}
 
 	@Override

+ 1 - 1
src/main/lombok/org/leumasjaffe/recipe/view/summary/ElementPanel.java

@@ -34,7 +34,7 @@ public class ElementPanel extends JPanel {
 		
 		lblProductName = new JLabel(element.getName());
 		GridBagConstraints gbc_lblProductName = new GridBagConstraints();
-		gbc_lblProductName.insets = new Insets(0, 0, 5, 5);
+		gbc_lblProductName.insets = new Insets(0, 0, 0, 5);
 		gbc_lblProductName.gridx = 0;
 		gbc_lblProductName.gridy = 0;
 		add(lblProductName, gbc_lblProductName);

+ 0 - 3
src/main/lombok/org/leumasjaffe/recipe/view/summary/IngredientPanel.java

@@ -14,7 +14,6 @@ import lombok.Getter;
 import lombok.experimental.FieldDefaults;
 
 import javax.swing.JFormattedTextField;
-import java.awt.Font;
 import javax.swing.JLabel;
 
 @SuppressWarnings("serial")
@@ -41,7 +40,6 @@ public class IngredientPanel extends JPanel {
 		
 		txtName = new JTextField();
 		txtName.setEditable(false);
-		txtName.setFont(new Font("Source Code Pro", Font.PLAIN, 10));
 		GridBagConstraints gbc_txtName = new GridBagConstraints();
 		gbc_txtName.fill = GridBagConstraints.HORIZONTAL;
 		gbc_txtName.insets = new Insets(0, 0, 0, 5);
@@ -52,7 +50,6 @@ public class IngredientPanel extends JPanel {
 		
 		txtAmount = new JFormattedTextField(new AmountFormatter());
 		txtAmount.setEditable(false);
-		txtAmount.setFont(new Font("Source Code Pro", Font.PLAIN, 10));
 		GridBagConstraints gbc_txtAmount = new GridBagConstraints();
 		gbc_txtAmount.fill = GridBagConstraints.HORIZONTAL;
 		gbc_txtAmount.gridx = 2;

+ 0 - 2
src/main/lombok/org/leumasjaffe/recipe/view/summary/SummaryPanel.java

@@ -20,7 +20,6 @@ import org.leumasjaffe.recipe.view.ImagePanel;
 
 import lombok.AccessLevel;
 import lombok.experimental.FieldDefaults;
-import java.awt.Font;
 
 @SuppressWarnings("serial")
 @FieldDefaults(level=AccessLevel.PRIVATE)
@@ -109,7 +108,6 @@ public class SummaryPanel extends JPanel {
 		panel.add(panelPhoto, gbc_panelPhoto);
 		
 		txaDesription = new JTextArea(5, 20);
-		txaDesription.setFont(new Font("Verdana", Font.PLAIN, 10));
 		txaDesription.setWrapStyleWord(true);
 		txaDesription.setLineWrap(true);
 		GridBagConstraints gbc_txaDesription = new GridBagConstraints();