From 789e708f694e0fd9b9d88c574c1b869bacfde621 Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Fri, 17 Oct 2008 19:49:29 -0500 Subject: [PATCH] Began work on PunchcardDisplayDialog to display timestamps on various timelines. Modified build file to clean additional files (logs, etc) committer: Jonathan Bernard --- build.xml | 10 ++ nbproject/private/private.properties | 1 + nbproject/private/private.xml | 4 - .../timestamper/PunchcardDisplayDialog.form | 65 +++++++++ .../timestamper/PunchcardDisplayDialog.java | 100 +++++++++++++ .../timestamper/TimelineDayDisplay.java | 136 ++++++++++++++++++ test-timeline.txt | Bin 0 -> 5680 bytes 7 files changed, 312 insertions(+), 4 deletions(-) create mode 100755 src/jdbernard/timestamper/PunchcardDisplayDialog.form create mode 100755 src/jdbernard/timestamper/PunchcardDisplayDialog.java create mode 100755 src/jdbernard/timestamper/TimelineDayDisplay.java create mode 100755 test-timeline.txt diff --git a/build.xml b/build.xml index 574c0b4..c6bbd56 100755 --- a/build.xml +++ b/build.xml @@ -82,4 +82,14 @@ + + + + + + + + + + diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties index 1974116..30d5b4c 100755 --- a/nbproject/private/private.properties +++ b/nbproject/private/private.properties @@ -4,3 +4,4 @@ javac.debug=true javadoc.preview=true jaxws.endorsed.dir=C:\\Program Files\\NetBeans 6.1\\java2\\modules\\ext\\jaxws21\\api user.properties.file=C:\\Documents and Settings\\jbernard\\.netbeans\\6.1\\build.properties +axis2.deploy.war=C:\\Program Files\\glassfish-v2ur2\\domains\\domain1\\autodeploy\\axis2.war diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml index f3fb4c5..c1f155a 100755 --- a/nbproject/private/private.xml +++ b/nbproject/private/private.xml @@ -1,8 +1,4 @@ - - file:/C:/Documents%20and%20Settings/jbernard/My%20Documents/Development/TimeStamper/src/jdbernard/timestamper/TimeStamperApp.java - file:/C:/Documents%20and%20Settings/jbernard/My%20Documents/Development/TimeStamper/src/jdbernard/timestamper/TimeStamperView.java - diff --git a/src/jdbernard/timestamper/PunchcardDisplayDialog.form b/src/jdbernard/timestamper/PunchcardDisplayDialog.form new file mode 100755 index 0000000..e1b8c0f --- /dev/null +++ b/src/jdbernard/timestamper/PunchcardDisplayDialog.form @@ -0,0 +1,65 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/jdbernard/timestamper/PunchcardDisplayDialog.java b/src/jdbernard/timestamper/PunchcardDisplayDialog.java new file mode 100755 index 0000000..7f7c9e7 --- /dev/null +++ b/src/jdbernard/timestamper/PunchcardDisplayDialog.java @@ -0,0 +1,100 @@ +/* + * PunchcardDisplayDialog.java + * + * Created on October 16, 2008, 4:37 PM + */ + +package jdbernard.timestamper; + +import java.io.File; +import java.util.Calendar; + +/** + * + * @author jbernard + */ +public class PunchcardDisplayDialog extends javax.swing.JDialog { + + /** Creates new form PunchcardDisplayDialog */ + public PunchcardDisplayDialog(java.awt.Frame parent, boolean modal) { + super(parent, modal); + initComponents(); + timelineDayDisplay1.setDay(Calendar.getInstance()); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + timelineDayDisplay1 = new jdbernard.timestamper.TimelineDayDisplay(); + + setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); + setName("Form"); // NOI18N + + timelineDayDisplay1.setName("timelineDayDisplay1"); // NOI18N + + javax.swing.GroupLayout timelineDayDisplay1Layout = new javax.swing.GroupLayout(timelineDayDisplay1); + timelineDayDisplay1.setLayout(timelineDayDisplay1Layout); + timelineDayDisplay1Layout.setHorizontalGroup( + timelineDayDisplay1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 380, Short.MAX_VALUE) + ); + timelineDayDisplay1Layout.setVerticalGroup( + timelineDayDisplay1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGap(0, 278, Short.MAX_VALUE) + ); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(timelineDayDisplay1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(timelineDayDisplay1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addContainerGap()) + ); + + pack(); + }// //GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(String args[]) throws Exception { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + PunchcardDisplayDialog dialog = new PunchcardDisplayDialog(new javax.swing.JFrame(), true); + try { dialog.timelineDayDisplay1.setTimeline(Timeline.readFromFile("test-timeline.txt")); } + catch (Exception e) { + System.err.println("Could not open timeline text."); + try { new File("PLACE_HERE").createNewFile(); } + catch (Exception e1) {} + } + dialog.addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + }); + dialog.setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private jdbernard.timestamper.TimelineDayDisplay timelineDayDisplay1; + // End of variables declaration//GEN-END:variables + + private Timeline timeline; +} diff --git a/src/jdbernard/timestamper/TimelineDayDisplay.java b/src/jdbernard/timestamper/TimelineDayDisplay.java new file mode 100755 index 0000000..cf64a7c --- /dev/null +++ b/src/jdbernard/timestamper/TimelineDayDisplay.java @@ -0,0 +1,136 @@ +/* TimelineDayDisplay.java + * Author: Jonathan Bernard - jonathan.bernard@gemalto.com + */ + +package jdbernard.timestamper; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Insets; +import java.awt.Rectangle; +import java.awt.geom.Rectangle2D; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Iterator; +import javax.swing.JComponent; +import javax.swing.JLabel; + +/** + * + * @author jbernard + */ +public class TimelineDayDisplay extends JComponent { + + private Timeline timeline; + private Calendar day; + + private final Color evenTrans = new Color(0.75f, 0.75f, 0.75f, 0.4f); + private final Color evenOpaque = new Color(0.75f, 0.75f, 0.75f, 1f); + private final Color oddTrans = new Color(0.5f, 0.5f, 0.5f, 0.4f); + private final Color oddOpaque = new Color(0.5f, 0.5f, 0.5f, 1f); + + public TimelineDayDisplay() { + super(); + } + + public TimelineDayDisplay(Timeline timeline, Calendar day) { + super(); + this.timeline = timeline; + this.day = day; + } + + public void setTimeline(Timeline t) { + timeline = t; + } + + public Timeline getTimeline() { + return timeline; + } + + public void setDay(Calendar d) { + day = d; + day.set(Calendar.HOUR_OF_DAY, 0); + day.set(Calendar.MINUTE, 0); + day.set(Calendar.SECOND, 0); + } + + public Calendar getDay() { + return day; + } + + @Override + public void paintComponent(Graphics g) { + Insets insets = this.getInsets(); + Rectangle bounds = this.getBounds(); + Rectangle canvasBounds = new Rectangle(insets.left, insets.top, + bounds.width - insets.left - insets.right - 1, + bounds.height - insets.top - insets.bottom - 1); + + Calendar nextDay = Calendar.getInstance(); + nextDay.setTime(day.getTime()); + nextDay.add(Calendar.DAY_OF_YEAR, 1); + + Graphics2D g2d = (Graphics2D) g; + double hourHeight = canvasBounds.getHeight() / 24.0; + long oneDayInMilli = (24 * 60 * 60 * 1000); + Rectangle2D stringBounds = getFontMetrics(getFont()).getStringBounds("00:00 ", g); + for (int i = 1; i < 24; i++) { + int lineY = (int) Math.round(hourHeight * (double) i); + g.drawLine(canvasBounds.x + (int) stringBounds.getWidth(), canvasBounds.y + lineY, + canvasBounds.x + canvasBounds.width, + canvasBounds.y + lineY); + + if ((hourHeight > (stringBounds.getHeight()) || ((i % 2) == 0))) { + g.drawString(String.format("%1$02d:00", i), + canvasBounds.x + 2, lineY + (int) (stringBounds.getHeight() / 2)); + } + } + + Timeline.TimelineMarker tm = timeline.getLastMarker(day.getTime()); + Iterator itr = timeline.iterator(); + + while (!itr.next().equals(tm)); + + ArrayList markers = new ArrayList(); + while (nextDay.getTime().after(tm.getTimestamp())) { + markers.add(tm); + if (itr.hasNext()) tm = itr.next(); + else break; + } + + markers.add(tm); + + for (int i = 0; i < markers.size(); i++) { + int boxY = 0; + int boxHeight = 1; + if (i != 0) { + double relTime = markers.get(i).getTimestamp().getTime() - day.getTimeInMillis(); + boxY = (int) Math.round((relTime / oneDayInMilli) + * canvasBounds.getHeight()) + canvasBounds.y; + } + if (i == markers.size() - 1) { + double relTime = nextDay.getTime().getTime() + - markers.get(i).getTimestamp().getTime(); + boxHeight = (int) Math.round(relTime / oneDayInMilli + * canvasBounds.getHeight()); + } else { + double relTime = markers.get(i + 1).getTimestamp().getTime() + - markers.get(i).getTimestamp().getTime(); + boxHeight = (int) Math.round(relTime / oneDayInMilli + * canvasBounds.getHeight()); + } + g.setColor((i % 2 == 0 ? evenTrans : oddTrans)); + g.fillRect(canvasBounds.x + (int) stringBounds.getWidth() + 5, boxY, + canvasBounds.x + canvasBounds.width, boxHeight); + g2d.setColor((i % 2 == 0 ? evenOpaque : oddOpaque)); + g2d.setStroke(new BasicStroke(3f)); + g2d.drawRect(canvasBounds.x + (int) stringBounds.getWidth() + 5, boxY, + canvasBounds.x + canvasBounds.width, boxHeight); + } + + g.setColor(Color.BLACK); + g.drawRect(canvasBounds.x, canvasBounds.y, canvasBounds.width, canvasBounds.height); + } +} diff --git a/test-timeline.txt b/test-timeline.txt new file mode 100755 index 0000000000000000000000000000000000000000..1cb120c5a4c26b4683c43502b7bba388ea4405eb GIT binary patch literal 5680 zcmcgwO>^2v5arCTXrHpFN(d5?F>~73`En{wQ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