Browse Source

Overhauled TabFrameDemo

Added TabFrame demo gif.

Signed-off-by: weisj <weisj@arcor.de>
pull/27/head
weisj 5 years ago
parent
commit
5af9282d5d
  1. BIN
      img/tabFrame.gif
  2. 94
      src/test/java/demo/tabFrame/TabFrameDemo.java

BIN
img/tabFrame.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 881 KiB

94
src/test/java/demo/tabFrame/TabFrameDemo.java

@ -23,10 +23,7 @@
*/
package demo.tabFrame;
import com.github.weisj.darklaf.LafManager;
import com.github.weisj.darklaf.components.SelectableTreeNode;
import com.github.weisj.darklaf.components.alignment.Alignment;
import com.github.weisj.darklaf.components.border.DarkBorders;
import com.github.weisj.darklaf.components.tabframe.JTabFrame;
import com.github.weisj.darklaf.components.tabframe.TabbedPopup;
import com.github.weisj.darklaf.components.text.NonWrappingTextPane;
@ -34,26 +31,42 @@ import com.github.weisj.darklaf.components.text.NumberedTextComponent;
import com.github.weisj.darklaf.components.text.NumberingPane;
import com.github.weisj.darklaf.icons.IconLoader;
import com.github.weisj.darklaf.util.StringUtil;
import demo.ComponentDemo;
import demo.DemoResources;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import javax.swing.text.BadLocationException;
import javax.swing.tree.DefaultMutableTreeNode;
import java.awt.*;
public class TabFrameDemo {
public class TabFrameDemo implements ComponentDemo {
public static void main(final String[] args) {
//Todo Rework Demo
SwingUtilities.invokeLater(() -> {
LafManager.install();
final JFrame frame = new JFrame();
Icon folderIcon = IconLoader.get().getUIAwareIcon("files/folder.svg", 19, 19);
ComponentDemo.showDemo(new TabFrameDemo(), new Dimension(1000, 500));
}
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@NotNull
private static Component createTextArea() {
NumberedTextComponent numberPane = new NumberedTextComponent(new NonWrappingTextPane() {{
setText(StringUtil.repeat(DemoResources.LOREM_IPSUM, 10));
setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));
}});
NumberingPane numbering = numberPane.getNumberingPane();
Icon icon = IconLoader.get().getIcon("navigation/arrowRight.svg");
try {
numbering.addIconAtLine(5, icon);
numbering.addIconAtLine(10, icon);
numbering.addIconAtLine(15, icon);
} catch (BadLocationException e) {
e.printStackTrace();
}
return numberPane;
}
@Override
public JComponent createComponent() {
Icon folderIcon = IconLoader.get().getUIAwareIcon("files/folder.svg", 19, 19);
JTabFrame tabFrame = new JTabFrame();
for (Alignment o : Alignment.values()) {
if (o != Alignment.CENTER) {
@ -73,7 +86,6 @@ public class TabFrameDemo {
panel.add(label);
tabbedPopup.getTabbedPane().addTab("Tab " + i, panel);
}
tabFrame.setComponentAt(new JScrollPane(createTree()), Alignment.NORTH_WEST, 0);
/* Activate for custom tab demo.
tabFrame.setUserTabComponentAt(new JLabel("NORTH (custom tab)") {{
setBorder(new EmptyBorder(0, 5, 0, 5));
@ -85,63 +97,13 @@ public class TabFrameDemo {
tabFrame.setAcceleratorAt(1, Alignment.NORTH_WEST, 0);
JPanel contentPane = new JPanel(new BorderLayout());
JPanel topPanel = new JPanel(new GridBagLayout());
topPanel.add(new JButton("I do nothing!"), null);
topPanel.setBorder(DarkBorders.createLineBorder(0, 0, 1, 0));
contentPane.add(topPanel, BorderLayout.NORTH);
contentPane.add(tabFrame, BorderLayout.CENTER);
frame.setContentPane(contentPane);
tabFrame.setContent(createTextArea());
frame.pack();
frame.setSize(1000, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
}
@NotNull
protected static JTree createTree() {
DefaultMutableTreeNode root = new DefaultMutableTreeNode("States");
DefaultMutableTreeNode parent1 = new DefaultMutableTreeNode("Andhra Pradesh");
DefaultMutableTreeNode child = new DefaultMutableTreeNode("Vijayawada");
DefaultMutableTreeNode child1 = new SelectableTreeNode("This node can be selected", true);
DefaultMutableTreeNode parent2 = new DefaultMutableTreeNode("Telangana");
DefaultMutableTreeNode child2 = new DefaultMutableTreeNode("Hyderabad");
// Adding child nodes to parent
parent1.add(child);
parent1.add(child1);
parent2.add(child2);
// Adding parent nodes to root
root.add(parent1);
root.add(parent2);
// Adding root to JTree
JTree tree = new JTree(root);
tree.setEditable(true);
// tree.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
return tree;
return tabFrame;
}
@NotNull
private static Component createTextArea() {
NumberedTextComponent numberPane = new NumberedTextComponent(new NonWrappingTextPane() {{
setText(StringUtil.repeat(DemoResources.LOREM_IPSUM, 10));
setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));
}});
NumberingPane numbering = numberPane.getNumberingPane();
Icon icon = IconLoader.get().getIcon("navigation/arrowRight.svg");
try {
numbering.addIconAtLine(5, icon);
numbering.addIconAtLine(10, icon);
numbering.addIconAtLine(15, icon);
} catch (BadLocationException e) {
e.printStackTrace();
}
return numberPane;
@Override
public String getTitle() {
return "TabFrame Demo";
}
}

Loading…
Cancel
Save