//package tideCalendar; import javax.swing.*; import javax.swing.plaf.basic.BasicArrowButton; import javax.swing.plaf.basic.BasicScrollBarUI; import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.GregorianCalendar; import java.util.LinkedList; import java.util.ListIterator; import java.util.Vector; import java.util.Timer; import java.util.TimerTask; import java.awt.geom.*; /** * Contains the implementation of the Calendar View for Earthguide's * Tide Calendar. * **/ public class CalendarFrame extends JPanel { /* GLOBAL VARIABLES * * week- is the amount of days before (or after) the start of the * currently Selected month. * * redraw- Whether or not to have the Month Select buttons redraw the * main screen when clicked. Will probably be removed. * * selected- Whether or not a day has been selected. * * monthColors- an array of the colors that the Months are drawn in. * * monthPanel- the main window which contains the calendar. * * titlePanel- the panel that contains the title and the back button. * * monthButton- the array of the buttons used to switch between months * * acceptButton- the button used to return to the continuous view. * * factory- a Java object that manages memory for popups. The basic * premise is that it is used to create the popups and will reuse * the same memory for popups so that popups can be created and * destroyed with impunity * * popup- The glorious popup. Currently used to display highs and lows * * titleImage- as the name implies, it is the image used for our title. * * bottomImage- Earthguide logo image * * tempCal- used to find the day of the weeks. * * weekSelector- used to around the weeks of a month. * * end- no current use, but was used for displaying popup warning messages. * Timer- a object that runs timerTasks. No current use * myMoon- an object that contains the phases of the moon. * moonVector- an object that contains the list of pictures for the moon */ private int week = 0; private boolean redraw = true; private boolean selected = false; private final Color[] monthColors = {Format.CAL_MONTH1, Format.CAL_MONTH2}; private final Color[] dayColors = {Format.CAL_DATECOLOR2, Format.CAL_DATECOLOR1}; private JPanel monthPanel; private JPanel titlePanel; private JButton[] monthButton; private JButton acceptButton; // private PopupFactory factory = PopupFactory.getSharedInstance(); // private Popup popup; private ImageIcon titleImage=Shared.loadImage("new_banner.jpg", 9800, this); // private ImageIcon bottomImage = new ImageIcon("tide_bottom.gif"); private GregorianCalendar tempCal; private JButton weekSelector; private final Rectangle calBounds = new Rectangle(X_OFFSET+DATE_WIDTH*7-55, Y_OFFSET+DATE_HEIGHT*5+43 - 17,67,17); private final Rectangle contBounds = new Rectangle (X_OFFSET,Y_OFFSET+DATE_HEIGHT*5+43 - 17,90,17); private final Rectangle bounds = new Rectangle(X_OFFSET,Y_OFFSET+30, 7*DATE_WIDTH,5*DATE_HEIGHT); private final Rectangle upBounds = new Rectangle(X_OFFSET+7*DATE_WIDTH+5, Y_OFFSET + 5*DATE_HEIGHT - 20, 24, 24); private final Rectangle downBounds = new Rectangle(X_OFFSET+7*DATE_WIDTH+5, Y_OFFSET + 5*DATE_HEIGHT + 5, 24, 24); /*private TimerTask end = new TimerTask() { public void run() { if (popup != null) { popup.hide(); popup = null; } } };*/ private Timer timer = new Timer(); private LinkedList ylocation = new LinkedList(); private LinkedList xlocation = new LinkedList(); private Moon myMoon = new Moon(); private Vector moonVector = new Vector(35); private ImageIcon upImage = Shared.loadImage("up.gif", 150, this); private ImageIcon downImage = Shared.loadImage("down.gif", 150, this); private ActionListener weekUp = new ActionListener() { public void actionPerformed(ActionEvent e) { } }; private ActionListener weekDown = new ActionListener() { public void actionPerformed(ActionEvent e) { } }; /** * Creates the Calendar. */ public CalendarFrame() { super(new BorderLayout()); tempCal = new GregorianCalendar(Shared.year, Shared.currentMonth, 1); //create the Title which will appear at the top of the screen. createTitle(); //create the side panel which contains the week selection buttons. monthButton = new JButton[12]; //Load the moon phases into our Moon object. myMoon.moonReader("moonCharts/moonChart"+Shared.year); // creates the monthButtons, which are now just abstract placeholders. // The actual buttons are located in the monthPanel on a header attached // to the calendar. makeMonthButtons(); // The panel which contains the actual Calendar. monthPanel = new JPanel() { public void paintComponent(Graphics g) { super.paintComponent(g); drawDays(g); } }; monthPanel.setBackground(Format.CAL_MAIN); //monthPanel.setBackground(Color.magenta); //Adds two listener that look for two things: // A) On the mouse clicked, the user is "selecting" a day or a month. // B) When the mouse moves over a day, the Highs and Lows for the day // will popup. monthPanel.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { Point p = e.getPoint(); // A rectangle that contains the calendar (but not the month // header) Rectangle bounds = new Rectangle(X_OFFSET,Y_OFFSET+30, 7*DATE_WIDTH,5*DATE_HEIGHT); if (bounds.contains(p))//if point is inside calendar { //in case they clicked on an invalid day (e.g. before Jan. 1) int tempClicked = Shared.currentDay; Shared.currentDay = 2-tempCal.get(tempCal.DAY_OF_WEEK)+week; //one day per box to the left Shared.currentDay += (p.x-X_OFFSET) / DATE_WIDTH; // seven days per box down Shared.currentDay += (p.y-Y_OFFSET-30) / DATE_HEIGHT * 7; //If they clicked before Jan 1 or after Dec. 31, reset day and //pretend like the user didn't click. if ( (Shared.currentDay < 1 && Shared.currentMonth == 0) || (Shared.currentDay > Shared.monthEnd[Shared.currentMonth] && Shared.currentMonth == 11)) { //clicked on an invalid month. Shared.currentDay = tempClicked; } /* <> include a section for clicking on a day that is * too far in the year to graph in a full week(e.g. Dec. 29). * when this happens, move the day back to the latest time /* that can still be graphed with a week of following data.*/ else {//they clicked on a day int days = Shared.monthToDay(Shared.currentMonth) + Shared.currentDay; //acceptButton.setText(Shared.toMonth(days)); selected = true; // <> Update popup to correct day. } //redraw screen to reflect update. monthPanel.repaint(monthPanel.getVisibleRect()); return; } // now check to see if the user clicked on a month rather than // on a day. bounds = new Rectangle(X_OFFSET,Y_OFFSET,7*DATE_WIDTH,30); if (bounds.contains(p)) {//selecting a month //redo so it isn't in a loop. Because loops suck compared to //math. <> for (int i = 0; i < 12; i++) { bounds = new Rectangle(X_OFFSET+i*42,Y_OFFSET,42,30); if (bounds.contains(p)) monthButton[i].doClick(); } return; } // then check to see if they clicked on either of the week // selection buttons. bounds = new Rectangle(X_OFFSET+7*DATE_WIDTH+5, Y_OFFSET+5*DATE_HEIGHT-20,25,50); if (bounds.contains(p)) { if (p.y < Y_OFFSET+5*DATE_HEIGHT+5)// up { if (Shared.currentMonth > 0 || week > 0) { week -= 7; int i = 2-tempCal.get(tempCal.DAY_OF_WEEK)+week; if (Shared.currentMonth > 0 && Shared.monthEnd[Shared.currentMonth-1] <= -i + 1) { redraw = false; monthButton[--Shared.currentMonth].doClick(); redraw = true; } moonVector.clear(); monthPanel.repaint(monthPanel.getVisibleRect()); } } else //down { if (Shared.currentMonth < 11 || week < 1) { int i; week += 7; i = 2-tempCal.get(tempCal.DAY_OF_WEEK)+week; i = Shared.monthEnd[Shared.currentMonth] - i; if (Shared.monthEnd[Shared.currentMonth] < 42 - i) { redraw = false; monthButton[++Shared.currentMonth].doClick(); if (i >= 6) week -= 7; redraw = true; } moonVector.clear(); monthPanel.repaint(monthPanel.getVisibleRect()); } } return; } // Finally check to see if they want to change to Continuous view bounds = new Rectangle(X_OFFSET-5, Y_OFFSET+DATE_HEIGHT*5+30,83,18); if (bounds.contains(p)) acceptButton.doClick(); //change to 2005 bounds = new Rectangle(X_OFFSET + 100, Y_OFFSET - 24, 36, 17); int index1 = 0, index2 = 0; if (Shared.year != 2005 && bounds.contains(p)) { Shared.year = 2005; if (Shared.parameterArray[0] != null) { for (index1 = 0; index1 < Shared.lines.length; ++index1) { if (Shared.lines[index1].toString().equals(Shared.parameterArray[0].getLine().toString())) break; } } if (Shared.parameterArray[1] != null) { for (index2 = 0; index2 < Shared.lines.length; ++index2) { if (Shared.lines[index2].toString().equals(Shared.parameterArray[1].getLine().toString())) break; } } Shared.setLines(); if (Shared.parameterArray[0] != null) Shared.parameterArray[0] = Grapher.fileReader(Shared.lines[index1]); if (Shared.parameterArray[1] != null) Shared.parameterArray[1] = Grapher.fileReader(Shared.lines[index2]); monthPanel.repaint(monthPanel.getVisibleRect()); } //change to 2006 bounds = new Rectangle(X_OFFSET + 150, Y_OFFSET - 24, 36, 17); if (Shared.year != 2006 && bounds.contains(p)) { Shared.year = 2006; if (Shared.parameterArray[0] != null) { for (index1 = 0; index1 < Shared.lines.length; ++index1) { if (Shared.lines[index1].toString().equals(Shared.parameterArray[0].getLine().toString())) break; } } if (Shared.parameterArray[1] != null) { for (index2 = 0; index2 < Shared.lines.length; ++index2) { if (Shared.lines[index2].toString().equals(Shared.parameterArray[1].getLine().toString())) break; } } Shared.setLines(); if (Shared.parameterArray[0] != null) Shared.parameterArray[0] = Grapher.fileReader(Shared.lines[index1]); if (Shared.parameterArray[1] != null) Shared.parameterArray[1] = Grapher.fileReader(Shared.lines[index2]); monthPanel.repaint(monthPanel.getVisibleRect()); } //change to 2007 bounds = new Rectangle(X_OFFSET + 200, Y_OFFSET - 24, 36, 17); if (Shared.year != 2007 && bounds.contains(p)) { Shared.year = 2007; if (Shared.parameterArray[0] != null) { for (index1 = 0; index1 < Shared.lines.length; ++index1) { if (Shared.lines[index1].toString().equals(Shared.parameterArray[0].getLine().toString())) break; } } if (Shared.parameterArray[1] != null) { for (index2 = 0; index2 < Shared.lines.length; ++index2) { if (Shared.lines[index2].toString().equals(Shared.parameterArray[1].getLine().toString())) break; } } Shared.setLines(); if (Shared.parameterArray[0] != null) Shared.parameterArray[0] = Grapher.fileReader(Shared.lines[index1]); if (Shared.parameterArray[1] != null) Shared.parameterArray[1] = Grapher.fileReader(Shared.lines[index2]); monthPanel.repaint(monthPanel.getVisibleRect()); } } }); monthPanel.addMouseMotionListener(new MouseMotionAdapter() { private int oldMonth = 999; private int oldDay = 999; private Rectangle calendar = new Rectangle(X_OFFSET,Y_OFFSET+30, 7*DATE_WIDTH,5*DATE_HEIGHT); public void mouseMoved(MouseEvent e) { // System.err.println("I have motion"); Point p = e.getPoint(); //if there is a day selected, that day is always highlighed. /*if (selected && oldMonth == Shared.currentMonth && oldDay == Shared.currentDay) return;*/ //if outside the Calendar /*if (!calendar.contains(p)) { if (popup != null) { popup.hide(); popup = null; oldMonth = 999; oldDay = 999; } return; }*/ int days = 2-tempCal.get(tempCal.DAY_OF_WEEK)+week; int month = Shared.currentMonth; days += (p.x-X_OFFSET) / DATE_WIDTH; days += (p.y-Y_OFFSET-30) / DATE_HEIGHT * 7; //if not moving into a new day if (days == oldDay && month == oldMonth) return; oldDay = days; oldMonth = month; if ((days<1&&month==0) || (days>Shared.monthEnd[month]&&month==11)) return; //Clicked on an invalid month /*JPanel popped = new JPanel(new FlowLayout(0,10,6)) { public void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Format.CAL_POPUP_BACKGROUND); g.fillRoundRect(0,0,getWidth()-2,getHeight()-2,15,15); g.setColor(Format.CAL_POPUP_BORDER); g.drawRoundRect(0,0,getWidth()-2,getHeight()-2,15,15); } }; popped.setBackground(new Color(0,0,0,0)); JLabel extrema = new JLabel( Shared.parameterArray[0].getExtremas(month, days)); extrema.setFont(Format.MONOSPACED); extrema.setVerticalAlignment(SwingConstants.TOP); //extrema.setPreferredSize(new Dimension(DATE_WIDTH*3, DATE_HEIGHT)); popped.setPreferredSize(new Dimension(DATE_WIDTH*3,DATE_HEIGHT)); popped.add(extrema); float xOffset = (p.x-X_OFFSET > calendar.getWidth()/2)?0.5f:3.5f; float yOffset = (p.y-Y_OFFSET-30 > calendar.getHeight()/2)?0.5f:3.5f; //p.x-xoffset > calender.getWidth()/2 xOffset = X_OFFSET+DATE_WIDTH*xOffset; yOffset = Y_OFFSET+30+DATE_HEIGHT*yOffset; p = monthPanel.getLocationOnScreen();*/ /*if (popup != null) popup.hide(); popup = factory.getPopup(monthPanel,popped,p.x+(int)xOffset,p.y+(int)yOffset); popup.show();*/ if (bounds.contains(p)) monthPanel.setToolTipText(Shared.parameterArray[0].getExtremas(month, days)); if (calBounds.contains(p)) monthPanel.setToolTipText("Current View"); if (contBounds.contains(p)) monthPanel.setToolTipText("Change to Continous View"); if (upBounds.contains(p)) monthPanel.setToolTipText("Previous Week"); if (downBounds.contains(p)) monthPanel.setToolTipText("Next Week"); if (!(bounds.contains(p) || calBounds.contains(p) || contBounds.contains(p) || upBounds.contains(p) || downBounds.contains(p))) monthPanel.setToolTipText(null); } }); JPanel bottomPanel = new JPanel(); bottomPanel.setPreferredSize(new Dimension(660,75)); bottomPanel.setBackground(Format.CAL_BOTTOM); monthPanel.setPreferredSize(new Dimension(660,3*Shared.FRAME_HEIGHT/4)); add(bottomPanel, BorderLayout.SOUTH); add(titlePanel, BorderLayout.NORTH); add(monthPanel, BorderLayout.CENTER); setPreferredSize(new Dimension(Shared.FRAME_WIDTH,Shared.FRAME_HEIGHT)); } private void drawDays(Graphics g) { Graphics2D G = (Graphics2D)g; Color monthColor; String day = ""; int offset=0, size=0; tempCal = new GregorianCalendar(Shared.year, Shared.currentMonth, 1); G.setColor(Format.CAL_LINECOLOR); /* Draw the outline of the Calendar */ G.drawRoundRect(X_OFFSET,Y_OFFSET,DATE_WIDTH*7, DATE_HEIGHT*5+30,15,15); /* Place the week selection buttons (up and down buttons) */ upImage.paintIcon(monthPanel, G, X_OFFSET+7*DATE_WIDTH+5, Y_OFFSET + 5*DATE_HEIGHT - 20); downImage.paintIcon(monthPanel, G, X_OFFSET + 7*DATE_WIDTH + 5, Y_OFFSET + 5*DATE_HEIGHT + 5); //year selection G.setColor(Color.BLACK); G.setFont(Format.MODE_UNSELECTED_FONT); G.drawString("Select a year:", X_OFFSET, Y_OFFSET - 7); //draw 2005 if (Shared.year == 2005) { G.setFont(Format.MODE_SELECTED_FONT); G.setColor(Format.SELECTED_FONT_COLOR); } else { G.setColor(Format.UNSELECTED_FONT_COLOR); G.setFont(Format.MODE_UNSELECTED_FONT); } G.drawString("2005", X_OFFSET + 100, Y_OFFSET - 7); //draw 2006 if (Shared.year == 2006) { G.setColor(Format.SELECTED_FONT_COLOR); G.setFont(Format.MODE_SELECTED_FONT); } else { G.setColor(Format.UNSELECTED_FONT_COLOR); G.setFont(Format.MODE_UNSELECTED_FONT); } G.drawString("2006", X_OFFSET + 150, Y_OFFSET - 7); //draw 2007 if (Shared.year == 2007) { G.setColor(Format.SELECTED_FONT_COLOR); G.setFont(Format.MODE_SELECTED_FONT); } else { G.setColor(Format.UNSELECTED_FONT_COLOR); G.setFont(Format.MODE_UNSELECTED_FONT); } G.drawString("2007", X_OFFSET + 200, Y_OFFSET - 7); G.setFont(Format.MODE_UNSELECTED_FONT); G.setColor(Format.UNSELECTED_FONT_COLOR); G.drawString("Continuous", X_OFFSET,Y_OFFSET+DATE_HEIGHT*5+43); G.setColor(Format.SELECTED_FONT_COLOR); G.setFont(Format.MODE_SELECTED_FONT); G.drawString("Calendar",X_OFFSET+DATE_WIDTH*7-55, Y_OFFSET+DATE_HEIGHT*5+43); /* Make life easier by ensuring that we can only draw within the confines of the Calendar */ G.clip(new RoundRectangle2D.Double(X_OFFSET,Y_OFFSET,DATE_WIDTH*7+1, DATE_HEIGHT*5+31,15,15)); /* Draw the "Header" of the Calendar which contains the months of the year. */ G.setColor(Format.CAL_MONTH_PANEL); G.fillRect(X_OFFSET+1, Y_OFFSET+1,DATE_WIDTH*7-1,29); G.setFont(Format.MONTH_SELECTOR_FONT); /* Place the Months on the Header */ for (int i = 0; i < 12; i++) { if (Shared.currentMonth == i) G.setColor(Format.CAL_MONTH_HEADER_SELECTED); else G.setColor(Format.CAL_MONTH_HEADER); G.drawString(Shared.monthShort[i], X_OFFSET+8+i*42, Y_OFFSET + 20); } /* Begin to draw the Calendar. It contains 5 rows and 7 columns of days. 'i' is the current day. j is the row number. k is the column number.*/ for (int j = 0, i = 2-tempCal.get(tempCal.DAY_OF_WEEK)+week; j < 5; j++) { for (int k = 0; k < 7; k++, i++) { int month = Shared.currentMonth; //draw border around day G.setStroke(new BasicStroke()); G.setFont(Format.DATEFONT); G.setColor(Format.CAL_LINECOLOR); G.drawRect(k*DATE_WIDTH + X_OFFSET, j*DATE_HEIGHT+Y_OFFSET+30, DATE_WIDTH, DATE_HEIGHT); if (i <= 0 && month > 0) //last month { //'i' will be negative, so it is subtracted from the amount of // days in the last month. int today = Shared.monthEnd[month-1] + i; //month color is based on even/odd-ness of month number. monthColor = monthColors[(month-1)%2]; //if month is today. if (today == Shared.cal.get(Shared.cal.DAY_OF_MONTH) && month-1 == Shared.cal.get(Shared.cal.MONTH)) { monthColor = Format.CAL_TODAY; } //if any day besides the first of the month, not bold. if (today != 1) day = Integer.toString(today); else //day is bold and contains month name. { G.setFont(Format.DATEBOLD); day = Shared.monthList[month-1]+" "+Integer.toString(today); } } else if (i <= Shared.monthEnd[month] && i > 0)//current month { monthColor = monthColors[month%2];//set month color if (i == Shared.cal.get(Shared.cal.DAY_OF_MONTH) && month == Shared.cal.get(Shared.cal.MONTH)) {//if today monthColor = Format.CAL_TODAY; } if (i != 1)//if any day besides the first day of month, not bold day = Integer.toString(i); else //day is bold and contains month name { G.setFont(Format.DATEBOLD); day = Shared.monthList[month]+" "+Integer.toString(i); } } else if (i > Shared.monthEnd[month] && month != 11)//next month { /* day in next month = number of days since beginning of this month - number of days in this month*/ int today = i-Shared.monthEnd[month]; monthColor = monthColors[(month+1)%2]; //set month color //if today. if (today == Shared.cal.get(Shared.cal.DAY_OF_MONTH) && month+1 == Shared.cal.get(Shared.cal.MONTH)) { monthColor = Format.CAL_TODAY; } if (today != 1)// not bold text day = Integer.toString(today); else//day is bold and contains month name. { G.setFont(Format.DATEBOLD); day = Shared.monthList[month+1]+" "+Integer.toString(today); } } else //not part of a month (before January or after December) monthColor = Format.CAL_NULLMONTH; //fill in the month with the color pertaining to that month G.setColor(monthColor); G.fillRect(k*DATE_WIDTH+1+X_OFFSET, j*DATE_HEIGHT+31+Y_OFFSET, DATE_WIDTH-1, DATE_HEIGHT-1); // highlight the month with the highlight color. if (i == Shared.currentDay) { G.setColor(Format.CAL_HIGHLIGHT); G.fillRect(k*DATE_WIDTH+1+X_OFFSET, j*DATE_HEIGHT+31+Y_OFFSET, DATE_WIDTH-1, DATE_HEIGHT-1); } /* if (j*7+k < moonVector.size()) { ImageIcon moonPic = (ImageIcon)moonVector.get(j*7+k); if (moonPic != null && (moonPic.getDescription() == "Full Moon" || moonPic.getDescription() == "New Moon")) G.drawString(moonPic.getDescription(),X_OFFSET+k*DATE_WIDTH+3, Y_OFFSET+j*DATE_HEIGHT+44); } else { ImageIcon moonPic = myMoon.getMoon(offset); moonVector.add(moonPic); if (moonPic != null && (moonPic.getDescription() == "Full Moon" || moonPic.getDescription() == "New Moon")) G.drawString(moonPic.getDescription(),X_OFFSET+k*DATE_WIDTH+3, Y_OFFSET+j*DATE_HEIGHT+44); }*/ /* Draw the tide Line as a double thick, white line*/ if (k == 0) { offset = (int)(Shared.monthToDay(Shared.currentMonth) + i - 1)*24; // Mathematically graph the line size = Grapher.graph(offset - ((offset > 0) ? 10/PCONVERT : 0), Shared.parameterArray[0], ylocation, xlocation, (int)Math.round(DATE_WIDTH*7) + 10, Y_OFFSET+78 + j*DATE_HEIGHT, X_OFFSET, 5, PCONVERT); } if (size > 0) { G.setColor(Color.white); G.setStroke(Format.THICKSTROKE); // Create an object that 'connects the dots' between the points // that were graphed by the grapher function. GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD,size); ListIterator xLI = xlocation.listIterator(0); ListIterator yLI = ylocation.listIterator(0); boolean first = true; while (xLI.hasNext() && yLI.hasNext()) { int x = ((Integer)xLI.next()).intValue() - (int)Math.round(offset*PCONVERT); int y = ((Integer)yLI.next()).intValue(); if (x > (X_OFFSET + k*DATE_WIDTH - 1) && x < (X_OFFSET + (k + 1)*DATE_WIDTH + 1)) { if (first) { polyline.moveTo(x, y); first = false; } else polyline.lineTo(x,y); } } //draw the line on the screen. G.draw(polyline); G.setStroke(Format.DEFAULT_STROKE); } // place the date in the upper left hand corner. if (i <= 0 && month > 0) G.setColor(dayColors[(month - 1)%2]); else if (i <= Shared.monthEnd[month] && i > 0) G.setColor(dayColors[month%2]); else if (i > Shared.monthEnd[month] && month != 11) G.setColor(dayColors[(month+1)%2]); else continue; G.drawString(day, k*DATE_WIDTH+3 + X_OFFSET, j*DATE_HEIGHT+44 + Y_OFFSET); } } } private void createTitle() { //Title Panel //Create the Panel that holds the Title and the Accept "Button" titlePanel = new JPanel(new FlowLayout(0,0,0)) { public void paint(Graphics g) { super.paint(g); titleImage.paintIcon(titlePanel, g, 0, 0); } }; //width of the entire frame, 1/8 of height of frame titlePanel.setPreferredSize(new Dimension(Shared.FRAME_WIDTH,Shared.FRAME_HEIGHT/8)); //Accept Button //Holds the Button that the user uses to move to the continuous view. acceptButton = new JButton(); acceptButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { /*if (popup != null) { popup.hide(); popup = null; }*/ if (Shared.currentMonth >= 11 && (Shared.currentDay >= Shared.monthEnd[Shared.currentMonth] - 6)) { Shared.currentMonth = 11; Shared.currentDay = Shared.monthEnd[Shared.currentMonth] - 6; } if (selected) { Shared.offset=(int)((Shared.monthToDay(Shared.currentMonth) + Shared.currentDay - 1) * 24); moonVector.clear(); TideCalendar.changeToContinuous(); } else //day not selected { Shared.offset=(int)((Shared.monthToDay(Shared.currentMonth) * 24)); moonVector.clear(); TideCalendar.changeToContinuous(); } } }); } public void makeMonthButtons() { for (int i = 0; i < 12; i++) { final int q = i; monthButton[i] = new JButton(); monthButton[i].addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { week = 0; Shared.currentMonth = q; /*reset currentDay to put the highlight off the screen so a * random day is not highlighted*/ Shared.currentDay = -50; //change Accept button //acceptButton.setText("Please Choose a Day"); selected = false; moonVector.clear(); if (redraw) monthPanel.repaint(monthPanel.getVisibleRect()); } }); } } /* * SIZES OF VARIOUS OBJECTS */ //Width of the individual boxers for the days private static final int DATE_WIDTH = 72; //Height of the individual boxes for the days private static final int DATE_HEIGHT = 72; //X Offset for the Calendar Viewscreen private static final int X_OFFSET = (Shared.FRAME_WIDTH - 7*DATE_WIDTH)/2; //Y Offset for the Calendar Viewscreen private static final int Y_OFFSET = (3*Shared.FRAME_HEIGHT/4 - 5*DATE_HEIGHT - 30)/2; // Formula for creation of Pixel Conversion Factors // (24 Hours/day) * (7 days/week)= # hours/week // (DATE_WIDTH pixels) * (7 days/week) = # of Pixels/week // so DATE_WIDTH / 24 = Pixels/hour private static final float PCONVERT = 3f; /* * END SIZES */ }