summaryrefslogtreecommitdiff
path: root/src/bjc/imgchain/utils
diff options
context:
space:
mode:
authorBenjamin Culkin <bjculkin@mix.wvu.edu>2018-04-26 05:48:09 -0700
committerBenjamin Culkin <bjculkin@mix.wvu.edu>2018-04-26 05:48:09 -0700
commiteab6df10ab8292a59a05b25d18c413dd107bb94a (patch)
tree9b147cbb61463d4a74d1a7dbc07f3273316fc670 /src/bjc/imgchain/utils
parent697bc0bae293a9f31c00f6e10f33955151228f64 (diff)
Initial commit
Diffstat (limited to 'src/bjc/imgchain/utils')
-rw-r--r--src/bjc/imgchain/utils/ImmutableTableModel.java17
-rw-r--r--src/bjc/imgchain/utils/LabeledInputPanel.java42
-rw-r--r--src/bjc/imgchain/utils/Utils.java54
3 files changed, 113 insertions, 0 deletions
diff --git a/src/bjc/imgchain/utils/ImmutableTableModel.java b/src/bjc/imgchain/utils/ImmutableTableModel.java
new file mode 100644
index 0000000..515f0a0
--- /dev/null
+++ b/src/bjc/imgchain/utils/ImmutableTableModel.java
@@ -0,0 +1,17 @@
+package bjc.imgchain.utils;
+
+import javax.swing.table.DefaultTableModel;
+
+public class ImmutableTableModel extends DefaultTableModel {
+ private static final long serialVersionUID = 6459890821518409439L;
+
+ public ImmutableTableModel(Object[][] data, Object[] columnNames) {
+ super(data, columnNames);
+ }
+
+
+ @Override
+ public boolean isCellEditable(int row, int column) {
+ return false;
+ }
+} \ No newline at end of file
diff --git a/src/bjc/imgchain/utils/LabeledInputPanel.java b/src/bjc/imgchain/utils/LabeledInputPanel.java
new file mode 100644
index 0000000..7eed8b0
--- /dev/null
+++ b/src/bjc/imgchain/utils/LabeledInputPanel.java
@@ -0,0 +1,42 @@
+package bjc.imgchain.utils;
+
+import java.awt.BorderLayout;
+
+import javax.swing.JFormattedTextField;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+/**
+ * A component for getting formatted input with a label.
+ *
+ * @author bjculkin
+ *
+ */
+public class LabeledInputPanel extends JPanel {
+ private static final long serialVersionUID = 1031310890698539040L;
+
+ /**
+ * The field input is stored in.
+ */
+ public final JFormattedTextField field;
+
+ /**
+ * Create a new labeled input component.
+ *
+ * @param label
+ * The label for the component.
+ * @param val
+ * The initial value for the field.
+ */
+ public LabeledInputPanel(String label, Object val) {
+ super();
+ setLayout(new BorderLayout());
+
+ JLabel xLabel = new JLabel(label);
+
+ field = new JFormattedTextField(val);
+
+ add(xLabel, BorderLayout.LINE_START);
+ add(field, BorderLayout.CENTER);
+ }
+} \ No newline at end of file
diff --git a/src/bjc/imgchain/utils/Utils.java b/src/bjc/imgchain/utils/Utils.java
new file mode 100644
index 0000000..38e2ec2
--- /dev/null
+++ b/src/bjc/imgchain/utils/Utils.java
@@ -0,0 +1,54 @@
+package bjc.imgchain.utils;
+
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.image.BufferedImage;
+
+public class Utils {
+ public static BufferedImage toBuffered(Image img) {
+ if (img instanceof BufferedImage) {
+ return (BufferedImage) img;
+ }
+
+ /*
+ * Create a buffered image with transparency
+ */
+ BufferedImage bufimg = new BufferedImage(img.getWidth(null), img.getHeight(null),
+ BufferedImage.TYPE_INT_ARGB);
+
+ /*
+ * Draw the image on to the buffered image
+ */
+ Graphics2D graph = bufimg.createGraphics();
+ graph.drawImage(img, 0, 0, null);
+ graph.dispose();
+
+ /*
+ * Return the buffered image
+ */
+ return bufimg;
+ }
+
+ public static int[] toARGBQuad(int rbg) {
+ return new int[] { (rbg >> 24) & 0xff, (rbg >> 16) & 0xff, (rbg >> 8) & 0xff, rbg & 0xff };
+ }
+
+ public static int fromARGBQuad(int[] argb) {
+ return (argb[0] << 24) | (argb[1] << 16) | (argb[2] << 8) | argb[3];
+ }
+
+ public static int[][] padarray(int[][] arr, int padWith, int numOfPads) {
+ int[][] temp = new int[arr.length + numOfPads * 2][arr[0].length + numOfPads * 2];
+ for (int i = 0; i < temp.length; i++) {
+ for (int j = 0; j < temp[i].length; j++) {
+ temp[i][j] = padWith;
+ }
+ }
+ for (int i = 0; i < arr.length; i++) {
+ for (int j = 0; j < arr[i].length; j++) {
+ temp[i + numOfPads][j + numOfPads] = arr[i][j];
+ }
+ }
+ return temp;
+ }
+}