package net.bunnie.jgm;
// import things for window
import java.awt.*;
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.*;
// java -Dhttp.proxyHost=192.168.5.1 -classpath .;Z:\java\files\oalnf\oalnf.jar EntryGUI
// August 1
public class EntryOutGUI extends JFrame implements ActionListener {
String command;
String[] mostRecent;
String[] weekdays = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
String[] months = {"null", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
String headerText = "Hazel Orb Archives";
int entryNumber = 0;
String entryN = "";
String superString = "Please Wait";
String entry = "";
String[] fileToFileArray = new String[4];
String[] fileInfo = new String[17];
int weekday = 0;
int month = 0;
int number = 0;
String ampm = "";
String time = "";
String date = "";
String firstLabel = " ";
String firstLabel2 = " ";
String secondLabel = " ";
//String[] entryByName = {"Entry 1", "Entry 2", "Entry 3", "Entry 4", "Lalala", "5", "6", "7", "8", "9", "10"};
JLabel header;
JLabel top;
JLabel top2;
JLabel bottom;
JLabel blank1;
JLabel blank2;
JPanel all;
JPanel borderP;
JPanel flowP;
JTextArea entryDisplay;
//JComboBox entryDropDown;
JTextField entrySelect;
JButton entrySB;
JScrollPane entryJSP;
//JScrollPane dropDownJSP;
TitledBorder headerBorder;
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
Font smallFont = new Font("Tahoma", Font.PLAIN, 13);
Font smallerFont = new Font("Tahoma", Font.PLAIN, 2);
Font bigFont = new Font("Tahoma", Font.PLAIN, 36);
Color blueish = new Color(100, 150, 230);
Color blueishBG = new Color(217, 234, 255);
/*String htmlFont = "";
String headerText = "Hazel Orb Archives";
String firstLabel = "" + htmlFont + "Entry number " + entryN;
String firstLabel2 = "" + htmlFont + " " + weekdays[weekday] + " " + fileInfo[2] + "
Posted by " + fileInfo[1] + " at " + time + " on " + date + ""; */ public void setScreen(int entryNumber) { entryN = ToFileArray.entryFormat(entryNumber); superString = "Viewing Entry " + entryN; //String entry = Regex.replaceBreak(entryNumber); //String[] fileToFileArray = ToFileArray.toFileArray(ToFileArray.entryFile(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); number = Integer.parseInt(fileInfo[0], 10); ampm = fileInfo[10].toLowerCase(); if (Integer.parseInt(fileInfo[8], 10) < 10) { fileInfo[8] = "0" + fileInfo[8]; } time = fileInfo[7] + ":" + fileInfo[8] + " " + ampm.charAt(0) + ".m."; date = months[month] + " " + fileInfo[5] + ", " + fileInfo[6]; firstLabel = "Entry number " + entryN; firstLabel2 = weekdays[weekday] + " " + fileInfo[2]; secondLabel = "Posted by " + fileInfo[1] + " at " + time + " on " + date; top.setText(firstLabel); top2.setText(firstLabel2); bottom.setText(secondLabel); superString = "Viewing Entry " + entryN; headerBorder = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(blueish), superString, TitledBorder.LEFT, TitledBorder.TOP, smallFont, blueish); borderP.setBorder(headerBorder); entryDisplay.setText(entry); entryDisplay.setCaretPosition(0); } public EntryOutGUI() { super("Viewing entry..."); 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); flowP = new JPanel(); flowP.setBackground(Color.white); //flowP.setBorder(headerBorder); flowP.setLayout(new FlowLayout()); 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.CENTER); top2.setFont(smallFont); top2.setForeground(blueish); blank1 = new JLabel(" ", JLabel.CENTER); blank1.setFont(smallerFont); blank1.setForeground(Color.white); blank2 = new JLabel(" ", JLabel.CENTER); blank1.setFont(smallerFont); blank2.setForeground(Color.white); bottom = new JLabel(secondLabel, JLabel.CENTER); bottom.setFont(smallFont); bottom.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.thumbDarkShadow", new ColorUIResource(Color.magenta)); UIManager.put("ScrollBar.thumbShadow", new ColorUIResource(Color.black)); UIManager.put("ScrollBar.thumbHighlight", new ColorUIResource(Color.white)); //UIManager.put("ScrollBar.thumbLightShadow", new ColorUIResource(Color.orange)); UIManager.put("ScrollBar.track", new ColorUIResource(Color.white)); //UIManager.put("ScrollBar.trackHighlight", new ColorUIResource(Color.red)); //UIManager.put("ScrollBar.width", new Integer(50)); //UIManager.put("ScrollBar.minimumThumbSize", new Integer(20)); //UIManager.put("ComboBox.disabledBackground", new ColorUIResource(blueishBG)); //UIManager.put("ComboBox.disabledForeground", new ColorUIResource(blueish)); //UIManager.put("textHighlight", new ColorUIResource(blueishBG)); //UIManager.put("textHighlightText", new ColorUIResource(blueish)); //UIManager.put("Button.pressed", new ColorUIResource(Color.white)); Caret care = new DefaultCaret(); care.setBlinkRate(500); Caret care2 = new DefaultCaret(); care2.setBlinkRate(500); entryDisplay = new JTextArea(entry, 1, 36); entryDisplay.setBackground(Color.white); entryDisplay.setBorder(BorderFactory.createLineBorder(Color.white, 5)); entryDisplay.setCaret(care); entryDisplay.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); entryDisplay.setFont(smallFont); entryDisplay.setForeground(blueish); entryDisplay.setLineWrap(true); entryDisplay.setSelectedTextColor(blueish); entryDisplay.setSelectionColor(blueishBG); entryDisplay.setWrapStyleWord(true); entryJSP = new JScrollPane(entryDisplay); entryJSP.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); entryJSP.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); /*entryDropDown = new JList(entryByName); entryDropDown.setBackground(Color.white); entryDropDown.setFont(smallFont); entryDropDown.setForeground(blueish); entryDropDown.setVisibleRowCount(1);*/ /*entryDropDown = new JComboBox(entryByName); entryDropDown.setBackground(Color.white); entryDropDown.setBorder(new CompoundBorder(BorderFactory.createLineBorder(blueish), BorderFactory.createLineBorder(Color.white, 2))); entryDropDown.setFont(smallFont); entryDropDown.setForeground(blueish); MyCellRenderer myRenderer = new MyCellRenderer(); entryDropDown.setRenderer(myRenderer); */ entrySelect = new JTextField("", 8); entrySelect.setBackground(Color.white); entrySelect.setBorder(new CompoundBorder(BorderFactory.createBevelBorder(0, Color.white, blueish, Color.white, new Color(99, 101, 111)), BorderFactory.createLineBorder(Color.white, 3))); //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)))); 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.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); /*BasicComboPopup thatPopup = new BasicComboPopup(entryDropDown); thatPopup.setBorder(BorderFactory.createLineBorder(Color.white));*/ /*dropDownJSP = new JScrollPane(entryDropDown); dropDownJSP.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); dropDownJSP.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);*/ mostRecent = ToFileArray.toFileArrayF("http://bunnie.net/blog/past/java.php?get=recent"); mostRecent[0] = Regex.replace("\n", "", mostRecent[0]); entryNumber = Integer.parseInt(mostRecent[0]); setScreen(entryNumber); headerBorder = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(blueish), "Viewing Most Recent Entry", TitledBorder.LEFT, TitledBorder.TOP, smallFont, blueish); borderP.setBorder(headerBorder); flowP.add(entrySelect); flowP.add(entrySB); gbc.gridy = 0; gbl.setConstraints(header, gbc); all.add(header); gbc.gridy = 1; gbl.setConstraints(top, gbc); all.add(top); gbc.gridy = 2; gbl.setConstraints(top2, gbc); all.add(top2); gbc.gridy = 3; gbl.setConstraints(blank1, gbc); all.add(blank1); gbc.gridy = 4; gbl.setConstraints(flowP, gbc); all.add(flowP); gbc.gridy = 5; gbl.setConstraints(blank2, gbc); all.add(blank2); gbc.gridy = 6; gbc.ipady = 230; gbl.setConstraints(entryJSP, gbc); all.add(entryJSP); gbc.gridy = 7; gbc.ipady = 0; gbc.gridheight = GridBagConstraints.REMAINDER; gbl.setConstraints(bottom, gbc); all.add(bottom); borderP.add(all); c.add(borderP); } public void actionPerformed (ActionEvent e) { command = e.getActionCommand(); if (command.equals("Select")) { try { entryNumber = Integer.parseInt(entrySelect.getText()); setScreen(entryNumber); } catch (NumberFormatException nfes) { entryDisplay.setText("Invalid input."); } catch (ArrayIndexOutOfBoundsException aioobes) { entryDisplay.setText("Invalid input."); } } } // swing listener and window public static void main (String[] args) { try { //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); //UIManager.setLookAndFeel("com.oyoaha.swing.plaf.oyoaha.OyoahaLookAndFeel"); UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel"); } catch (Exception e) { } EntryOutGUI displayEntry = new EntryOutGUI(); JCloseListener clickMe = new JCloseListener(); displayEntry.addWindowListener(clickMe); displayEntry.setSize(480, 490); displayEntry.setVisible(true); } } // window listener class JCloseListener extends WindowAdapter { public void windowClosing (WindowEvent ev) { System.exit(0); } }