Skip to content

Commit

Permalink
wrapped text area with extra panel
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Reimann committed Mar 15, 2018
1 parent f11d5c9 commit 77e4262
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 41 deletions.
@@ -1,18 +1,23 @@
/*******************************************************************************
* Copyright (c) 2014 Opt4J
*
* 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:
* 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 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.
* 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 org.opt4j.core.config.visualization;
Expand All @@ -26,8 +31,10 @@
/**
* The {@link DialogLayout} is used for label-field pair layout.
*
* @see <a href="http://www.javafaq.nu/java-allbooks-8.html">http://www.javafaq.nu/java-allbooks-8.html</a>
* @see <a href="http://www.javafaq.nu/java-bookpage-15-5.html">http://www.javafaq.nu/java-bookpage-15-5.html</a>
* @see <a href=
* "http://www.javafaq.nu/java-allbooks-8.html">http://www.javafaq.nu/java-allbooks-8.html</a>
* @see <a href=
* "http://www.javafaq.nu/java-bookpage-15-5.html">http://www.javafaq.nu/java-bookpage-15-5.html</a>
*
* @author lukasiewycz
*
Expand Down Expand Up @@ -63,7 +70,8 @@ public DialogLayout(int hGap, int vGap) {
/*
* (non-Javadoc)
*
* @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
* @see java.awt.LayoutManager#addLayoutComponent(java.lang.String,
* java.awt.Component)
*/
@Override
public void addLayoutComponent(String name, Component comp) {
Expand Down Expand Up @@ -132,13 +140,10 @@ public void layoutContainer(Container parent) {
int w = parent.getWidth() - insets.left - insets.right - divider;
int x = insets.left;
int y = insets.top;
System.out.println("divider: " + divider + " parent.width: " + parent.getWidth());
for (int k = 1; k < parent.getComponentCount(); k += 2) {
Component comp1 = parent.getComponent(k - 1);
Component comp2 = parent.getComponent(k);
Dimension d = comp2.getPreferredSize();
System.out.println("[" + x + "," + y + "," + (divider - hGap) + "," + d.height + "][" + (x + divider) + ","
+ y + "," + w + "," + d.height + "]");
comp1.setBounds(x, y, divider - hGap, d.height);
comp2.setBounds(x + divider, y, w, d.height);
y += d.height + vGap;
Expand All @@ -164,11 +169,9 @@ protected int getDivider(Container parent) {
Component comp = parent.getComponent(k);
Dimension d = comp.getPreferredSize();
divider = Math.max(divider, d.width);
System.out.println(d.width + "--> max: " + divider);
}

divider += hGap;
System.out.println("getDivider=" + Math.max(divider, half));
return Math.max(divider, half);

}
Expand Down
@@ -1,18 +1,23 @@
/*******************************************************************************
* Copyright (c) 2014 Opt4J
*
* 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:
* 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 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.
* 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 org.opt4j.core.config.visualization;
Expand Down Expand Up @@ -59,8 +64,8 @@
import org.opt4j.core.config.annotations.File;

/**
* The {@link PropertyPanel} is a panel for the configuration of one module. Properties and values are arranged in a
* table.
* The {@link PropertyPanel} is a panel for the configuration of one module.
* Properties and values are arranged in a table.
*
* @author lukasiewycz
*
Expand All @@ -79,7 +84,8 @@ public class PropertyPanel extends JPanel {
protected final Map<Property, Component> components = new HashMap<Property, Component>();

/**
* Constructs a {@link PropertyPanel} for one {@link PropertyModule} instance.
* Constructs a {@link PropertyPanel} for one {@link PropertyModule}
* instance.
*
* @param module
* the instance of the {@link PropertyModule}
Expand All @@ -98,11 +104,10 @@ public PropertyPanel(PropertyModule module, FileChooser fileChooser, Format form
panel = new JPanel(new DialogLayout(20, 2));
panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

updatePropertyPanel();
update();

setLayout(new BorderLayout());
add(BorderLayout.NORTH, panel);

update();
}

protected Component createComponent(final Property property) {
Expand Down Expand Up @@ -283,12 +288,12 @@ public void actionPerformed(ActionEvent e) {
}

/**
* Adds a row showing the {@link Citation}. On the left hand side, "reference" is printed while on the right hand
* side, the {@link Citation} is added in a static {@link TextArea}.
* Adds a row showing the {@link Citation}. On the left hand side,
* "reference" is printed while on the right hand side, the {@link Citation}
* is added in a static {@link TextArea}.
*
* @param citation
* the {@link Citation}
* @return
* the citation to add
*/
protected void addReferenceRow(Citation citation) {
JPanel labelPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
Expand All @@ -304,9 +309,9 @@ protected void addReferenceRow(Citation citation) {
field.setFont(label.getFont());
field.setBackground(label.getBackground());
field.setEditable(false);
field.setPreferredSize(
new Dimension((int) (panel.getPreferredSize().width * 0.70), field.getMaximumSize().height));
field.setText(Format.formatJava(citation));
System.out.println("title: " + citation.title());
System.out.println("formatJava: " + Format.formatJava(citation));

if (!citation.doi().isEmpty()) {
final String doi = citation.doi();
Expand Down Expand Up @@ -341,7 +346,12 @@ public void mouseClicked(MouseEvent e) {
}
});
}
panel.add(field);

JPanel rightPanel = new JPanel(new BorderLayout());
rightPanel.add(BorderLayout.NORTH, field);
rightPanel.setPreferredSize(
new Dimension((int) (panel.getPreferredSize().width * 0.70), panel.getPreferredSize().height));
panel.add(rightPanel);
}

protected void update() {
Expand Down

0 comments on commit 77e4262

Please sign in to comment.