Skip to content

Commit

Permalink
Merge branch 'TAPAAL:main' into smart-draw-layout-2038420
Browse files Browse the repository at this point in the history
  • Loading branch information
mtygesen authored Oct 6, 2023
2 parents 2e97df9 + 2c98a30 commit d8ca3ba
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 34 deletions.
3 changes: 2 additions & 1 deletion src/main/java/dk/aau/cs/model/tapn/TimedPlace.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public void setNumberOfTokens(int numberOfTokens) {
}

public void resetNumberOfTokens() {
numberOfTokens = 0;
this.numberOfTokens = 0;
this.tokens().clear();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/tapaal/gui/GuiFrameController.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public void showAbout() {
buffer.append("TAPAAL GUI and Translations:\n");
buffer.append("Mathias Andersen, Sine V. Birch, Jacob Hjort Bundgaard, Joakim Byg, Malo Dautry, \nJakob Dyhr, Louise Foshammer, Malte Neve-Gr\u00E6sb\u00F8ll, ");
buffer.append("Lasse Jacobsen, Morten Jacobsen,\nThomas S. Jacobsen, Jacob J. Jensen, Peter G. Jensen, ");
buffer.append("Mads Johannsen,\nKenneth Y. J\u00F8rgensen, Mikael H. M\u00F8ller, Christoffer Moesgaard, Kristian Morsing Pedersen,\nThomas Pedersen, Lena S. Ernstsen, Niels N. Samuelsen, Jiri Srba, Mathias G. S\u00F8rensen,\nJakob H. Taankvist and Peter H. Taankvist\n");
buffer.append("Mads Johannsen,\nKenneth Y. J\u00F8rgensen, Mikael H. M\u00F8ller, Christoffer Moesgaard, Kristian Morsing Pedersen,\nThomas Pedersen, Lena S. Ernstsen, Niels N. Samuelsen, Jiri Srba, Mathias G. S\u00F8rensen,\nJakob H. Taankvist, Peter H. Taankvist and Mikkel Tygesen\n");

buffer.append("Aalborg University 2008-2023\n\n");

Expand All @@ -258,7 +258,7 @@ public void showAbout() {
buffer.append("Aalborg University 2012-2023\n\n");

buffer.append("TAPAAL Untimed Engine (verifypn):\n");
buffer.append("Alexander Bilgram, Frederik M. B\u00F8nneland, Jakob Dyhr, Peter Fogh, ");
buffer.append("Alexander Bilgram, Frederik M. B\u00F8nneland, Jakob Dyhr, Malo Dautry, Peter Fogh, ");
buffer.append("Jonas F. Jensen,\nLasse S. Jensen, Peter G. Jensen, Nicolaj \u00D8. Jensen,");
buffer.append("Tobias S. Jepsen,\nMads Johannsen, Kenneth Y. J\u00F8rgensen, Mads Johannsen, Isabella Kaufmann,\n");
buffer.append("Andreas H. Klostergaard, S\u00F8ren M. Nielsen, Thomas S. Nielsen, ");
Expand Down
25 changes: 18 additions & 7 deletions src/main/java/net/tapaal/gui/petrinet/dialog/QueryDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@

import javax.swing.*;
import javax.swing.border.LineBorder;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Vector;

import javax.swing.event.*;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.SimpleAttributeSet;
Expand Down Expand Up @@ -414,6 +409,7 @@ private QueryDialog(EscapableDialog me, QueryDialogueOption option, TAPNQuery qu

setLayout(new GridBagLayout());


init(option, queryToCreateFrom);
makeShortcuts();
toggleAdvancedSimpleView(false);
Expand Down Expand Up @@ -687,11 +683,25 @@ public static TAPNQuery showQueryDialogue(QueryDialogueOption option, TAPNQuery

// 2 Add query editor
QueryDialog queryDialogue = new QueryDialog(guiDialog, option, queryToRepresent, tapnNetwork, guiModels, lens, tab);
contentPane.add(queryDialogue);

guiDialog.setResizable(false);

// Make window fit contents' preferred size
// setResizable seems to be platform dependent so use scrolling as a fallback
JScrollPane scrollPane = new JScrollPane(queryDialogue);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setBorder(null);

GridBagConstraints gbc = new GridBagConstraints();
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.BOTH;

contentPane.add(scrollPane, gbc);

// Make window fit contents' preferred size
guiDialog.pack();

// 'hack' for hiding the trace drop-down menu for HyperLTL on intial launch of the query dialogue panel
Expand Down Expand Up @@ -1502,6 +1512,7 @@ private void init(QueryDialogueOption option, final TAPNQuery queryToCreateFrom)
setEnabledReductionOptions();

rootPane.setDefaultButton(saveAndVerifyButton);

disableAllQueryButtons();
setSaveButtonsEnabled();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@

public class ColorComboBoxRenderer extends JLabel implements ListCellRenderer {
final JComboBox comboBox;
final int adjust;

public ColorComboBoxRenderer(JComboBox comboBox) {
this(comboBox, 0);
}

public ColorComboBoxRenderer(JComboBox comboBox, int adjust) {
this.comboBox = comboBox;
this.adjust = adjust;
}

public Component getListCellRendererComponent(
Expand All @@ -17,34 +24,52 @@ public Component getListCellRendererComponent(
int index,
boolean isSelected,
boolean cellHasFocus) {
if(value instanceof JSeparator){
return new JSeparator(JSeparator.HORIZONTAL);

if (value instanceof JSeparator){
return new JSeparator(JSeparator.HORIZONTAL);
}
else if(value instanceof Variable){
setText(ellipsis(((Variable)value).getName(), comboBox.getWidth() / 7));
else if (value instanceof Variable){
String text = ((Variable)value).getName();

setText(ellipsis(text, maxChars(text, list, adjust)));
setFont(list.getFont());
}
else if(value != null) {
setText(ellipsis(value.toString(), comboBox.getWidth() / 7));

else if (value != null) {
String text = value.toString();

setText(ellipsis(text, maxChars(text, list, adjust)));
setFont(list.getFont());
}

return this;
}
//From here https://stackoverflow.com/questions/3597550/ideal-method-to-truncate-a-string-with-ellipsis


// Calculates max possible chars that can be shown on list - padding
private int maxChars(String text, JList list, int adjust) {
FontMetrics metrics = list.getFontMetrics(list.getFont());

int width = 0;
int comboBoxWidth = comboBox.getWidth();

for (int i = 0; i < text.length(); ++i) {
int cWidth = metrics.charWidth(text.charAt(i));

if (width + cWidth > comboBoxWidth) {
return i - adjust;
}

width += cWidth;
}

return text.length();
}


// Inspired by: https://stackoverflow.com/questions/3597550/ideal-method-to-truncate-a-string-with-ellipsis
public static String ellipsis(final String text, int length)
{
if(length > 3) {
// The letters [iIl1] are slim enough to only count as half a character.
length += Math.ceil(text.replaceAll("[^iIl]", "").length() / 2.0d);

if (text.length() > length) {
return text.substring(0, length - 3) + "...";
}
if (length > 3 && text.length() > length) {
return text.substring(0, length - 3) + "...";
}

return text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@ public void updateColorType(ColorType ct, Context context, boolean includePlaceH

private JComboBox createColoredCombobox(Context context, ColorType ct, boolean includePlaceHolder) {
JComboBox combobox = new JComboBox<>();
combobox.setRenderer(new ColorComboBoxRenderer(combobox));
combobox.setRenderer(new ColorComboBoxRenderer(combobox, 2));
combobox.setPreferredSize(new Dimension(200,25));

combobox.setMaximumRowCount(20);

if (includePlaceHolder) {
combobox.addItem(new PlaceHolderColorExpression());
combobox.addItem(new JSeparator());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class ColorTypeDialogPanel extends JPanel {

private JScrollPane scrollPane;


private static final int MAXIMUM_INTEGER = 10000;

public ColorTypeDialogPanel(ConstantsPane.ColorTypesListModel colorTypesListModel,
Expand Down Expand Up @@ -88,12 +89,16 @@ public ColorTypeDialogPanel(ConstantsPane.ColorTypesListModel colorTypesListMode

public void showDialog() {
dialog = new EscapableDialog(TAPAALGUI.getApp(), "Edit color type", true);

scrollPane.setBorder(null);

dialog.add(scrollPane, BorderLayout.CENTER);
dialog.getRootPane().setDefaultButton(okButton);
dialog.setResizable(true);
dialog.pack();
//size of range of integers panel
dialog.setMinimumSize(new Dimension(447, 231));

dialog.setLocationRelativeTo(null);
dialog.setVisible(true);
}
Expand Down Expand Up @@ -387,6 +392,7 @@ private JPanel createCyclicAndFiniteEnumerationPanel() {
final JPanel cyclicAndFiniteEnumeration = new JPanel();
cyclicAndFiniteEnumeration.setLayout(new GridBagLayout());
cyclicAndFiniteEnumeration.setBorder(BorderFactory.createTitledBorder("Cyclic and Finite Enumeration"));
cyclicAndFiniteEnumeration.setPreferredSize(new Dimension(450, 250));
//cyclicAndFiniteEnumeration.setSize(550,300);
JButton moveUpButton = new JButton(new ImageIcon(Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource("Images/Up.png"))));
JButton moveDownButton = new JButton(new ImageIcon(Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource("Images/Down.png"))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,8 @@ private void initExprField () {
exprField.setBackground(java.awt.Color.white);

exprField.setEditable(false);
exprField.setToolTipText("Tooltip missing");
exprField.setToolTipText("<html>Click on a part of the query you want to edit.<br />" +
"(Queries can also be edited manually by pressing the \"Edit Query\" button.)</html>");

JScrollPane exprScrollPane = new JScrollPane(exprField);
exprScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,8 @@ private void initExprField() {

exprField.setBackground(java.awt.Color.white);
exprField.setEditable(false);
exprField.setToolTipText("Tooltip missing");
exprField.setToolTipText("<html>Click on a part of the query you want to edit.<br />" +
"(Queries can also be edited manually by pressing the \"Edit Query\" button.)</html>");

JScrollPane exprScrollPane = new JScrollPane(exprField);
exprScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import javax.swing.event.ListSelectionEvent;
Expand Down Expand Up @@ -401,7 +402,14 @@ private void showSharedPlaceNameDialog(SharedPlace placeToEdit) {
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));

JPanel panel = new SharedPlaceNamePanel(guiDialog.getRootPane(), sharedPlacesListModel, new Context(tab), placeToEdit);
contentPane.add(panel);

// setResizable seems to be platform dependent so use scrolling as a fallback
JScrollPane scrollPane = new JScrollPane(panel);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setBorder(null);

contentPane.add(scrollPane);

guiDialog.setResizable(false);
guiDialog.pack();
Expand Down
20 changes: 18 additions & 2 deletions src/main/java/net/tapaal/gui/petrinet/editor/TemplateExplorer.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javax.swing.KeyStroke;
import javax.swing.ListCellRenderer;
import javax.swing.ListSelectionModel;
import javax.swing.ScrollPaneConstants;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import javax.swing.event.ListSelectionEvent;
Expand Down Expand Up @@ -551,8 +552,16 @@ private void initComponentsOfNewTemplateDialog(String nameToShow) {

private void ShowNewTemplateDialog(String nameToShow) {
dialog = new EscapableDialog(TAPAALGUI.getApp(), "Enter Component Name", true);

initComponentsOfNewTemplateDialog(nameToShow);
dialog.add(container);

// setResizable seems to be platform dependent so use scrolling as a fallback
JScrollPane scrollPane = new JScrollPane(container);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setBorder(null);

dialog.add(scrollPane);
dialog.setResizable(false);
dialog.pack();
dialog.setLocationRelativeTo(null);
Expand Down Expand Up @@ -635,7 +644,14 @@ private void showRenameTemplateDialog(String nameToShow) {
else {
initComponentsOfRenameTemplateDialog(nameToShow);
}
dialog.add(container);

// setResizable seems to be platform dependent so use scrolling as a fallback
JScrollPane scrollPane = new JScrollPane(container);
scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setBorder(null);

dialog.add(scrollPane);
dialog.setResizable(false);
dialog.pack();
dialog.setLocationRelativeTo(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void showDialog() {

dialog = new EscapableDialog(TAPAALGUI.getApp(),
panelHeader, true);
scrollPane.setBorder(null);
dialog.add(scrollPane, BorderLayout.CENTER);
dialog.getRootPane().setDefaultButton(okButton);
dialog.setResizable(false);
Expand Down Expand Up @@ -174,6 +175,9 @@ private void createColorTypesComboBox() {

colorTypeComboBox = new JComboBox();

colorTypeComboBox.setPreferredSize(new Dimension(330, 30));
colorTypeComboBox.setRenderer(new ColorComboBoxRenderer(colorTypeComboBox, -4));

int selectedVariableIndex = 0; int index = 0;
for (ColorType element : colorTypes) {
colorTypeComboBox.addItem(element);
Expand All @@ -198,7 +202,7 @@ private void createColorTypesComboBox() {
gbc.gridwidth = 1;
gbc.anchor = GridBagConstraints.EAST;
gbc.fill = GridBagConstraints.HORIZONTAL;
container.add(colorTypeComboBox,gbc);
container.add(colorTypeComboBox, gbc);
}

private void createOKButton() {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/pipe/gui/petrinet/editor/GuardDialogue.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public GuardDialogue(JRootPane rootPane, PetriNetObject objectToBeEdited, Contex
scrollPane.setViewportView(mainPanel);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
scrollPane.setBorder(null);

initTimeGuardPanel();

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/pipe/gui/petrinet/editor/PlaceEditorPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ public PlaceEditorPanel(EscapableDialog parent,JRootPane rootPane, TimedPlaceCom
else originalExpression = null;
hideIrrelevantInformation();
scrollPane.setViewportView(mainPanel);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
scrollPane.setBorder(null);
add(scrollPane, BorderLayout.CENTER);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ public void actionPerformed(ActionEvent arg0) {
scrollPane.setViewportView(mainPanel);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollPane.setBorder(null);
add(scrollPane, BorderLayout.CENTER);
}

Expand Down

0 comments on commit d8ca3ba

Please sign in to comment.