package net.bunnie.jgm; import java.awt.*; import java.awt.datatransfer.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.plaf.ColorUIResource; import javax.swing.text.*; import net.bunnie.*; import net.bunnie.jgm.*; // August 15 public class EntryGUIEdit extends JFrame implements ActionListener, ClipboardOwner { String command; String[] titles = {"Morning", "Afternoon", "Evening"}; String[] time = {"Keep Time", "Set Time"}; String[] insert = {"Insert", "SEPARATOR", "Dull Entry", "Entry Reference", "Image HTML"}; String[] weekdays = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; String[] monthDays = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"}; // fix for months String[] hour = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}; String[] minutes = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59"}; String[] seconds = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59"}; String[] ampm = {"a.m.", "p.m."}; String superString = "JGreymatter"; JLabel header; JLabel top; JLabel top2; JLabel bottom; JLabel copyLabel; JLabel blank1; JLabel blank2; JPanel all; JPanel borderP; JPanel timePanel; JPanel top3Panel; JPanel draftPanel; JPanel copyPanel; JPanel rbPanel; JPanel flowP; JTextArea entryMain; JTextArea entryMore; JTextField year; JTextField entrySelect; JButton entrySB; JButton entrySBCurrent; JButton addButton; JButton draftButton; JButton backToMain; JRadioButton continueButton; JRadioButton finishButton; ButtonGroup draftBG; JComboBox titlesCB; JComboBox timeCB; JComboBox insertCB; JComboBox weekdaysCB; JComboBox monthsCB; JComboBox monthDaysCB; JComboBox hourCB; JComboBox minutesCB; JComboBox secondsCB; JComboBox ampmCB; JScrollPane mainJSP; JScrollPane moreJSP; TitledBorder headerBorder; GridBagLayout gbl = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); Font smallFont = new Font("Tahoma", Font.PLAIN, 13); Font smallFont2 = new Font("Tahoma", Font.PLAIN, 9); Font bigFont = new Font("Tahoma", Font.PLAIN, 36); Color blueish = new Color(100, 150, 230); Color blueishBG = new Color(217, 234, 255); String headerText = "JGreymatter"; String firstLabel = "Edit An Entry"; String firstLabel2 = "Main: "; String secondLabel = "More: "; String copyright = "©2003 Bunnie Network"; int entryNumber = 0; String mostRecent[]; String entry = ""; String[] fileToFileArray = new String[4]; String[] fileInfo = new String[17]; int weekday = 0; int month = 0; String ampmtext = ""; int leapYear = 0; int getListing = 0; String getLS = ""; public void setEditScreen(int entryNumber) { entry = Regex.replaceBreakF(entryNumber); fileToFileArray = ToFileArray.toFileArrayF(ToFileArray.entryFileF(entryNumber)); fileInfo = Explode.explode("|", fileToFileArray[0]); weekday = Integer.parseInt(fileInfo[3], 10); month = Integer.parseInt(fileInfo[4], 10); ampmtext = fileInfo[10].toLowerCase(); ampmtext = ampmtext.charAt(0) + ".m."; titlesCB.setSelectedItem(fileInfo[2]); weekdaysCB.setSelectedItem(weekdays[weekday]); monthsCB.setSelectedItem(months[month - 1]); monthDaysCB.setSelectedItem(fileInfo[5]); hourCB.setSelectedItem(fileInfo[7]); minutesCB.setSelectedItem(fileInfo[8]); secondsCB.setSelectedItem(fileInfo[9]); ampmCB.setSelectedItem(ampmtext); year.setText(fileInfo[6]); fileToFileArray[3] = Regex.replace("\n", "", fileToFileArray[3]); entryMain.setText(entry); entryMain.setCaretPosition(0); entryMore.setText(fileToFileArray[3]); entryMore.setCaretPosition(0); } public void setEditScreenCurrent() { mostRecent = ToFileArray.toFileArrayF("http://bunnie.net/blog/past/java.php?get=recent"); mostRecent[0] = Regex.replace("\n", "", mostRecent[0]); entryNumber = Integer.parseInt(mostRecent[0]); setEditScreen(entryNumber); } public EntryGUIEdit() { super("JGreymatter"); Container c = getContentPane(); c.setBackground(Color.white); c.setLayout(new FlowLayout(FlowLayout.CENTER, 3, 3)); headerBorder = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(blueish), superString, TitledBorder.LEFT, TitledBorder.TOP, smallFont, blueish); all = new JPanel(); all.setBackground(Color.white); all.setBorder(BorderFactory.createLineBorder(Color.white, 5)); all.setLayout(gbl); borderP = new JPanel(); borderP.setBackground(Color.white); borderP.setBorder(headerBorder); timePanel = new JPanel(); timePanel.setBackground(Color.white); timePanel.setLayout(new GridLayout(2, 4)); top3Panel = new JPanel(); top3Panel.setBackground(Color.white); top3Panel.setLayout(new GridLayout(1, 3)); draftPanel = new JPanel(); draftPanel.setBackground(Color.white); draftPanel.setLayout(new GridLayout(1, 2)); copyPanel = new JPanel(); copyPanel.setBackground(Color.white); copyPanel.setLayout(new GridLayout(1, 3)); rbPanel = new JPanel(); rbPanel.setBackground(Color.white); rbPanel.setLayout(new GridLayout(1, 2)); flowP = new JPanel(); flowP.setBackground(Color.white); flowP.setLayout(new GridLayout(1, 3)); gbc.fill = GridBagConstraints.BOTH; gbc.weightx = 1; gbc.weighty = 0; gbc.gridx = 0; gbc.ipadx = 0; gbc.ipady = 0; header = new JLabel(headerText, JLabel.CENTER); header.setFont(bigFont); header.setForeground(blueish); top = new JLabel(firstLabel, JLabel.CENTER); top.setFont(smallFont); top.setForeground(blueish); top2 = new JLabel(firstLabel2, JLabel.LEFT); top2.setFont(smallFont); top2.setForeground(blueish); blank1 = new JLabel(" ", JLabel.CENTER); blank1.setForeground(Color.white); blank2 = new JLabel(" ", JLabel.CENTER); blank2.setForeground(Color.white); blank2.setFont(new Font("Tahoma", Font.PLAIN, 4)); bottom = new JLabel(secondLabel, JLabel.LEFT); bottom.setFont(smallFont); bottom.setForeground(blueish); copyLabel = new JLabel(copyright, JLabel.RIGHT); copyLabel.setFont(smallFont); copyLabel.setForeground(blueish); UIManager.put("ScrollBar.foreground", new ColorUIResource(blueish)); UIManager.put("ScrollBar.background", new ColorUIResource(Color.white)); UIManager.put("ScrollBar.highlight", new ColorUIResource(new Color(204, 204, 204))); UIManager.put("ScrollBar.shadow", new ColorUIResource(Color.white)); UIManager.put("ScrollBar.thumb", new ColorUIResource(blueish)); UIManager.put("ScrollBar.thumbShadow", new ColorUIResource(Color.black)); UIManager.put("ScrollBar.thumbHighlight", new ColorUIResource(Color.white)); UIManager.put("ScrollBar.track", new ColorUIResource(Color.white)); UIManager.put("RadioButton.select", new ColorUIResource(blueish)); UIManager.put("RadioButton.select", new ColorUIResource(blueish)); UIManager.put("RadioButtonMenuItem.selectionBackground", new ColorUIResource(blueish)); Caret care = new DefaultCaret(); care.setBlinkRate(500); Caret careMain = new DefaultCaret(); careMain.setBlinkRate(500); Caret careMore = new DefaultCaret(); careMore.setBlinkRate(500); Caret care2 = new DefaultCaret(); care2.setBlinkRate(500); JGMCellRenderer myRenderer = new JGMCellRenderer(); entryMain = new JTextArea(1, 15); entryMain.setBackground(Color.white); entryMain.setBorder(BorderFactory.createLineBorder(Color.white, 5)); entryMain.setCaret(careMain); entryMain.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); entryMain.setFont(smallFont); entryMain.setForeground(blueish); entryMain.setLineWrap(true); entryMain.setSelectedTextColor(blueish); entryMain.setSelectionColor(blueishBG); entryMain.setWrapStyleWord(true); mainJSP = new JScrollPane(entryMain); mainJSP.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); mainJSP.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); entryMore = new JTextArea(1, 15); entryMore.setBackground(Color.white); entryMore.setBorder(BorderFactory.createLineBorder(Color.white, 5)); entryMore.setCaret(careMore); entryMore.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); entryMore.setFont(smallFont); entryMore.setForeground(blueish); entryMore.setLineWrap(true); entryMore.setSelectedTextColor(blueish); entryMore.setSelectionColor(blueishBG); entryMore.setWrapStyleWord(true); moreJSP = new JScrollPane(entryMore); moreJSP.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); moreJSP.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); year = new JTextField("2003", 4); year.setBackground(Color.white); year.setBorder(new CompoundBorder(BorderFactory.createLineBorder(blueish), BorderFactory.createLineBorder(Color.white, 3))); year.setCaret(care); year.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); year.setFont(smallFont2); year.setForeground(blueish); year.setSelectedTextColor(blueish); year.setSelectionColor(blueishBG); titlesCB = new JComboBox(titles); titlesCB.setBackground(Color.white); titlesCB.setBorder(new CompoundBorder(BorderFactory.createLineBorder(blueish), BorderFactory.createLineBorder(Color.white, 2))); titlesCB.setFont(smallFont); titlesCB.setForeground(blueish); titlesCB.setRenderer(myRenderer); timeCB = new JComboBox(time); timeCB.setBackground(Color.white); timeCB.setBorder(new CompoundBorder(BorderFactory.createLineBorder(blueish), BorderFactory.createLineBorder(Color.white, 2))); timeCB.setFont(smallFont); timeCB.setForeground(blueish); timeCB.setRenderer(myRenderer); insertCB = new JComboBox(insert); insertCB.setBackground(Color.white); insertCB.setBorder(new CompoundBorder(BorderFactory.createLineBorder(blueish), BorderFactory.createLineBorder(Color.white, 2))); insertCB.setFont(smallFont); insertCB.setForeground(blueish); insertCB.setRenderer(myRenderer); weekdaysCB = new JComboBox(weekdays); weekdaysCB.setBackground(Color.white); weekdaysCB.setBorder(new CompoundBorder(BorderFactory.createLineBorder(blueish), BorderFactory.createLineBorder(Color.white, 2))); weekdaysCB.setFont(smallFont2); weekdaysCB.setForeground(blueish); weekdaysCB.setRenderer(myRenderer); monthsCB = new JComboBox(months); monthsCB.setBackground(Color.white); monthsCB.setBorder(new CompoundBorder(BorderFactory.createLineBorder(blueish), BorderFactory.createLineBorder(Color.white, 2))); monthsCB.setFont(smallFont2); monthsCB.setForeground(blueish); monthsCB.setRenderer(myRenderer); monthsCB.addActionListener(this); monthDaysCB = new JComboBox(monthDays); monthDaysCB.setBackground(Color.white); monthDaysCB.setBorder(new CompoundBorder(BorderFactory.createLineBorder(blueish), BorderFactory.createLineBorder(Color.white, 2))); monthDaysCB.setFont(smallFont2); monthDaysCB.setForeground(blueish); monthDaysCB.setModel((MutableComboBoxModel)monthDaysCB.getModel()); monthDaysCB.setRenderer(myRenderer); hourCB = new JComboBox(hour); hourCB.setBackground(Color.white); hourCB.setBorder(new CompoundBorder(BorderFactory.createLineBorder(blueish), BorderFactory.createLineBorder(Color.white, 2))); hourCB.setFont(smallFont2); hourCB.setForeground(blueish); hourCB.setRenderer(myRenderer); minutesCB = new JComboBox(minutes); minutesCB.setBackground(Color.white); minutesCB.setBorder(new CompoundBorder(BorderFactory.createLineBorder(blueish), BorderFactory.createLineBorder(Color.white, 2))); minutesCB.setFont(smallFont2); minutesCB.setForeground(blueish); minutesCB.setRenderer(myRenderer); secondsCB = new JComboBox(seconds); secondsCB.setBackground(Color.white); secondsCB.setBorder(new CompoundBorder(BorderFactory.createLineBorder(blueish), BorderFactory.createLineBorder(Color.white, 2))); secondsCB.setFont(smallFont2); secondsCB.setForeground(blueish); secondsCB.setRenderer(myRenderer); ampmCB = new JComboBox(ampm); ampmCB.setBackground(Color.white); ampmCB.setBorder(new CompoundBorder(BorderFactory.createLineBorder(blueish), BorderFactory.createLineBorder(Color.white, 2))); ampmCB.setFont(smallFont2); ampmCB.setForeground(blueish); ampmCB.setRenderer(myRenderer); entrySelect = new JTextField("", 8); entrySelect.setBackground(Color.white); entrySelect.setBorder(new CompoundBorder(BorderFactory.createLineBorder(Color.white, 5), new CompoundBorder(BorderFactory.createBevelBorder(0, Color.white, blueish, Color.white, new Color(99, 101, 111)), BorderFactory.createLineBorder(Color.white, 3)))); entrySelect.setCaret(care2); entrySelect.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); entrySelect.setFont(smallFont); entrySelect.setForeground(blueish); entrySelect.setSelectedTextColor(blueish); entrySelect.setSelectionColor(blueishBG); entrySB = new JButton("Select"); entrySB.setBackground(Color.white); entrySB.setBorder(new CompoundBorder(BorderFactory.createLineBorder(Color.white, 5), new CompoundBorder(BorderFactory.createBevelBorder(0, Color.white, blueish, Color.white, new Color(99, 101, 111)), BorderFactory.createLineBorder(Color.white, 3)))); entrySB.setFont(smallFont); entrySB.setForeground(blueish); entrySB.addActionListener(this); entrySBCurrent = new JButton("Current Entry"); entrySBCurrent.setBackground(Color.white); entrySBCurrent.setBorder(new CompoundBorder(BorderFactory.createLineBorder(Color.white, 5), new CompoundBorder(BorderFactory.createBevelBorder(0, Color.white, blueish, Color.white, new Color(99, 101, 111)), BorderFactory.createLineBorder(Color.white, 3)))); entrySBCurrent.setFont(smallFont); entrySBCurrent.setForeground(blueish); entrySBCurrent.addActionListener(this); addButton = new JButton("Save changes"); addButton.setBackground(Color.white); addButton.setBorder(new CompoundBorder(BorderFactory.createLineBorder(Color.white, 3), new CompoundBorder(BorderFactory.createBevelBorder(0, Color.white, blueish, Color.white, new Color(99, 101, 111)), BorderFactory.createLineBorder(Color.white, 3)))); //addButton.setBorder(UIManager.getBorder(new JButton())); addButton.setFont(smallFont); addButton.setForeground(blueish); draftButton = new JButton("Draft it"); draftButton.setBackground(Color.white); draftButton.setBorder(new CompoundBorder(BorderFactory.createLineBorder(Color.white, 3), new CompoundBorder(BorderFactory.createBevelBorder(0, Color.white, blueish, Color.white, new Color(99, 101, 111)), BorderFactory.createLineBorder(Color.white, 3)))); draftButton.setFont(smallFont); draftButton.setForeground(blueish); backToMain = new JButton("Main"); backToMain.setBackground(Color.white); backToMain.setBorder(new CompoundBorder(BorderFactory.createLineBorder(Color.white, 3), new CompoundBorder(BorderFactory.createBevelBorder(0, Color.white, blueish, Color.white, new Color(99, 101, 111)), BorderFactory.createLineBorder(Color.white, 3)))); backToMain.setFont(smallFont); backToMain.setForeground(blueish); continueButton = new JRadioButton(" Continue", true); continueButton.setBackground(Color.white); continueButton.setFont(smallFont); continueButton.setForeground(blueish); finishButton = new JRadioButton(" Finish"); finishButton.setBackground(Color.white); finishButton.setFont(smallFont); finishButton.setForeground(blueish); draftBG = new ButtonGroup(); draftBG.add(continueButton); draftBG.add(finishButton); setEditScreenCurrent(); flowP.add(entrySelect); flowP.add(entrySB); flowP.add(entrySBCurrent); rbPanel.add(continueButton); rbPanel.add(finishButton); timePanel.add(weekdaysCB); timePanel.add(monthsCB); timePanel.add(monthDaysCB); timePanel.add(year); timePanel.add(hourCB); timePanel.add(minutesCB); timePanel.add(secondsCB); timePanel.add(ampmCB); top3Panel.add(timeCB); top3Panel.add(titlesCB); top3Panel.add(insertCB); draftPanel.add(rbPanel); draftPanel.add(draftButton); copyPanel.add(backToMain); copyPanel.add(blank1); copyPanel.add(copyLabel); gbc.gridy = 0; gbl.setConstraints(header, gbc); all.add(header); gbc.gridy = 1; gbc.ipady = 15; gbl.setConstraints(top, gbc); all.add(top); gbc.gridy = 2; gbc.ipady = 0; gbl.setConstraints(flowP, gbc); all.add(flowP); gbc.gridy = 3; gbl.setConstraints(top3Panel, gbc); all.add(top3Panel); gbc.gridy = 4; gbl.setConstraints(blank2, gbc); all.add(blank2); gbc.gridy = 5; gbl.setConstraints(timePanel, gbc); all.add(timePanel); gbc.gridy = 6; gbc.ipady = 10; gbl.setConstraints(top2, gbc); all.add(top2); gbc.gridy = 7; gbc.ipady = 150; gbl.setConstraints(mainJSP, gbc); all.add(mainJSP); gbc.gridy = 8; gbc.ipady = 10; gbl.setConstraints(bottom, gbc); all.add(bottom); gbc.gridy = 9; gbc.ipady = 80; gbl.setConstraints(moreJSP, gbc); all.add(moreJSP); gbc.gridy = 10; gbc.ipady = 0; gbl.setConstraints(draftPanel, gbc); all.add(draftPanel); gbc.gridy = 11; gbl.setConstraints(addButton, gbc); all.add(addButton); gbc.gridy = 12; gbc.gridheight = GridBagConstraints.REMAINDER; gbl.setConstraints(copyPanel, gbc); all.add(copyPanel); borderP.add(all); c.add(borderP); } public void actionPerformed (ActionEvent e) { command = e.getActionCommand(); if (command.equals("Select")) { try { entryNumber = Integer.parseInt(entrySelect.getText()); setEditScreen(entryNumber); } catch (NumberFormatException nfes) { entryMain.setText("Invalid input."); } catch (ArrayIndexOutOfBoundsException aioobes) { entryMain.setText("Invalid input."); } } if (command.equals("Current Entry")) { setEditScreenCurrent(); } command = (String) monthsCB.getSelectedItem(); getLS = (String) monthDaysCB.getItemAt(monthDaysCB.getItemCount() - 1); getListing = Integer.parseInt(getLS); if (command.equals("January") || command.equals("March") || command.equals("May") || command.equals("July") || command.equals("August") || command.equals("October") || command.equals("December")) { if (getListing != 31) { if (getListing != 30) { if (getListing != 29) { if (getListing != 28) { monthDaysCB.addItem("28"); } monthDaysCB.addItem("29"); } monthDaysCB.addItem("30"); } monthDaysCB.addItem("31"); } } if (command.equals("September") || command.equals("April") || command.equals("June") || command.equals("November")) { if (getListing != 30) { if (getListing > 30) { monthDaysCB.removeItemAt(getListing - 1); } else { if (getListing != 29) { if (getListing != 28) { monthDaysCB.addItem("28"); } monthDaysCB.addItem("29"); } monthDaysCB.addItem("30"); } } } if (command.equals("February")) { try { leapYear = Integer.parseInt(year.getText()); if ((leapYear % 4 == 0) && ((leapYear % 100 != 0) || ((leapYear % 100 == 0) && (leapYear % 400 != 0)))) { if (getListing != 29) { if (getListing > 29) { while (Integer.parseInt((String) (monthDaysCB.getItemAt(monthDaysCB.getItemCount() - 1))) > 29) { monthDaysCB.removeItemAt(monthDaysCB.getItemCount() - 1); } } else { monthDaysCB.addItem("29"); } } } else { if (getListing != 28) { while (Integer.parseInt((String) (monthDaysCB.getItemAt(monthDaysCB.getItemCount() - 1))) > 28) { monthDaysCB.removeItemAt(monthDaysCB.getItemCount() - 1); } } } } catch (NumberFormatException nfexxx) { if (getListing != 28) { while (Integer.parseInt((String) (monthDaysCB.getItemAt(monthDaysCB.getItemCount() - 1))) > 28) { monthDaysCB.removeItemAt(monthDaysCB.getItemCount() - 1); } } } } } public void toClipboard(String str) { SecurityManager sm = System.getSecurityManager(); if (sm != null) { try { sm.checkSystemClipboardAccess(); } catch (Exception e) { } } Toolkit tk = Toolkit.getDefaultToolkit(); StringSelection st = new StringSelection(str); Clipboard clipboard = tk.getSystemClipboard(); clipboard.setContents(st, this); } public void lostOwnership(Clipboard clip, Transferable tr) { } // swing listener and window public static void main (String[] args) { try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel"); } catch (Exception e) { } EntryGUIEdit displayEntry = new EntryGUIEdit(); JCloseListener clickMe = new JCloseListener(); displayEntry.addWindowListener(clickMe); displayEntry.setSize(480, 680); displayEntry.setVisible(true); } }