diff --git a/ComposeWindow.java b/ComposeWindow.java index a373b05..1fe6807 100644 --- a/ComposeWindow.java +++ b/ComposeWindow.java @@ -10,6 +10,11 @@ import javax.swing.JSeparator; import javax.swing.Box; import javax.swing.BorderFactory; import javax.swing.JOptionPane; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.UIManager; +import javax.swing.JToggleButton; +import javax.swing.ButtonGroup; import javax.swing.border.Border; import java.awt.GridLayout; import java.awt.BorderLayout; @@ -22,8 +27,13 @@ import java.awt.Cursor; import java.awt.Color; import java.awt.Font; import java.awt.Insets; +import java.awt.FlowLayout; +import java.awt.Component; +import java.awt.Container; import javax.swing.event.CaretListener; import javax.swing.event.CaretEvent; +import java.util.List; +import java.util.ArrayList; import cafe.biskuteri.hinoki.Tree; import java.io.IOException; @@ -48,6 +58,9 @@ ComposeWindow extends JFrame { private AttachmentsComponent attachmentsDisplay; + private JTabbedPane + tabs; + // ---%-@-%--- public synchronized void @@ -117,22 +130,6 @@ ComposeWindow extends JFrame { contentsDisplay.setSubmitting(false); } - public void - showContentsPage() - { - setContentPane(contentsDisplay); - revalidate(); - contentsDisplay.requestFocusInWindow(); - } - - public void - showAttachmentsPage() - { - setContentPane(attachmentsDisplay); - revalidate(); - attachmentsDisplay.requestFocusInWindow(); - } - // - -%- - private synchronized void @@ -173,17 +170,22 @@ ComposeWindow extends JFrame { this.primaire = primaire; this.api = primaire.getMastodonApi(); - final Dimension SZ = new Dimension(360, 270); + Dimension sz = new Dimension(360, 270); - getContentPane().setPreferredSize(SZ); - pack(); setDefaultCloseOperation(DISPOSE_ON_CLOSE); contentsDisplay = new ComposeComponent(this); attachmentsDisplay = new AttachmentsComponent(this); newComposition(); - showContentsPage(); + tabs = new JTabbedPane(); + contentsDisplay.setPreferredSize(sz); + tabs.addTab("Text", contentsDisplay); + tabs.addTab("Media", attachmentsDisplay); + + setBackground((Color)UIManager.get("TabbedPane.tabAreaBackground")); + setContentPane(tabs); + pack(); setIconImage(primaire.getProgramIcon()); } @@ -331,7 +333,8 @@ implements ActionListener, CaretListener, KeyListener { actionPerformed(ActionEvent eA) { if (eA.getSource() == showAttachmentsPage) - primaire.showAttachmentsPage(); + //primaire.showAttachmentsPage(); + ; if (eA.getSource() == submit) primaire.submit(); @@ -343,8 +346,14 @@ implements ActionListener, CaretListener, KeyListener { public void keyPressed(KeyEvent eK) { - boolean esc = eK.getKeyCode() == KeyEvent.VK_ESCAPE; - if (esc) showAttachmentsPage.requestFocusInWindow(); + boolean esc = eK.getKeyCode() == KeyEvent.VK_ESCAPE; + if (esc) + { + Container fcr = getFocusCycleRootAncestor(); + fcr.getFocusTraversalPolicy() + .getComponentAfter(fcr, text) + .requestFocusInWindow(); + } else updateTextLength(); } @@ -420,11 +429,11 @@ implements ActionListener, CaretListener, KeyListener { submit = new JButton("Submit"); submit.addActionListener(this); - showAttachmentsPage = new JButton("Media"); + showAttachmentsPage = new JButton("Media"); showAttachmentsPage.addActionListener(this); Box bottom = Box.createHorizontalBox(); - bottom.add(showAttachmentsPage); + //bottom.add(showAttachmentsPage); bottom.add(Box.createGlue()); bottom.add(textLength); bottom.add(Box.createHorizontalStrut(12)); @@ -459,22 +468,22 @@ implements ActionListener { // - -%- - - private Attachment[] - working; + private List + working; - private JButton - attachment1, - attachment2, - attachment3, - attachment4; + private JPanel + selections; + + private ButtonGroup + selectionsGroup; + + private JButton + add; private JButton delete, revert; - private JButton - close; - private JLabel descriptionLabel; @@ -483,14 +492,54 @@ implements ActionListener { // ---%-@-%--- + private void + updateButtons() + { + selections.removeAll(); + + Dimension sz = add.getPreferredSize(); + + int i = 1; + for (Attachment attachment: working) + { + JToggleButton button = new JToggleButton(); + button.setPreferredSize(sz); + button.setMargin(add.getMargin()); + button.setText(Integer.toString(i++)); + selections.add(button); + } + if (working.size() < 4) selections.add(add); + + int bw = sz.width; + int hgap = 4; + int count = Math.min(1 + working.size(), 4); + int w = count * bw + (count - 1) * hgap; + int h = bw; + selections.setPreferredSize(new Dimension(w, h)); + selections.setMaximumSize(new Dimension(w, h)); + } + public void actionPerformed(ActionEvent eA) { Object src = eA.getSource(); - if (src == close) + if (false) + { + // Clicked on filled attachment button. + } + + if (src == add) + { + // Invoke file picker. Try to get file. + // Try to upload file. So on. + // Then add to working. + working.add(new Attachment()); + updateButtons(); + } + + if (src == delete) { - primaire.showContentsPage(); return; } @@ -498,11 +547,6 @@ implements ActionListener { { return; } - - if (src == delete) - { - return; - } } // ---%-@-%--- @@ -514,79 +558,89 @@ implements ActionListener { Border b1 = BorderFactory.createEmptyBorder(8, 8, 8, 8); Border b2 = BorderFactory.createEmptyBorder(4, 4, 4, 4); Border b3 = BorderFactory.createLineBorder(Color.GRAY); - Border bc = BorderFactory.createCompoundBorder(b3, b2); + Border b4 = BorderFactory.createEmptyBorder(4, 8, 8, 8); + Border b5 = BorderFactory.createEtchedBorder(); + Border bc1 = BorderFactory.createCompoundBorder(b3, b2); + Border bc2 = BorderFactory.createCompoundBorder(b4, b2); - attachment1 = new JButton("+"); - attachment2 = new JButton("+"); - attachment3 = new JButton("+"); - attachment4 = new JButton("+"); - attachment1.setMargin(new Insets(0, 0, 0, 0)); - attachment2.setMargin(new Insets(0, 0, 0, 0)); - attachment3.setMargin(new Insets(0, 0, 0, 0)); - attachment4.setMargin(new Insets(0, 0, 0, 0)); - attachment1.addActionListener(this); - attachment2.addActionListener(this); - attachment3.addActionListener(this); - attachment4.addActionListener(this); + add = new JButton("+"); + add.setPreferredSize(new Dimension(32, 32)); + add.setMargin(new Insets(0, 0, 0, 0)); + add.addActionListener(this); - JPanel leftleft = new JPanel(); - leftleft.setOpaque(false); - leftleft.setLayout(null); - // BoxLayout wasn't listening to my - // preferred nor minimum sizes. - attachment1.setSize(40, 40); - attachment2.setSize(40, 40); - attachment3.setSize(40, 40); - attachment4.setSize(40, 40); - attachment1.setLocation(0, 0); - attachment2.setLocation(0, 44); - attachment3.setLocation(0, 88); - attachment4.setLocation(0, 132); - leftleft.add(attachment1); - leftleft.add(attachment2); - leftleft.add(attachment3); - leftleft.add(attachment4); - leftleft.setPreferredSize(new Dimension(40, 172)); - JSeparator line = new JSeparator(JSeparator.VERTICAL); - JPanel left = new JPanel(); - left.setLayout(new BorderLayout(8, 0)); - left.add(leftleft, BorderLayout.CENTER); - left.add(line, BorderLayout.EAST); + selections = new JPanel(); + selections.setOpaque(false); + selections.setLayout(new GridLayout(1, 0, 4, 0)); + + working = new ArrayList(); + updateButtons(); + JButton del = new JButton("D"); + JButton rev = new JButton("R"); + JButton ml = new JButton("←"); + JButton mr = new JButton("→"); + del.setMargin(new Insets(0, 0, 0, 0)); + //ml.setMargin(new Insets(0, 0, 0, 0)); + //mr.setMargin(new Insets(0, 0, 0, 0)); + rev.setMargin(new Insets(0, 0, 0, 0)); + + JPanel actions = new JPanel(); + actions.setOpaque(false); + actions.setLayout(new GridLayout(1, 4, 4, 4)); + actions.add(del); + actions.add(rev); + actions.add(ml); + actions.add(mr); + actions.setPreferredSize(new Dimension(108, 24)); + actions.setMaximumSize(new Dimension(108, 24)); + delete = new JButton("Delete"); revert = new JButton("Revert"); - close = new JButton("Save all & close"); delete.addActionListener(this); revert.addActionListener(this); - close.addActionListener(this); + + Box top = Box.createHorizontalBox(); + top.add(selections); + top.add(Box.createGlue()); - Box bottom = Box.createHorizontalBox(); - bottom.add(close); - bottom.add(Box.createGlue()); - bottom.add(delete); - bottom.add(Box.createHorizontalStrut(16)); - bottom.add(revert); + Box bottom = Box.createHorizontalBox(); + bottom.add(ml); + bottom.add(mr); + bottom.add(Box.createHorizontalStrut(8)); + bottom.add(delete); + bottom.add(Box.createGlue()); + bottom.add(revert); description = new JTextArea(); description.setLineWrap(true); description.setWrapStyleWord(true); java.awt.Font f = description.getFont(); description.setFont(f.deriveFont(16f)); - description.setBorder(bc); + description.setBorder(bc1); descriptionLabel = new JLabel("Description"); descriptionLabel.setLabelFor(description); JPanel row1 = new JPanel(); row1.setOpaque(false); - row1.setLayout(new BorderLayout()); + row1.setLayout(new BorderLayout()); row1.add(descriptionLabel, BorderLayout.NORTH); row1.add(description, BorderLayout.CENTER); - Box right = Box.createVerticalBox(); - right.add(row1); + + /* + Box row2 = Box.createHorizontalBox(); + row2.add(Box.createGlue()); + row2.add(delete); + row2.add(Box.createHorizontalStrut(8)); + row2.add(revert); + */ + + Box centre = Box.createVerticalBox(); + centre.setBorder(b4); + centre.add(row1); setLayout(new BorderLayout(8, 8)); - add(right, BorderLayout.CENTER); - add(left, BorderLayout.WEST); + add(centre, BorderLayout.CENTER); + add(top, BorderLayout.NORTH); add(bottom, BorderLayout.SOUTH); setBorder(b1); diff --git a/JKomasto.java b/JKomasto.java index 114ccb8..b9dd9d8 100644 --- a/JKomasto.java +++ b/JKomasto.java @@ -17,6 +17,11 @@ import java.time.Period; import java.time.temporal.ChronoUnit; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; +import javax.swing.plaf.metal.MetalLookAndFeel; +import javax.swing.plaf.metal.DefaultMetalTheme; +import javax.swing.plaf.metal.OceanTheme; +import javax.swing.plaf.ColorUIResource; +import javax.swing.UIDefaults; import cafe.biskuteri.hinoki.Tree; @@ -86,11 +91,72 @@ JKomasto { public Image getProgramIcon() { return programIcon; } +// ---%-@-%--- + + private static class + MetalTheme extends OceanTheme { + + private ColorUIResource + lightPink = new ColorUIResource(246, 240, 240), + mildPink = new ColorUIResource(238, 233, 233), + white = new ColorUIResource(250, 250, 250), + darkPink = new ColorUIResource(242, 230, 230), + veryDarkPink = new ColorUIResource(164, 160, 160); + +// -=%=- + + public ColorUIResource + getPrimary2() { return darkPink; } + + public ColorUIResource + getSecondary2() { return white; } + + public ColorUIResource + getSecondary3() { return mildPink; } + + public ColorUIResource + getSecondary1() { return veryDarkPink; } + + public ColorUIResource + getPrimary1() { return veryDarkPink; } + + public void + addCustomEntriesToTable(UIDefaults table) + { + super.addCustomEntriesToTable(table); + table.put( + "TabbedPane.tabAreaBackground", + getPrimary1() + ); + table.put( + "TabbedPane.contentAreaColor", + getSecondary3() + ); + table.put( + "TabbedPane.selected", + getSecondary3() + ); + table.put( + "MenuBar.gradient", + java.util.Arrays.asList(new Object[] { + 1f, 0f, + getWhite(), + getSecondary3(), + getSecondary1() + }) + ); + } + + } + // ---%-@-%--- public static void main(String... args) { + //System.setProperty("swing.boldMetal", "false"); + MetalLookAndFeel.setCurrentTheme(new MetalTheme()); + new JKomasto().loginWindow.setVisible(true); } diff --git a/graphics/Federated.xcf b/graphics/Federated.xcf old mode 100644 new mode 100755 diff --git a/graphics/Flags.xcf b/graphics/Flags.xcf old mode 100644 new mode 100755 diff --git a/graphics/Home.xcf b/graphics/Home.xcf old mode 100644 new mode 100755 diff --git a/graphics/Hourglass.xcf b/graphics/Hourglass.xcf old mode 100644 new mode 100755 diff --git a/graphics/Kettle.xcf b/graphics/Kettle.xcf old mode 100644 new mode 100755 diff --git a/graphics/boostToggled.png b/graphics/boostToggled.png old mode 100644 new mode 100755 diff --git a/graphics/boostUntoggled.png b/graphics/boostUntoggled.png old mode 100644 new mode 100755 diff --git a/graphics/button.png b/graphics/button.png old mode 100644 new mode 100755 diff --git a/graphics/disabledOverlay.png b/graphics/disabledOverlay.png old mode 100644 new mode 100755 diff --git a/graphics/favouriteToggled.png b/graphics/favouriteToggled.png old mode 100644 new mode 100755 diff --git a/graphics/favouriteUntoggled.png b/graphics/favouriteUntoggled.png old mode 100644 new mode 100755 diff --git a/graphics/federated.png b/graphics/federated.png old mode 100644 new mode 100755 diff --git a/graphics/home.png b/graphics/home.png old mode 100644 new mode 100755 diff --git a/graphics/kettle.png b/graphics/kettle.png old mode 100644 new mode 100755 diff --git a/graphics/miscToggled.png b/graphics/miscToggled.png old mode 100644 new mode 100755 diff --git a/graphics/miscUntoggled.png b/graphics/miscUntoggled.png old mode 100644 new mode 100755 diff --git a/graphics/nextToggled.png b/graphics/nextToggled.png old mode 100644 new mode 100755 index 7677635..f288ec4 Binary files a/graphics/nextToggled.png and b/graphics/nextToggled.png differ diff --git a/graphics/nextUntoggled.png b/graphics/nextUntoggled.png old mode 100644 new mode 100755 index 1cb32ff..4f70b6c Binary files a/graphics/nextUntoggled.png and b/graphics/nextUntoggled.png differ diff --git a/graphics/postWindow.png b/graphics/postWindow.png old mode 100644 new mode 100755 diff --git a/graphics/prevToggled.png b/graphics/prevToggled.png old mode 100644 new mode 100755 index cadac76..5d28c80 Binary files a/graphics/prevToggled.png and b/graphics/prevToggled.png differ diff --git a/graphics/prevUntoggled.png b/graphics/prevUntoggled.png old mode 100644 new mode 100755 index 1e8b4f8..3794090 Binary files a/graphics/prevUntoggled.png and b/graphics/prevUntoggled.png differ diff --git a/graphics/ref1.png b/graphics/ref1.png old mode 100644 new mode 100755 diff --git a/graphics/replyToggled.png b/graphics/replyToggled.png old mode 100644 new mode 100755 diff --git a/graphics/replyUntoggled.png b/graphics/replyUntoggled.png old mode 100644 new mode 100755 diff --git a/graphics/selectedOverlay.png b/graphics/selectedOverlay.png old mode 100644 new mode 100755 diff --git a/graphics/test1.png b/graphics/test1.png old mode 100644 new mode 100755 diff --git a/graphics/test2.png b/graphics/test2.png old mode 100644 new mode 100755 diff --git a/graphics/test3.png b/graphics/test3.png old mode 100644 new mode 100755 diff --git a/graphics/test4.png b/graphics/test4.png old mode 100644 new mode 100755