Browse Source

Added ScrollPane demo.

Signed-off-by: weisj <weisj@arcor.de>
pull/27/head
weisj 5 years ago
parent
commit
1b3fee5a70
  1. 34
      src/test/java/ScrollPaneDemo.java
  2. 3
      src/test/java/TabFrameDemo.java
  3. 4
      src/test/java/demo/ComponentDemo.java
  4. 7
      src/test/java/demo/DemoPanel.java
  5. 6
      src/test/java/demo/DemoResources.java
  6. 38
      src/test/java/demo/SolidColorComponent.java
  7. 87
      src/test/java/demo/scrollPane/ScrollPaneDemo.java

34
src/test/java/ScrollPaneDemo.java

@ -1,34 +0,0 @@
import com.github.weisj.darklaf.LafManager;
import com.github.weisj.darklaf.util.StringUtil;
import org.jdesktop.swingx.MultiSplitLayout;
import javax.swing.*;
import java.awt.*;
/**
* @author Jannis Weis
* @since 2019
*/
public final class ScrollPaneDemo extends MultiSplitLayout {
public static void main(final String[] args) {
SwingUtilities.invokeLater(() -> {
LafManager.install();
final JFrame frame = new JFrame();
frame.setSize(500, 500);
JTextPane overlayScroll = new JTextPane() {{
setText(StringUtil.repeat(TestResources.LOREM_IPSUM, 10));
setFont(Font.getFont(Font.MONOSPACED));
// setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
// SimpleAttributeSet attribs = new SimpleAttributeSet();
// StyleConstants.setAlignment(attribs, StyleConstants.ALIGN_RIGHT);
// setParagraphAttributes(attribs, true);
}};
frame.setContentPane(new JPanel(new BorderLayout()) {{
add(overlayScroll, BorderLayout.CENTER);
}});
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
});
}
}

3
src/test/java/TabFrameDemo.java

@ -9,6 +9,7 @@ import com.github.weisj.darklaf.components.text.NumberedTextComponent;
import com.github.weisj.darklaf.components.text.NumberingPane; import com.github.weisj.darklaf.components.text.NumberingPane;
import com.github.weisj.darklaf.icons.IconLoader; import com.github.weisj.darklaf.icons.IconLoader;
import com.github.weisj.darklaf.util.StringUtil; import com.github.weisj.darklaf.util.StringUtil;
import demo.DemoResources;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import javax.swing.*; import javax.swing.*;
@ -126,7 +127,7 @@ public class TabFrameDemo {
@NotNull @NotNull
private static Component createTextArea() { private static Component createTextArea() {
NumberedTextComponent numberPane = new NumberedTextComponent(new NonWrappingTextPane() {{ NumberedTextComponent numberPane = new NumberedTextComponent(new NonWrappingTextPane() {{
setText(StringUtil.repeat(TestResources.LOREM_IPSUM, 10)); setText(StringUtil.repeat(DemoResources.LOREM_IPSUM, 10));
setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14)); setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));
}}); }});
NumberingPane numbering = numberPane.getNumberingPane(); NumberingPane numbering = numberPane.getNumberingPane();

4
src/test/java/demo/ComponentDemo.java

@ -34,7 +34,9 @@ public interface ComponentDemo {
static void showDemo(final ComponentDemo demo) { static void showDemo(final ComponentDemo demo) {
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
LafManager.install(); LafManager.install();
JFrame frame = DemoPanel.createFrame(); JFrame frame = new JFrame();
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setTitle(demo.getTitle()); frame.setTitle(demo.getTitle());
frame.setContentPane(demo.createComponent()); frame.setContentPane(demo.createComponent());
frame.pack(); frame.pack();

7
src/test/java/demo/DemoPanel.java

@ -43,13 +43,6 @@ public class DemoPanel extends JPanel {
add(controls, BorderLayout.SOUTH); add(controls, BorderLayout.SOUTH);
} }
public static JFrame createFrame() {
JFrame frame = new JFrame();
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
return frame;
}
public JPanel getControls() { public JPanel getControls() {
return controls; return controls;
} }

6
src/test/java/TestResources.java → src/test/java/demo/DemoResources.java

@ -1,7 +1,7 @@
/* /*
* MIT License * MIT License
* *
* Copyright (c) 2019 Jannis Weis * Copyright (c) 2020 Jannis Weis
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
@ -21,7 +21,9 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. * SOFTWARE.
*/ */
public class TestResources { package demo;
public class DemoResources {
public static final String LOREM_IPSUM = public static final String LOREM_IPSUM =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. In tempor quis nibh a semper. Nullam\n" "Lorem ipsum dolor sit amet, consectetur adipiscing elit. In tempor quis nibh a semper. Nullam\n"
+ " auctor, erat non viverra commodo, libero orci aliquam quam, ac interdum nunc est sed\n " + " auctor, erat non viverra commodo, libero orci aliquam quam, ac interdum nunc est sed\n "

38
src/test/java/demo/SolidColorComponent.java

@ -0,0 +1,38 @@
/*
* MIT License
*
* Copyright (c) 2020 Jannis Weis
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package demo;
import javax.swing.*;
import java.awt.*;
public class SolidColorComponent extends JPanel {
public SolidColorComponent(final Color color, final int width, final int height) {
setBackground(color);
Dimension size = new Dimension(width, height);
setPreferredSize(size);
setMinimumSize(size);
setMaximumSize(size);
}
}

87
src/test/java/demo/scrollPane/ScrollPaneDemo.java

@ -0,0 +1,87 @@
/*
* MIT License
*
* Copyright (c) 2020 Jannis Weis
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package demo.scrollPane;
import demo.ComponentDemo;
import demo.DemoPanel;
import demo.DemoResources;
import demo.SolidColorComponent;
import javax.swing.*;
import java.awt.*;
/**
* @author Jannis Weis
* @since 2019
*/
public final class ScrollPaneDemo implements ComponentDemo {
public static void main(final String[] args) {
ComponentDemo.showDemo(new ScrollPaneDemo());
}
@Override
public JComponent createComponent() {
JScrollPane scrollPane = new JScrollPane();
scrollPane.setViewportView(new JPanel() {{
add(new JTextArea() {{
setText(DemoResources.LOREM_IPSUM);
}});
}});
JPanel upperLeft = new SolidColorComponent(Color.RED, 20, 20);
JPanel upperRight = new SolidColorComponent(Color.RED, 20, 20);
JPanel lowerLeft = new SolidColorComponent(Color.RED, 20, 20);
JPanel lowerRight = new SolidColorComponent(Color.RED, 20, 20);
DemoPanel panel = new DemoPanel(scrollPane);
JPanel controlPanel = panel.getControls();
controlPanel.setLayout(new GridLayout(3, 2));
controlPanel.add(new JCheckBox("LeftToRight") {{
setSelected(scrollPane.getComponentOrientation().isLeftToRight());
addActionListener(e -> scrollPane.setComponentOrientation(isSelected() ? ComponentOrientation.LEFT_TO_RIGHT
: ComponentOrientation.RIGHT_TO_LEFT));
}});
controlPanel.add(new JLabel());
controlPanel.add(new JCheckBox("UpperLeft corner") {{
addActionListener(e -> scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, isSelected() ? upperLeft : null));
}});
controlPanel.add(new JCheckBox("UpperRight corner") {{
addActionListener(e -> scrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, isSelected() ? upperRight : null));
}});
controlPanel.add(new JCheckBox("LowerLeft corner") {{
addActionListener(e -> scrollPane.setCorner(JScrollPane.LOWER_LEFT_CORNER, isSelected() ? lowerLeft : null));
}});
controlPanel.add(new JCheckBox("LowerRight corner") {{
addActionListener(e -> scrollPane.setCorner(JScrollPane.LOWER_RIGHT_CORNER, isSelected() ? lowerRight : null));
}});
return panel;
}
@Override
public String getTitle() {
return "ScrollPane Demo";
}
}
Loading…
Cancel
Save