file_name
stringlengths
6
86
file_path
stringlengths
45
249
content
stringlengths
47
6.26M
file_size
int64
47
6.26M
language
stringclasses
1 value
extension
stringclasses
1 value
repo_name
stringclasses
767 values
repo_stars
int64
8
14.4k
repo_forks
int64
0
1.17k
repo_open_issues
int64
0
788
repo_created_at
stringclasses
767 values
repo_pushed_at
stringclasses
767 values
LayerInfoPanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/LayerInfoPanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * */ package org.wandora.application.gui.topicpanels; import java.awt.Color; import java.awt.FlowLayout; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Collection; import java.util.HashMap; import java.util.Map; import javax.swing.Icon; import javax.swing.JMenu; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JSeparator; import org.wandora.application.CancelledException; import org.wandora.application.LocatorHistory; import org.wandora.application.Wandora; import org.wandora.application.gui.LayerTree; import org.wandora.application.gui.UIBox; import org.wandora.application.gui.UIConstants; import org.wandora.application.gui.simple.SimpleButton; import org.wandora.application.gui.simple.SimpleLabel; import org.wandora.application.gui.simple.SimpleToggleButton; import org.wandora.exceptions.OpenTopicNotSupportedException; import org.wandora.topicmap.Association; import org.wandora.topicmap.Locator; import org.wandora.topicmap.Topic; import org.wandora.topicmap.TopicMap; import org.wandora.topicmap.TopicMapException; import org.wandora.topicmap.TopicMapStatOptions; import org.wandora.topicmap.layered.Layer; import org.wandora.utils.ClipboardBox; /** * * @author akivela */ public class LayerInfoPanel implements ActionListener, TopicPanel, Runnable { private SimpleButton copyButton = null; private SimpleToggleButton trackChangesButton = null; private JPanel infoPanel = null; private Wandora wandora = null; private TopicMap map = null; private StringBuilder stats = null; private boolean trackChanges = false; private JPanel buttonPanel = null; private Map<Object, SimpleLabel> fieldLabels = null; private Map<Integer, String> originalValues = null; private boolean requiresRefresh = false; private Thread refresher = null; public LayerInfoPanel() { } @Override public void init() { wandora = Wandora.getWandora(); infoPanel = new JPanel(); infoPanel.setLayout(new GridBagLayout()); fieldLabels = new HashMap<>(); initInfo(); refresher = new Thread(this); refresher.start(); } @Override public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if(cmd != null) { if("Refresh".equalsIgnoreCase(cmd)) { if(infoPanel != null) { infoPanel.removeAll(); initInfo(); infoPanel.revalidate(); infoPanel.repaint(); } } else if("Copy info".equalsIgnoreCase(cmd)) { copyActionPerformed(); } else if("Track changes".equalsIgnoreCase(cmd)) { trackChangesActionPerformed(); trackChangesButton.setSelected(trackChanges); trackChangesButton.revalidate(); trackChangesButton.repaint(); } } } public void trackChangesActionPerformed() { trackChanges = !trackChanges; if(trackChanges) { originalValues = null; } if(infoPanel != null) { initInfo(); infoPanel.revalidate(); infoPanel.repaint(); } } public void copyActionPerformed() { if(stats != null) { ClipboardBox.setClipboard(stats.toString()); } else { ClipboardBox.setClipboard("n.a."); } } @Override public boolean supportsOpenTopic() { return false; } @Override public void open(Topic topic) throws TopicMapException, OpenTopicNotSupportedException { } @Override public void stop() { refresher.interrupt(); } public void initInfo() { map = getCurrentTopicMap(); int[] statOptions = TopicMapStatOptions.getAvailableOptions(); int bagCount = 0; stats = new StringBuilder(); GridBagConstraints gbc = null; SimpleLabel statDescription = null; SimpleLabel statValue = null; String statDescriptionString = null; String statString = "n.a."; String originalStatString = "n.a."; gbc=new GridBagConstraints(); Insets rowInsets = new Insets(0, 9, 0, 9); gbc.insets = new Insets(9, 9, 0, 9); infoPanel.removeAll(); gbc.gridy=bagCount++; gbc.gridx=0; gbc.weightx=1; gbc.fill=GridBagConstraints.HORIZONTAL; String layerName = getCurrentLayerName(); SimpleLabel layerNameLabel = new SimpleLabel(layerName); layerNameLabel.setFont(UIConstants.largeLabelFont); fieldLabels.put("title", layerNameLabel); infoPanel.add(layerNameLabel, gbc); stats.append(layerName).append("\n"); boolean fillOriginalValues = false; if(originalValues == null) { originalValues = new HashMap<>(); fillOriginalValues = true; } for(int i=0; i<statOptions.length; i++) { try { gbc.gridy=bagCount++; gbc.gridx=0; gbc.weightx=0.5; gbc.gridwidth=1; gbc.fill=GridBagConstraints.HORIZONTAL; statDescriptionString = TopicMapStatOptions.describeStatOption(statOptions[i]); stats.append(statDescriptionString); statDescription = new SimpleLabel(statDescriptionString); infoPanel.add(statDescription, gbc); gbc.gridx=1; statString = "n.a."; try { if(map != null) { statString = map.getStatistics(new TopicMapStatOptions(statOptions[i])).toString(); if(fillOriginalValues) { originalValues.put(statOptions[i], statString); } } } catch(Exception e) { e.printStackTrace(); } if(trackChanges) { originalStatString = originalValues.get(statOptions[i]).toString(); stats.append("\t").append(originalStatString); SimpleLabel originalValue = new SimpleLabel(originalStatString); originalValue.setHorizontalAlignment(SimpleLabel.RIGHT); fieldLabels.put("o"+statOptions[i], originalValue); infoPanel.add(originalValue, gbc); gbc.gridx=2; } Color statValueColor = Color.BLACK; if(trackChanges) { try { int statInt = Integer.parseInt(statString); int originalInt = Integer.parseInt(originalStatString); int delta = statInt - originalInt; statString = (delta > 0 ? "+"+delta : ""+delta); if(delta > 0) statValueColor = Color.green.darker(); else if(delta < 0) statValueColor = Color.red.darker(); } catch(Exception e) {} } stats.append("\t").append(statString); statValue = new SimpleLabel(statString); statValue.setForeground(statValueColor); statValue.setHorizontalAlignment(SimpleLabel.RIGHT); fieldLabels.put(statOptions[i], statValue); infoPanel.add(statValue, gbc); stats.append("\n"); gbc.gridy=bagCount++; gbc.gridx=0; gbc.weightx=1; gbc.gridwidth=trackChanges ? 3 : 2; gbc.insets = rowInsets; JSeparator js = new JSeparator(JSeparator.HORIZONTAL); js.setForeground(new Color(0x909090)); infoPanel.add(js, gbc); } catch(Exception e) { e.printStackTrace(); } } gbc.gridx=0; gbc.gridy=bagCount++; gbc.weightx=0; gbc.weightx=0; gbc.fill=GridBagConstraints.NONE; gbc.insets = new Insets(9, 9, 9, 9); JPanel buttonPanel = getButtonPanel(); infoPanel.add(buttonPanel, gbc); gbc.gridy=bagCount++; gbc.weightx=1; gbc.weighty=1; gbc.fill=GridBagConstraints.BOTH; infoPanel.add(new JPanel(), gbc); // Filler } public void refreshInfo() { map = getCurrentTopicMap(); int[] statOptions = TopicMapStatOptions.getAvailableOptions(); stats = new StringBuilder(); SimpleLabel statValue = null; String statString = "n.a."; String originalStatString = "n.a."; String layerName = getCurrentLayerName(); SimpleLabel layerNameLabel = fieldLabels.get("title"); if(layerNameLabel != null) { layerNameLabel.setText(layerName); } stats.append(layerName).append("\n"); boolean fillOriginalValues = false; if(originalValues == null) { originalValues = new HashMap<>(); fillOriginalValues = true; } for(int i=0; i<statOptions.length; i++) { try { String statDescriptionString = TopicMapStatOptions.describeStatOption(statOptions[i]); stats.append(statDescriptionString); statString = "n.a."; try { if(map != null) { statString = map.getStatistics(new TopicMapStatOptions(statOptions[i])) + ""; if(fillOriginalValues) { originalValues.put(statOptions[i], statString); } } } catch(Exception e) { e.printStackTrace(); } if(trackChanges) { originalStatString = originalValues.get(statOptions[i]) + ""; stats.append("\t").append(originalStatString); SimpleLabel originalValue = fieldLabels.get("o"+statOptions[i]); if(originalValue != null) { originalValue.setText(originalStatString); } } Color statValueColor = Color.BLACK; if(trackChanges) { try { int statInt = Integer.parseInt(statString); int originalInt = Integer.parseInt(originalStatString); int delta = statInt - originalInt; statString = (delta > 0 ? "+"+delta : ""+delta); if(delta > 0) statValueColor = Color.green.darker(); else if(delta < 0) statValueColor = Color.red.darker(); } catch(Exception e) {} } stats.append("\t").append(statString); statValue = fieldLabels.get(statOptions[i]); if(statValue != null) { statValue.setForeground(statValueColor); statValue.setText(statString); } stats.append("\n"); } catch(Exception e) { e.printStackTrace(); } } } private JPanel getButtonPanel() { if(buttonPanel != null) { return buttonPanel; } else { buttonPanel = new JPanel(); buttonPanel.setLayout(new FlowLayout()); copyButton = new SimpleButton("Copy"); copyButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { copyActionPerformed(); } }); buttonPanel.add(copyButton); trackChangesButton = new SimpleToggleButton("Track changes"); Insets margin = trackChangesButton.getMargin(); margin.left = 4; margin.right = 4; trackChangesButton.setMargin(margin); trackChangesButton.setSelected(trackChanges); trackChangesButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { trackChangesActionPerformed(); } }); buttonPanel.add(trackChangesButton); return buttonPanel; } } private TopicMap getCurrentTopicMap() { LayerTree layerTree = wandora.layerTree; if(layerTree != null) { Layer layer = layerTree.getSelectedLayer(); if(layer != null) { return layer.getTopicMap(); } } return null; } private String getCurrentLayerName() { LayerTree layerTree = wandora.layerTree; if(layerTree != null) { Layer layer = layerTree.getSelectedLayer(); if(layer != null) { return layer.getName(); } } return "n.a."; } @Override public void refresh() throws TopicMapException { if(infoPanel != null) { requiresRefresh = true; } } @Override public void run() { while(!refresher.isInterrupted()) { if(requiresRefresh) { requiresRefresh = false; // System.out.println("RefreshInfo"); refreshInfo(); infoPanel.revalidate(); infoPanel.repaint(); } try { Thread.sleep(300); } catch(InterruptedException e) {} } try { refresher.join(); } catch(InterruptedException e) {} } @Override public boolean applyChanges() throws CancelledException, TopicMapException { return true; } @Override public JPanel getGui() { return infoPanel; } @Override public Topic getTopic() throws TopicMapException { return null; } @Override public String getName(){ return "Layer info"; } @Override public String getTitle() { return "Layer info"; } @Override public Icon getIcon() { return UIBox.getIcon("gui/icons/topic_panel_layer_info.png"); } @Override public boolean noScroll(){ return false; } @Override public int getOrder() { return 9996; } @Override public Object[] getViewMenuStruct() { return new Object[] { //"Refresh", (ActionListener) this, "Copy info", (ActionListener) this, "Track changes", (ActionListener) this, }; } @Override public JMenu getViewMenu() { return UIBox.makeMenu(getViewMenuStruct(), this); } @Override public JPopupMenu getViewPopupMenu() { return UIBox.makePopupMenu(getViewMenuStruct(), this); } @Override public LocatorHistory getTopicHistory() { return null; } // ---------------------------------------------------- TopicMapListener --- @Override public void topicSubjectIdentifierChanged(Topic t, Locator added, Locator removed) throws TopicMapException { refresh(); } @Override public void topicBaseNameChanged(Topic t, String newName, String oldName) throws TopicMapException { refresh(); } @Override public void topicTypeChanged(Topic t, Topic added, Topic removed) throws TopicMapException { refresh(); } @Override public void topicVariantChanged(Topic t, Collection<Topic> scope, String newName, String oldName) throws TopicMapException { refresh(); } @Override public void topicDataChanged(Topic t, Topic type, Topic version, String newValue, String oldValue) throws TopicMapException { refresh(); } @Override public void topicSubjectLocatorChanged(Topic t, Locator newLocator, Locator oldLocator) throws TopicMapException { refresh(); } @Override public void topicRemoved(Topic t) throws TopicMapException { refresh(); } @Override public void topicChanged(Topic t) throws TopicMapException { refresh(); } @Override public void associationTypeChanged(Association a, Topic newType, Topic oldType) throws TopicMapException { refresh(); } @Override public void associationPlayerChanged(Association a, Topic role, Topic newPlayer, Topic oldPlayer) throws TopicMapException { refresh(); } @Override public void associationRemoved(Association a) throws TopicMapException { refresh(); } @Override public void associationChanged(Association a) throws TopicMapException { refresh(); } }
18,512
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
SketchGridPanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/SketchGridPanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * SketchGridPanel.java * * Created on 2013-05-10 */ package org.wandora.application.gui.topicpanels; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.util.Collection; import java.util.List; import javax.swing.Icon; import javax.swing.JMenu; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.table.JTableHeader; import org.wandora.application.CancelledException; import org.wandora.application.LocatorHistory; import org.wandora.application.RefreshListener; import org.wandora.application.Wandora; import org.wandora.application.gui.UIBox; import org.wandora.application.gui.table.TopicGrid; import org.wandora.topicmap.Association; import org.wandora.topicmap.Locator; import org.wandora.topicmap.Topic; import org.wandora.topicmap.TopicMapException; import org.wandora.topicmap.TopicMapListener; /** * * @author akivela */ public class SketchGridPanel extends javax.swing.JPanel implements TopicMapListener, RefreshListener, TopicPanel, ActionListener, ComponentListener { private static final long serialVersionUID = 1L; private int gridWidth = 10; private int gridHeight = 200; private TopicGrid topicGrid; private boolean needsRefresh = false; /** * Creates new form SketchGridPanel */ public SketchGridPanel() { } @Override public void init() { initComponents(); this.addComponentListener(this); scrollPane.getVerticalScrollBar().setUnitIncrement(16); topicGrid = new TopicGrid(Wandora.getWandora()); topicGrid.initialize(gridWidth, gridHeight); contentPanel.add(topicGrid, BorderLayout.CENTER); JTableHeader tableHeader = topicGrid.getTableHeader(); headerPanel.add(tableHeader, BorderLayout.CENTER); } @Override public void doRefresh() throws TopicMapException { } @Override public boolean supportsOpenTopic() { return true; } @Override public void open(Topic topic) throws TopicMapException { List<int[]> cells = topicGrid.getSelectedCells(); if(cells != null && !cells.isEmpty()) { topicGrid.setCurrentTopic(topic); } else { topicGrid.setTopicAt(topic, 0, 0); } } @Override public void stop() { } @Override public void refresh() throws TopicMapException { } @Override public boolean applyChanges() throws CancelledException, TopicMapException { return false; } @Override public JPanel getGui() { return this; } @Override public Topic getTopic() throws TopicMapException { Topic[] cts = topicGrid.getCurrentTopics(); if(cts != null && cts.length > 0) { return cts[0]; } return null; } @Override public String getName() { return "Sketch grid"; } @Override public String getTitle() { return getName(); } @Override public Icon getIcon() { return UIBox.getIcon("gui/icons/topic_panel_grid.png"); } @Override public int getOrder() { return 300; } @Override public boolean noScroll(){ return false; } @Override public Object[] getViewMenuStruct() { return new Object[] {}; } @Override public JPopupMenu getViewPopupMenu() { return UIBox.makePopupMenu(getViewMenuStruct(), this); } @Override public JMenu getViewMenu() { return UIBox.makeMenu(getViewMenuStruct(), this); } @Override public LocatorHistory getTopicHistory() { return null; } @Override public void actionPerformed(ActionEvent e) { } // ------------------------------------------------------------------------- @Override public void componentResized(ComponentEvent e) { handleComponentEvent(e); } @Override public void componentMoved(ComponentEvent e) { handleComponentEvent(e); } @Override public void componentShown(ComponentEvent e) { handleComponentEvent(e); } @Override public void componentHidden(ComponentEvent e) { handleComponentEvent(e); } private void handleComponentEvent(ComponentEvent e) { this.setPreferredSize(new Dimension(50, 50)); } // ------------------------------------------------------------------------- @Override public void topicSubjectIdentifierChanged(Topic t, Locator added, Locator removed) throws TopicMapException { needsRefresh=true; } @Override public void topicBaseNameChanged(Topic t, String newName, String oldName) throws TopicMapException { needsRefresh=true; } @Override public void topicTypeChanged(Topic t, Topic added, Topic removed) throws TopicMapException { needsRefresh=true; } @Override public void topicVariantChanged(Topic t, Collection<Topic> scope, String newName, String oldName) throws TopicMapException { needsRefresh=true; } @Override public void topicDataChanged(Topic t, Topic type, Topic version, String newValue, String oldValue) throws TopicMapException { needsRefresh=true; } @Override public void topicSubjectLocatorChanged(Topic t, Locator newLocator, Locator oldLocator) throws TopicMapException { needsRefresh=true; } @Override public void topicRemoved(Topic t) throws TopicMapException { needsRefresh=true; } @Override public void topicChanged(Topic t) throws TopicMapException { needsRefresh=true; } @Override public void associationTypeChanged(Association a, Topic newType, Topic oldType) throws TopicMapException { needsRefresh=true; } @Override public void associationPlayerChanged(Association a, Topic role, Topic newPlayer, Topic oldPlayer) throws TopicMapException { needsRefresh=true; } @Override public void associationRemoved(Association a) throws TopicMapException { needsRefresh=true; } @Override public void associationChanged(Association a) throws TopicMapException { needsRefresh=true; } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { headerPanel = new javax.swing.JPanel(); scrollPane = new javax.swing.JScrollPane(); contentPanel = new javax.swing.JPanel(); setLayout(new java.awt.BorderLayout()); headerPanel.setLayout(new java.awt.BorderLayout()); add(headerPanel, java.awt.BorderLayout.NORTH); contentPanel.setLayout(new java.awt.BorderLayout()); scrollPane.setViewportView(contentPanel); add(scrollPane, java.awt.BorderLayout.CENTER); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel contentPanel; private javax.swing.JPanel headerPanel; private javax.swing.JScrollPane scrollPane; // End of variables declaration//GEN-END:variables }
8,530
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
WebViewPanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/webview/WebViewPanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * */ package org.wandora.application.gui.topicpanels.webview; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Desktop; import java.awt.Dimension; import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.event.MouseWheelEvent; import java.awt.image.BufferedImage; import java.io.StringWriter; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Hashtable; import java.util.List; import java.util.Map; import javax.swing.JPopupMenu; import javax.swing.SwingUtilities; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.apache.commons.io.IOUtils; import org.w3c.dom.Document; import org.wandora.application.CancelledException; import org.wandora.application.RefreshListener; import org.wandora.application.Wandora; import org.wandora.application.gui.UIBox; import org.wandora.application.gui.WandoraOptionPane; import org.wandora.application.gui.simple.SimpleButton; import org.wandora.application.gui.simple.SimpleField; import org.wandora.application.gui.topicstringify.TopicToString; import org.wandora.application.modulesserver.ModulesWebApp; import org.wandora.application.modulesserver.WandoraModulesServer; import org.wandora.application.tools.browserextractors.BrowserExtractRequest; import org.wandora.application.tools.browserextractors.BrowserExtractorManager; import org.wandora.application.tools.server.HTTPServerTool; import org.wandora.application.tools.webview.AddWebLocationAsOccurrence; import org.wandora.application.tools.webview.AddWebLocationAsSubjectIdentifier; import org.wandora.application.tools.webview.AddWebLocationAsSubjectLocator; import org.wandora.application.tools.webview.AddWebSelectionAsBasename; import org.wandora.application.tools.webview.AddWebSelectionAsOccurrence; import org.wandora.application.tools.webview.AddWebSourceAsOccurrence; import org.wandora.application.tools.webview.CreateWebLocationTopic; import org.wandora.application.tools.webview.OpenFirebugInWebView; import org.wandora.application.tools.webview.OpenOccurrenceInWebView; import org.wandora.application.tools.webview.OpenWebLocationInExternalBrowser; import org.wandora.topicmap.Association; import org.wandora.topicmap.Locator; import org.wandora.topicmap.Topic; import org.wandora.topicmap.TopicMap; import org.wandora.topicmap.TopicMapException; import org.wandora.topicmap.TopicMapListener; import org.wandora.utils.Options; import org.wandora.utils.Tuples.T3; import javafx.application.Platform; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.concurrent.Worker; import javafx.concurrent.Worker.State; import javafx.embed.swing.JFXPanel; import javafx.embed.swing.SwingFXUtils; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.image.WritableImage; import javafx.scene.web.PopupFeatures; import javafx.scene.web.PromptData; import javafx.scene.web.WebEngine; import javafx.scene.web.WebEvent; import javafx.scene.web.WebView; import javafx.util.Callback; import netscape.javascript.JSObject; /** * * @author akivela */ public class WebViewPanel extends javax.swing.JPanel implements TopicMapListener, RefreshListener, ActionListener, ComponentListener { private static final long serialVersionUID = 1L; private static final String JAVASCRIPT_RESOURCE_GET_SELECTED_SOURCE = "js/GetSelectionHTML.js"; private static final String JAVASCRIPT_RESOURCE_GET_SOURCE_WITH_SELECTION_INDEXES = "js/GetSourceWithSelectionIndexes.js"; public static String javaFXVersion = ""; public static int javaFXVersionInt = 0; public boolean USE_LOCAL_OPTIONS = true; private String title = null; private Topic rootTopic = null; private TopicMap tm = null; private boolean isUIInitialized = false; private Options options = null; private Component fxPanelHandle = null; private WebView webView = null; private WebEngine webEngine = null; private String webSource = null; private boolean informPopupBlocking = true; private boolean informVisibilityChanges = true; private BrowserExtractorManager browserExtractorManager = null; private boolean viewBrowser = true; private static final String failedToOpenMessage = "<h1>Failed to open URL</h1>"; private ModulesWebApp selectedWebApp=null; private static final Color WEBAPP_ACTIVE_COLOR = new Color(243,243,243); private static final Color WEBAPP_PASSIVE_COLOR = Color.WHITE; public class WandoraJFXPanel extends JFXPanel { private static final long serialVersionUID = 1L; // EmbeddedScene.mouseEvent calls it's listeners with 40x wheel rotation // multiplier -> mouseDelta in JS is 4800 instead of 120. This screws up // the zoom behavior in D3 powered visualizations. // // The Bug is in D3! Wandora uses a slightly modified version of D3 Javascript // library with fixed wheel multiplier. @Override protected void processMouseWheelEvent(MouseWheelEvent e) { MouseWheelEvent ee = new MouseWheelEvent( (Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiers(), e.getX(), e.getY(), e.getXOnScreen(), e.getYOnScreen(), e.getClickCount(), e.isPopupTrigger(), e.getScrollType(), e.getScrollAmount(), e.getWheelRotation(), e.getPreciseWheelRotation()); super.processMouseWheelEvent(ee); } } /** * Creates new form WebViewPanel */ public WebViewPanel() { try { browserExtractorManager = new BrowserExtractorManager(Wandora.getWandora()); } catch(Exception e) { e.printStackTrace(); } } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; buttonPanel = new javax.swing.JPanel(); backButton = new SimpleButton(); forwardButton = new SimpleButton(); reloadButton = new SimpleButton(); stopButton = new SimpleButton(); urlTextField = new SimpleField(); menuButton = new SimpleButton(); setMinimumSize(new java.awt.Dimension(20, 20)); setPreferredSize(new java.awt.Dimension(20, 20)); setLayout(new java.awt.BorderLayout()); buttonPanel.setBackground(new java.awt.Color(238, 238, 238)); buttonPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204))); buttonPanel.setLayout(new java.awt.GridBagLayout()); backButton.setText("<"); backButton.setToolTipText("Go back one page"); backButton.setBorder(null); backButton.setBorderPainted(false); backButton.setContentAreaFilled(false); backButton.setMargin(new java.awt.Insets(0, 0, 0, 0)); backButton.setPreferredSize(new java.awt.Dimension(24, 24)); backButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { backButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4); buttonPanel.add(backButton, gridBagConstraints); forwardButton.setText(">"); forwardButton.setToolTipText("Go forward one page"); forwardButton.setBorder(null); forwardButton.setBorderPainted(false); forwardButton.setContentAreaFilled(false); forwardButton.setMargin(new java.awt.Insets(0, 0, 0, 0)); forwardButton.setPreferredSize(new java.awt.Dimension(24, 24)); forwardButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { forwardButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.insets = new java.awt.Insets(4, 0, 4, 0); buttonPanel.add(forwardButton, gridBagConstraints); reloadButton.setText("R"); reloadButton.setToolTipText("Reload current page"); reloadButton.setBorderPainted(false); reloadButton.setContentAreaFilled(false); reloadButton.setMargin(new java.awt.Insets(0, 0, 0, 0)); reloadButton.setPreferredSize(new java.awt.Dimension(24, 24)); reloadButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { reloadButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4); buttonPanel.add(reloadButton, gridBagConstraints); stopButton.setText("S"); stopButton.setToolTipText("Stop and close current page"); stopButton.setBorderPainted(false); stopButton.setContentAreaFilled(false); stopButton.setMargin(new java.awt.Insets(0, 0, 0, 0)); stopButton.setPreferredSize(new java.awt.Dimension(24, 24)); stopButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { stopButtonActionPerformed(evt); } }); buttonPanel.add(stopButton, new java.awt.GridBagConstraints()); urlTextField.setMargin(new java.awt.Insets(2, 4, 2, 4)); urlTextField.setPreferredSize(new java.awt.Dimension(6, 24)); urlTextField.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { urlTextFieldKeyPressed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4); buttonPanel.add(urlTextField, gridBagConstraints); menuButton.setText("="); menuButton.setToolTipText("More Webview options and tools"); menuButton.setBorderPainted(false); menuButton.setContentAreaFilled(false); menuButton.setMargin(new java.awt.Insets(0, 0, 0, 0)); menuButton.setPreferredSize(new java.awt.Dimension(25, 25)); menuButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mousePressed(java.awt.event.MouseEvent evt) { menuButtonMousePressed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.insets = new java.awt.Insets(4, 0, 4, 4); buttonPanel.add(menuButton, gridBagConstraints); add(buttonPanel, java.awt.BorderLayout.NORTH); }// </editor-fold>//GEN-END:initComponents private void urlTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_urlTextFieldKeyPressed //System.out.println("evt.getKeyCode() == "+evt.getKeyCode()); if(webEngine != null && evt.getKeyCode() == 10) { final String u = toURL(urlTextField.getText()); Platform.runLater(new Runnable() { @Override public void run() { urlTextField.setBackground(Color.WHITE); webEngine.load(u); } }); } }//GEN-LAST:event_urlTextFieldKeyPressed private void backButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backButtonActionPerformed if(webEngine != null) { Platform.runLater(new Runnable() { @Override public void run() { webEngine.executeScript("history.back()"); } }); } }//GEN-LAST:event_backButtonActionPerformed private void forwardButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_forwardButtonActionPerformed if(webEngine != null) { Platform.runLater(new Runnable() { @Override public void run() { webEngine.executeScript("history.forward()"); } }); } }//GEN-LAST:event_forwardButtonActionPerformed private void menuButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_menuButtonMousePressed Object[] menuItems = getBrowserMenuStruct(); if(menuItems != null && menuItems.length > 0) { JPopupMenu popupMenu = UIBox.makePopupMenu(menuItems, this); popupMenu.show(this, menuButton.getX()+evt.getX(), menuButton.getY()+evt.getY()); } }//GEN-LAST:event_menuButtonMousePressed private void reloadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reloadButtonActionPerformed if(webEngine != null) { Platform.runLater(new Runnable() { @Override public void run() { webEngine.reload(); } }); } }//GEN-LAST:event_reloadButtonActionPerformed private void stopButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopButtonActionPerformed selectedWebApp = null; browse((String) null); }//GEN-LAST:event_stopButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton backButton; private javax.swing.JPanel buttonPanel; private javax.swing.JButton forwardButton; private javax.swing.JButton menuButton; private javax.swing.JButton reloadButton; private javax.swing.JButton stopButton; private javax.swing.JTextField urlTextField; // End of variables declaration//GEN-END:variables // ------------------------------------------------------------------------- public WebEngine getWebEngine() { return this.webEngine; } public String getWebLocation() { return urlTextField.getText(); //return webEngine.getLocation(); } private Object[] getBrowserMenuStruct() { List<Object> topicMenuItems = new ArrayList<>(); if(rootTopic != null) { try { if(rootTopic.getSubjectLocator() != null) { topicMenuItems.add(rootTopic.getSubjectLocator().toExternalForm()); topicMenuItems.add("---"); } for(Locator l : rootTopic.getSubjectIdentifiers()) { topicMenuItems.add(l.toExternalForm()); } boolean firstOccurrence = true; for(Topic occurrenceType : rootTopic.getDataTypes()) { Hashtable<Topic,String> scopedOccurrences = rootTopic.getData(occurrenceType); for(Topic occurrenceScope : scopedOccurrences.keySet()) { if(firstOccurrence) { topicMenuItems.add("---"); firstOccurrence = false; } topicMenuItems.add("Open occurrence "+TopicToString.toString(occurrenceType)+" - "+TopicToString.toString(occurrenceScope)); topicMenuItems.add(new OpenOccurrenceInWebView(rootTopic, occurrenceType, occurrenceScope)); } } } catch(Exception e) { e.printStackTrace(); } } List<Object> browseServices = new ArrayList<>(); Wandora wandora = Wandora.getWandora(); if(wandora != null) { WandoraModulesServer httpServer = wandora.httpServer; List<ModulesWebApp> webApps=httpServer.getWebApps(); Map<String,ModulesWebApp> webAppsMap=new HashMap<>(); for(ModulesWebApp wa : webApps) webAppsMap.put(wa.getAppName(), wa); List<String> sorted = new ArrayList<>(webAppsMap.keySet()); Collections.sort(sorted); for(String appName : sorted) { ModulesWebApp wa=webAppsMap.get(appName); if(wa.isRunning()) { String url=wa.getAppStartPage(); if(url==null) continue; browseServices.add(appName); browseServices.add(UIBox.getIcon("gui/icons/open_browser.png")); browseServices.add(new HTTPServerTool(HTTPServerTool.OPEN_PAGE_IN_BROWSER_TOPIC_PANEL, wa, this)); } else { browseServices.add(appName); browseServices.add(UIBox.getIcon("gui/icons/open_browser.png")); browseServices.add(new HTTPServerTool(HTTPServerTool.OPEN_PAGE_IN_BROWSER_TOPIC_PANEL, wa, this)); } } } List<Object> extractors = new ArrayList<>(); if(browserExtractorManager != null) { T3<String, Integer, Integer> contentWithSelectionIndexes = getSourceWithSelectionIndexes(); String content = contentWithSelectionIndexes.e1; int start = contentWithSelectionIndexes.e2.intValue(); int end = contentWithSelectionIndexes.e3.intValue(); String selection = null; try { if(start != -1 && end != -1) { selection = content.substring(start,end); } } catch(Exception e) {} BrowserExtractRequest extractRequest=new BrowserExtractRequest(getWebLocation(), content, null, "WebView", start, end, selection); String[] browserExtractors = browserExtractorManager.getExtractionMethods(extractRequest); for(String browserExtractorName : browserExtractors) { extractors.add(browserExtractorName); extractors.add((ActionListener) this); } } Object[] menuStruct = new Object[] { "Open current topic", topicMenuItems.toArray(), "Open Wandora's services", browseServices.toArray(), "---", "Open Firebug", new OpenFirebugInWebView(), "Open in external browser", new OpenWebLocationInExternalBrowser(), "---", "Add to current topic", new Object[] { "Add selection as an occurrence...", new AddWebSelectionAsOccurrence(), "Add selection source as an occurrence...", new AddWebSourceAsOccurrence(true), "Add source as an occurrence...", new AddWebSourceAsOccurrence(), "Add location as an occurrence...", new AddWebLocationAsOccurrence(), "---", "Add location as a subject locator", new AddWebLocationAsSubjectLocator(), "Add location as a subject identifier", new AddWebLocationAsSubjectIdentifier(), "---", "Add selection as a basename", new AddWebSelectionAsBasename(), // "---", // "Add links as associations", // "Add image locations as associations", }, "Create a topic", new Object[] { "Create topic from location", new CreateWebLocationTopic(), "---", "Create topic from location and make instance", new CreateWebLocationTopic(true,false,true,false), "Create topic from location and make subclass", new CreateWebLocationTopic(false,true,true,false), "Create topic from location and associate", new CreateWebLocationTopic(false,false,true,true), }, "---", "Extract", extractors.toArray() }; return menuStruct; } // ------------------------------------------------------------------------- private static String toURL(String str) { try { return new URL(str).toExternalForm(); } catch (MalformedURLException exception) { if(!str.startsWith("http://")) { return "http://"+str; } else { return null; } } } // ------------------------------------------------------ topic listener --- @Override public void topicSubjectIdentifierChanged(Topic t, Locator added, Locator removed) throws TopicMapException { doRefresh(); } @Override public void topicBaseNameChanged(Topic t, String newName, String oldName) throws TopicMapException { doRefresh(); } @Override public void topicTypeChanged(Topic t, Topic added, Topic removed) throws TopicMapException { doRefresh(); } @Override public void topicVariantChanged(Topic t, Collection<Topic> scope, String newName, String oldName) throws TopicMapException { doRefresh(); } @Override public void topicDataChanged(Topic t, Topic type, Topic version, String newValue, String oldValue) throws TopicMapException { doRefresh(); } @Override public void topicSubjectLocatorChanged(Topic t, Locator newLocator, Locator oldLocator) throws TopicMapException { doRefresh(); } @Override public void topicRemoved(Topic t) throws TopicMapException { doRefresh(); } @Override public void topicChanged(Topic t) throws TopicMapException { doRefresh(); } @Override public void associationTypeChanged(Association a, Topic newType, Topic oldType) throws TopicMapException { doRefresh(); } @Override public void associationPlayerChanged(Association a, Topic role, Topic newPlayer, Topic oldPlayer) throws TopicMapException { doRefresh(); } @Override public void associationRemoved(Association a) throws TopicMapException { doRefresh(); } @Override public void associationChanged(Association a) throws TopicMapException { doRefresh(); } // ------------------------------------------------------------------------- @Override public void doRefresh() throws TopicMapException { } public void open(Topic topic) throws TopicMapException { try { rootTopic = topic; if(!isUIInitialized) { isUIInitialized = true; initializeUI(); } else { browse(rootTopic); } } catch(Exception e) { e.printStackTrace(); } } public void openContent(final String str) { try { if(str != null) { if(!isUIInitialized) { isUIInitialized = true; initializeUI(); } Platform.runLater(new Runnable() { @Override public void run() { webEngine.loadContent(str); } }); } } catch(Exception e) { e.printStackTrace(); } } private void initializeUI() { Wandora wandora = Wandora.getWandora(); if(options == null) { if(USE_LOCAL_OPTIONS) { options = new Options(wandora.getOptions()); } else { options = wandora.getOptions(); } } tm = wandora.getTopicMap(); initComponents(); Platform.setImplicitExit(false); final WandoraJFXPanel fxPanel = new WandoraJFXPanel(); fxPanelHandle = fxPanel; this.add(fxPanel, BorderLayout.CENTER); Platform.runLater(new Runnable() { @Override public void run() { initFX(fxPanel); browse(rootTopic); } }); this.addComponentListener(this); backButton.setText(""); backButton.setIcon(UIBox.getIcon("gui/icons/webview/backward.png")); forwardButton.setText(""); forwardButton.setIcon(UIBox.getIcon("gui/icons/webview/forward.png")); stopButton.setText(""); stopButton.setIcon(UIBox.getIcon("gui/icons/webview/stop.png")); reloadButton.setText(""); reloadButton.setIcon(UIBox.getIcon("gui/icons/webview/reload.png")); menuButton.setText(""); menuButton.setIcon(UIBox.getIcon("gui/icons/webview/menu.png")); } public void browse(Topic topic) { try { String u = null; if(topic != null) { u = topic.getFirstSubjectIdentifier().toExternalForm(); if(selectedWebApp != null) { String url=selectedWebApp.getAppTopicPage(u); if(url!=null) { urlTextField.setBackground(WEBAPP_ACTIVE_COLOR); browse(url, false); return; } } } browse(u); } catch(Exception e) { e.printStackTrace(); } } public void browse(final String url) { browse(url, true); } public void browse(final String url, boolean resetWebApp) { if(resetWebApp && url != null) { selectedWebApp = null; WandoraModulesServer s=Wandora.getWandora().getHTTPServer(); for(ModulesWebApp webApp : s.getWebApps()){ if(url.equals(webApp.getAppStartPage())) { urlTextField.setBackground(WEBAPP_ACTIVE_COLOR); selectedWebApp = webApp; break; } } } if(selectedWebApp == null) { urlTextField.setBackground(WEBAPP_PASSIVE_COLOR); } Platform.runLater(new Runnable() { @Override public void run() { webEngine.load(url); } }); } public void executeScript(final String script) { Platform.runLater(new Runnable() { @Override public void run() { webEngine.executeScript(script); } }); } private Object scriptReturn = null; public Object executeSynchronizedScript(final String script) { scriptReturn = null; if(script != null && script.length()>0) { Thread runner = new Thread() { @Override public void run() { scriptReturn = webEngine.executeScript(script); } }; Platform.runLater(runner); do { try { Thread.sleep(100); } catch(Exception ex) { } } while(runner.isAlive()); } return scriptReturn; } public Object executeSynchronizedScriptResource(String scriptResource) { try { String script = IOUtils.toString(this.getClass().getResourceAsStream(scriptResource),"UTF-8"); return executeSynchronizedScript(script); } catch(Exception e) { e.printStackTrace(); } return null; } private void startLoadingAnimation() { Wandora wandora = Wandora.getWandora(); if(wandora != null) wandora.setAnimated(true, this); } private void stopLoadingAnimation() { Wandora wandora = Wandora.getWandora(); if(wandora != null) wandora.setAnimated(false, this); } private void initFX(final JFXPanel fxPanel) { Group group = new Group(); Scene scene = new Scene(group); fxPanel.setScene(scene); webView = new WebView(); if(javaFXVersionInt >= 8) { webView.setScaleX(1.0); webView.setScaleY(1.0); //webView.setFitToHeight(false); //webView.setFitToWidth(false); //webView.setZoom(javafx.stage.Screen.getPrimary().getDpi() / 96); } group.getChildren().add(webView); int w = this.getWidth(); int h = this.getHeight()-34; webView.setMinSize(w, h); webView.setMaxSize(w, h); webView.setPrefSize(w, h); // Obtain the webEngine to navigate webEngine = webView.getEngine(); webEngine.locationProperty().addListener(new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, final String newValue) { if (newValue.endsWith(".pdf")) { try { int a = WandoraOptionPane.showConfirmDialog(Wandora.getWandora(), "Open PDF document in external application?", "Open PDF document in external application?", WandoraOptionPane.YES_NO_OPTION); if(a == WandoraOptionPane.YES_OPTION) { Desktop dt = Desktop.getDesktop(); dt.browse(new URI(newValue)); } } catch(Exception e) {} } else { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { urlTextField.setText(newValue); } }); } } }); webEngine.titleProperty().addListener(new ChangeListener<String>() { @Override public void changed(ObservableValue<? extends String> observable, String oldValue, final String newValue) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { title = newValue; } }); } }); webEngine.setOnAlert(new EventHandler<WebEvent<java.lang.String>>() { @Override public void handle(WebEvent<String> t) { if(t != null) { String str = t.getData(); if(str != null && str.length() > 0) { WandoraOptionPane.showMessageDialog(Wandora.getWandora(), str, "Javascript Alert", WandoraOptionPane.PLAIN_MESSAGE); } } } }); webEngine.setConfirmHandler(new Callback<String, Boolean>() { @Override public Boolean call(String msg) { int a = WandoraOptionPane.showConfirmDialog(Wandora.getWandora(), msg, "Javascript Alert", WandoraOptionPane.YES_NO_OPTION); return (a == WandoraOptionPane.YES_OPTION); } }); webEngine.setPromptHandler(new Callback<PromptData, String>() { @Override public String call(PromptData data) { String a = WandoraOptionPane.showInputDialog(Wandora.getWandora(), data.getMessage(), data.getDefaultValue(), "Javascript Alert", WandoraOptionPane.QUESTION_MESSAGE); return a; } }); webEngine.setCreatePopupHandler(new Callback<PopupFeatures,WebEngine>() { @Override public WebEngine call(PopupFeatures features) { if(informPopupBlocking) { WandoraOptionPane.showMessageDialog(Wandora.getWandora(), "A javascript popup has been blocked. Wandora doesn't allow javascript popups in Webview topic panel.", "Javascript popup blocked", WandoraOptionPane.PLAIN_MESSAGE); } informPopupBlocking = false; return null; } }); webEngine.setOnVisibilityChanged(new EventHandler<WebEvent<Boolean>>() { @Override public void handle(WebEvent<Boolean> t) { if(t != null) { Boolean b = t.getData(); if(informVisibilityChanges) { WandoraOptionPane.showMessageDialog(Wandora.getWandora(), "A browser window visibility change has been blocked. Wandora doesn't allow visibility changes of windows in Webview topic panel.", "Javascript visibility chnage blocked", WandoraOptionPane.PLAIN_MESSAGE); informVisibilityChanges = false; } } } }); webEngine.getLoadWorker().stateProperty().addListener( new ChangeListener<State>() { @Override public void changed(ObservableValue ov, State oldState, State newState) { if(newState == Worker.State.SCHEDULED) { //System.out.println("Scheduled!"); startLoadingAnimation(); } if(newState == Worker.State.SUCCEEDED) { Document doc = webEngine.getDocument(); try { Transformer transformer = TransformerFactory.newInstance().newTransformer(); //transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); // transformer.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(System.out, "UTF-8"))); StringWriter stringWriter = new StringWriter(); transformer.transform(new DOMSource(doc), new StreamResult(stringWriter)); webSource = stringWriter.toString(); } catch (Exception ex) { ex.printStackTrace(); } stopLoadingAnimation(); } else if(newState == Worker.State.CANCELLED) { //System.out.println("Cancelled!"); stopLoadingAnimation(); } else if(newState == Worker.State.FAILED) { webEngine.loadContent(failedToOpenMessage); stopLoadingAnimation(); } } }); } public void stop() { //System.out.println("---- Stopping Webview topic panel!"); browse((String) null); } public void refresh() throws TopicMapException { } public boolean applyChanges() throws CancelledException, TopicMapException { return true; } public Topic getTopic() throws TopicMapException { return rootTopic; } public String getTitle() { if(rootTopic == null) { return "Webview"; } else { return TopicToString.toString(rootTopic); } } @Override public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if(cmd != null) { if(cmd.startsWith("http://")) { browse(cmd); } else { Wandora w = Wandora.getWandora(); if(w != null) w.setAnimated(true, this); T3<String, Integer, Integer> contentWithSelectionIndexes = getSourceWithSelectionIndexes(); String content = contentWithSelectionIndexes.e1; int start = contentWithSelectionIndexes.e2.intValue(); int end = contentWithSelectionIndexes.e3.intValue(); String selection = null; try { if(start != -1 && end != -1) { selection = content.substring(start,end); } } catch(Exception ex) {} BrowserExtractRequest extractRequest=new BrowserExtractRequest(getWebLocation(), content, cmd, "WebView", start, end, selection); String message=browserExtractorManager.doPluginExtract(extractRequest); if(message!=null) { WandoraOptionPane.showMessageDialog(Wandora.getWandora(), message, cmd); } if(w != null) w.setAnimated(false, this); } } } public Image getSnapshot() { WritableImage image = webView.snapshot(null, null); BufferedImage bufferedImage = SwingFXUtils.fromFXImage(image, null); return bufferedImage; } public String getSelectedText() { //System.out.println("get selected text"); String selection = (String) executeSynchronizedScript("window.getSelection().toString()"); //System.out.println(" and the selection is "+selection); return selection; } public String getSelectedSource() { String selection = (String) executeSynchronizedScriptResource(JAVASCRIPT_RESOURCE_GET_SELECTED_SOURCE); //System.out.println("--------"); //System.out.println(selection); //System.out.println("--------"); return selection; } public T3<String,Integer,Integer> getSourceWithSelectionIndexes() { String content = null; int start = -1; int end = -1; try { JSObject d = (JSObject) executeSynchronizedScriptResource(JAVASCRIPT_RESOURCE_GET_SOURCE_WITH_SELECTION_INDEXES); if(d != null) { //System.out.println("========"); //System.out.println(d.toString()); //System.out.println("========"); try { content = (String) d.getMember("content"); start = (Integer) d.getMember("selectionStart"); end = (Integer) d.getMember("selectionEnd"); } catch(Exception e) {} } //System.out.println("--------"); //System.out.println(content); //if(start != -1 && end != -1) System.out.println(content.substring(start, end)); //else System.out.println("ALL"); //System.out.println("--------"); //System.out.println("start: "+start); //System.out.println("end: "+end); //System.out.println("--------"); } catch(Exception e) { e.printStackTrace(); } return new T3<>(content, Integer.valueOf(start), Integer.valueOf(end)); } public String getSource() { return webSource; } public String getWebTitle() { if(webEngine != null) { return webEngine.getTitle(); } else return null; } // ------------------------------------------------------------------------- // --------------------------------------------------- ComponentListener --- // ------------------------------------------------------------------------- @Override public void componentShown(ComponentEvent e) { handleComponentEvent(e); } @Override public void componentResized(ComponentEvent e) { handleComponentEvent(e); } @Override public void componentHidden(ComponentEvent e) { handleComponentEvent(e); } @Override public void componentMoved(ComponentEvent e) { handleComponentEvent(e); } private void handleComponentEvent(ComponentEvent e) { try { Component c = this; if(this.getParent() != null) c = this.getParent(); final int w = c.getWidth(); final int h = c.getHeight()-35; Dimension d = new Dimension(w, h); if(this.getParent() != null) { this.setPreferredSize(d); this.setMinimumSize(d); this.setMaximumSize(d); } if(webView != null && w > 1 && h > 1) { Platform.runLater(new Runnable() { @Override public void run() { webView.setMinSize(w, h); webView.setMaxSize(w, h); webView.setPrefSize(w, h); } }); } revalidate(); repaint(); } catch(Exception ex) {} } // ------------------------------------------------------------------------- }
43,435
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
WandoraDockable.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/dockingpanel/WandoraDockable.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.dockingpanel; import java.awt.Component; import java.awt.event.MouseEvent; import javax.swing.Icon; import javax.swing.event.MouseInputListener; import org.wandora.application.gui.topicpanels.TopicPanel; import bibliothek.gui.dock.DefaultDockable; import bibliothek.gui.dock.title.DockTitle; /** * * * @author akivela */ public class WandoraDockable extends DefaultDockable { private TopicPanel topicPanel = null; private MouseEvent lastMouseEvent = null; private Component wrapper = null; public WandoraDockable(Component c, TopicPanel tp, String title, Icon icon) { super(c, title, icon); wrapper = c; DockTitle[] dtitles = listBoundTitles(); for(int i=0; i<dtitles.length; i++) { DockTitle dtitle = dtitles[i]; Component comp = dtitle.getComponent(); //System.out.println("COMP="+comp); //comp.add(tp.getViewPopupMenu()); } this.addMouseInputListener(new WandoraDockableMouseListener()); topicPanel = tp; } public Component getWrapper() { return wrapper; } public TopicPanel getInnerTopicPanel() { return topicPanel; } public MouseEvent getLastMouseEvent() { return lastMouseEvent; } // ------------------------------------------------------------------------- // ------------------------------------------------------------------------- // ------------------------------------------------------------------------- public class WandoraDockableMouseListener implements MouseInputListener { @Override public void mouseClicked(MouseEvent e) { lastMouseEvent = e; } @Override public void mousePressed(MouseEvent e) { lastMouseEvent = e; } @Override public void mouseReleased(MouseEvent e) { lastMouseEvent = e; } @Override public void mouseEntered(MouseEvent e) { lastMouseEvent = e; } @Override public void mouseExited(MouseEvent e) { lastMouseEvent = e; } @Override public void mouseDragged(MouseEvent e) { lastMouseEvent = e; } @Override public void mouseMoved(MouseEvent e) { lastMouseEvent = e; } } }
3,317
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
WandoraDockTheme.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/dockingpanel/WandoraDockTheme.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.dockingpanel; import bibliothek.gui.dock.themes.BasicTheme; /** * * @author akivela */ public class WandoraDockTheme extends BasicTheme { public WandoraDockTheme() { super(); } }
1,069
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
WandoraDockController.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/dockingpanel/WandoraDockController.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.dockingpanel; import org.wandora.application.gui.UIConstants; import bibliothek.gui.DockController; import bibliothek.gui.DockTheme; import bibliothek.gui.dock.util.IconManager; import bibliothek.gui.dock.util.Priority; import bibliothek.gui.dock.util.color.ColorManager; import bibliothek.gui.dock.util.font.FontManager; /** * * @author akivela */ public class WandoraDockController extends DockController { public WandoraDockController() { super(); DockTheme dockTheme = new WandoraDockTheme(); this.setTheme(dockTheme); ColorManager colorManager = this.getColors(); colorManager.put(Priority.CLIENT, "title.active", UIConstants.defaultActiveBackground); FontManager fontManager = this.getFonts(); IconManager iconManager = this.getIcons(); } }
1,705
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
WandoraBackgroundPaint.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/dockingpanel/WandoraBackgroundPaint.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.dockingpanel; import java.awt.Color; import java.awt.Component; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.image.BufferedImage; import java.io.File; import java.net.URL; import javax.imageio.ImageIO; import javax.swing.SwingUtilities; import bibliothek.gui.dock.util.BackgroundComponent; import bibliothek.gui.dock.util.BackgroundPaint; import bibliothek.gui.dock.util.PaintableComponent; import bibliothek.gui.dock.util.Transparency; /** * * @author akivela */ public class WandoraBackgroundPaint implements BackgroundPaint { /* the entire image as it was read from the disk */ private BufferedImage baseImage; /* an image with the same size as the frame */ private BufferedImage image; /* our anchor point, the location 0/0 of our image and of this component will always match */ private Component content; /* standard constructor */ public WandoraBackgroundPaint( Component content ) { this.content = content; resolveImage("gui/startup_image.gif"); } public void install( BackgroundComponent component ){ // ignore } public void uninstall( BackgroundComponent component ){ // ignore } private void resolveImage(String imageLocator) { if(imageLocator != null) { baseImage = null; try { URL url = new URL(imageLocator); this.baseImage = ImageIO.read(url); } catch (Exception e) { try { File file = new File(imageLocator); this.baseImage = ImageIO.read(file); } catch (Exception e2) { try { URL url = ClassLoader.getSystemResource(imageLocator); this.baseImage = ImageIO.read(url); } catch (Exception e3) { e2.printStackTrace(); } } } } } /* gets the image that should be used for painting */ public BufferedImage getImage(){ if( image == null || image.getWidth() != content.getWidth() || image.getHeight() != content.getHeight() ){ image = createBackground( baseImage, content.getWidth(), content.getHeight() ); } return image; } /* this is the method that paints the background */ public void paint( BackgroundComponent background, PaintableComponent paintable, Graphics g ){ if( SwingUtilities.isDescendingFrom( background.getComponent(), content )){ /* If we are painting an non-transparent component we paint our custom background image, otherwise * we just let it shine through */ if( paintable.getTransparency() == Transparency.SOLID ){ Point point = new Point( 0, 0 ); point = SwingUtilities.convertPoint( paintable.getComponent(), point, content ); BufferedImage image = getImage(); if( image != null ){ int w = paintable.getComponent().getWidth(); int h = paintable.getComponent().getHeight(); g.drawImage( image, 0, 0, w, h, point.x, point.y, point.x + w, point.y + h, null ); } } /* and now we paint the original content of the component */ Graphics2D g2 = (Graphics2D)g.create(); //g2.setComposite( alpha ); paintable.paintBackground( g2 ); paintable.paintForeground( g ); paintable.paintBorder( g2 ); g2.dispose(); paintable.paintChildren( g ); } } /* This helper method creates an image we use for the background */ private static BufferedImage createBackground( BufferedImage image, int width, int height ){ if( width <= 0 || height <= 0 ){ return null; } BufferedImage result = new BufferedImage( width, height, BufferedImage.TYPE_INT_ARGB ); Graphics g = result.createGraphics(); g.setColor( Color.WHITE ); g.fillRect( 0, 0, width, height ); int imageWidth = image.getWidth(); int imageHeight = image.getHeight(); int mw = Math.min( width, imageWidth ); int mh = Math.min( height, imageHeight ); g.drawImage( image, width/2-mw/2, height/2-mh/2, width/2+mw/2, height/2+mh/2, imageWidth/2-mw/2, imageHeight/2-mh/2, imageWidth/2+mw/2, imageHeight/2+mh/2, null ); g.dispose(); return result; } }
5,570
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
WandoraDockActionSource.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/dockingpanel/WandoraDockActionSource.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.dockingpanel; import org.wandora.application.gui.topicpanels.DockingFramePanel; import org.wandora.application.gui.topicpanels.TopicPanel; import org.wandora.application.gui.topicpanels.dockingpanel.actions.CloseDockableAction; import org.wandora.application.gui.topicpanels.dockingpanel.actions.MaximizeDockableAction; import bibliothek.gui.DockController; import bibliothek.gui.dock.action.MultiDockActionSource; /** * * @author akivela */ public class WandoraDockActionSource extends MultiDockActionSource { private TopicPanel topicPanel = null; public WandoraDockActionSource(TopicPanel tp, DockingFramePanel dfp, DockController control) { topicPanel = tp; //this.add(new WandoraToolWrapperAction(new OpenTopic(OpenTopic.ASK_USER))); //this.add(new TopicPanelMenuAction(tp)); this.add(new MaximizeDockableAction(dfp)); this.add(new CloseDockableAction(dfp)); } }
1,795
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
SelectTopicPanelPanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/dockingpanel/SelectTopicPanelPanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * */ package org.wandora.application.gui.topicpanels.dockingpanel; import java.util.List; import javax.swing.DefaultListModel; import javax.swing.JDialog; import org.wandora.application.Wandora; import org.wandora.application.gui.simple.SimpleButton; import org.wandora.application.gui.simple.SimpleCheckBox; import org.wandora.application.gui.topicpanels.TopicPanel; /** * * @author akivela */ public class SelectTopicPanelPanel extends javax.swing.JPanel { private static final long serialVersionUID = 1L; private JDialog myDialog = null; private List<TopicPanel> topicPanels = null; private Wandora wandora = null; private boolean wasAccepted = false; private static TopicPanel lastSelectedTopicPanel = null; private static boolean lastRememberSelection = false; /** * Creates new form SelectTopicPanelPanel */ public SelectTopicPanelPanel() { initComponents(); } public void openInDialog(List<TopicPanel> topicPanels, Wandora wandora) { this.topicPanels = topicPanels; this.wandora = wandora; int index = 0; int defaultIndex = -1; DefaultListModel topicPanelListModel = new DefaultListModel(); for(TopicPanel tp : topicPanels) { topicPanelListModel.addElement(tp.getName()+" w "+tp.getTitle()); if(lastSelectedTopicPanel != null && tp.equals(lastSelectedTopicPanel)) { defaultIndex = index; } index++; } topicPanelList.setModel(topicPanelListModel); topicPanelList.setSelectedIndex(defaultIndex); rememberCheckBox.setSelected(lastRememberSelection); wasAccepted = false; myDialog = new JDialog(wandora, true); myDialog.setTitle("Select topic panel"); myDialog.add(this); myDialog.setSize(500, 250); wandora.centerWindow(myDialog); myDialog.setVisible(true); } public boolean wasAccepted() { return wasAccepted; } public TopicPanel getSelectedTopicPanel() { int i = topicPanelList.getSelectedIndex(); TopicPanel selectedTopicPanel = null; if(i >= 0 && i < topicPanels.size()) { selectedTopicPanel = topicPanels.get(i); lastSelectedTopicPanel = selectedTopicPanel; } return selectedTopicPanel; } public boolean getRememberSelection() { lastRememberSelection = rememberCheckBox.isSelected(); return rememberCheckBox.isSelected(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; jPanel1 = new javax.swing.JPanel(); selectorsPanel = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); topicPanelList = new javax.swing.JList(); buttonPanel = new javax.swing.JPanel(); rememberCheckBox = new SimpleCheckBox(); fillerPanel = new javax.swing.JPanel(); selectButton = new SimpleButton(); cancelButton = new SimpleButton(); setLayout(new java.awt.GridBagLayout()); jPanel1.setLayout(new java.awt.GridBagLayout()); selectorsPanel.setLayout(new java.awt.GridBagLayout()); topicPanelList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); topicPanelList.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR)); jScrollPane1.setViewportView(topicPanelList); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; selectorsPanel.add(jScrollPane1, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; jPanel1.add(selectorsPanel, gridBagConstraints); buttonPanel.setLayout(new java.awt.GridBagLayout()); rememberCheckBox.setText("remember selection"); buttonPanel.add(rememberCheckBox, new java.awt.GridBagConstraints()); fillerPanel.setLayout(new java.awt.GridBagLayout()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; buttonPanel.add(fillerPanel, gridBagConstraints); selectButton.setText("Select"); selectButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { selectButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 2); buttonPanel.add(selectButton, gridBagConstraints); cancelButton.setText("Cancel"); cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelButtonActionPerformed(evt); } }); buttonPanel.add(cancelButton, new java.awt.GridBagConstraints()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0); jPanel1.add(buttonPanel, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4); add(jPanel1, gridBagConstraints); }// </editor-fold>//GEN-END:initComponents private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed wasAccepted = false; if(myDialog != null) { myDialog.setVisible(false); } }//GEN-LAST:event_cancelButtonActionPerformed private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectButtonActionPerformed int i = topicPanelList.getSelectedIndex(); if(i >= 0 && i < topicPanels.size()) { wasAccepted = true; } if(myDialog != null) { myDialog.setVisible(false); } }//GEN-LAST:event_selectButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel buttonPanel; private javax.swing.JButton cancelButton; private javax.swing.JPanel fillerPanel; private javax.swing.JPanel jPanel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JCheckBox rememberCheckBox; private javax.swing.JButton selectButton; private javax.swing.JPanel selectorsPanel; private javax.swing.JList topicPanelList; // End of variables declaration//GEN-END:variables // ------------------------------------------------------------------------- }
8,649
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
WandoraSplitDockStation.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/dockingpanel/WandoraSplitDockStation.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.dockingpanel; import bibliothek.gui.dock.SplitDockStation; /** * * @author akivela */ public class WandoraSplitDockStation extends SplitDockStation { private static final long serialVersionUID = 1L; public WandoraSplitDockStation() { super(false); } public WandoraSplitDockStation(boolean createFullScreenAction) { super(false); } }
1,233
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
CloseDockableAction.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/dockingpanel/actions/CloseDockableAction.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.dockingpanel.actions; import org.wandora.application.gui.UIBox; import org.wandora.application.gui.topicpanels.DockingFramePanel; import bibliothek.gui.Dockable; import bibliothek.gui.dock.action.actions.SimpleButtonAction; /** * * @author akivela */ public class CloseDockableAction extends SimpleButtonAction { private DockingFramePanel dockingFramePanel = null; public CloseDockableAction(DockingFramePanel dfp) { super(false); this.dockingFramePanel = dfp; this.setIcon( UIBox.getIcon("gui/icons/close_dockable.png") ); } @Override public String getText(Dockable dckbl) { return "Close dockable"; } @Override public String getTooltipText(Dockable dckbl) { return "Close dockable permanently."; } @Override public void action(Dockable dockable) { System.out.println("ACTION CloseDockableAction TRIGGERED"); try { dockingFramePanel.deleteDockable(dockable); } catch (Exception ex) { ex.printStackTrace(); } } }
1,962
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
WandoraToolWrapperAction.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/dockingpanel/actions/WandoraToolWrapperAction.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.dockingpanel.actions; import java.awt.event.ActionEvent; import javax.swing.Icon; import org.wandora.application.Wandora; import org.wandora.application.WandoraTool; import org.wandora.application.tools.navigate.OpenTopic; import org.wandora.topicmap.TopicMapException; import bibliothek.gui.Dockable; import bibliothek.gui.dock.action.ActionContentModifier; import bibliothek.gui.dock.action.actions.SimpleButtonAction; /** * * @author akivela */ public class WandoraToolWrapperAction extends SimpleButtonAction { private WandoraTool tool = new OpenTopic(); public WandoraToolWrapperAction(WandoraTool tool) { super(true); this.tool = tool; this.setIcon( tool.getIcon() ); this.setIcon( ActionContentModifier.NONE_HOVER, tool.getIcon() ); this.setIcon( ActionContentModifier.NONE_PRESSED, tool.getIcon() ); } @Override public Icon getIcon(Dockable dckbl, ActionContentModifier acm) { return tool != null ? tool.getIcon() : null; } @Override public String getText(Dockable dckbl) { return tool != null ? tool.getName() : "Unknown tool"; } @Override public String getTooltipText(Dockable dckbl) { return tool.getDescription(); } @Override public void action(Dockable dockable) { System.out.println("ACTION TRIGGERED"); try { if(tool != null) { tool.execute(Wandora.getWandora(), (ActionEvent) null); } } catch (TopicMapException ex) { ex.printStackTrace(); } } }
2,469
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
TopicPanelMenuAction.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/dockingpanel/actions/TopicPanelMenuAction.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.dockingpanel.actions; import java.awt.Point; import java.awt.event.MouseEvent; import javax.swing.Icon; import javax.swing.JPopupMenu; import org.wandora.application.gui.topicpanels.TopicPanel; import org.wandora.application.gui.topicpanels.dockingpanel.WandoraDockable; import bibliothek.gui.Dockable; import bibliothek.gui.dock.action.ActionContentModifier; import bibliothek.gui.dock.action.actions.SimpleButtonAction; /** * * @author akivela */ public class TopicPanelMenuAction extends SimpleButtonAction { private TopicPanel topicPanel = null; public TopicPanelMenuAction(TopicPanel tp) { super(false); this.topicPanel = tp; this.setIcon( topicPanel.getIcon() ); this.setIcon( ActionContentModifier.NONE_HOVER, topicPanel.getIcon() ); this.setIcon( ActionContentModifier.NONE_PRESSED, topicPanel.getIcon() ); } @Override public Icon getIcon(Dockable dckbl, ActionContentModifier acm) { return topicPanel != null ? topicPanel.getIcon() : null; } @Override public Icon getIcon(ActionContentModifier modifier) { return getIcon(modifier); } @Override public Icon getDisabledIcon() { return topicPanel != null ? topicPanel.getIcon() : null; } @Override public String getText(Dockable dckbl) { return (topicPanel != null ? topicPanel.getName() : "Topic panel") + " options"; } @Override public String getTooltipText(Dockable dckbl) { return getText(dckbl); } @Override public void action(Dockable dockable) { System.out.println("ACTION Open topic panel options TRIGGERED"); try { if(topicPanel != null) { JPopupMenu popupMenu = topicPanel.getViewPopupMenu(); Point p = new Point(dockable.getComponent().getWidth(), 0); if(dockable instanceof WandoraDockable) { System.out.println("Dockable is WandoraDockable"); MouseEvent me = ((WandoraDockable) dockable).getLastMouseEvent(); System.out.println("Dockable's last mousevent is "+me); if(me != null) { p = me.getPoint(); } } popupMenu.show(dockable.getComponent(), p.x, p.y ); } } catch (Exception ex) { ex.printStackTrace(); } } }
3,330
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
MaximizeDockableAction.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/dockingpanel/actions/MaximizeDockableAction.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.dockingpanel.actions; import org.wandora.application.gui.UIBox; import org.wandora.application.gui.topicpanels.DockingFramePanel; import bibliothek.gui.Dockable; import bibliothek.gui.dock.action.actions.SimpleButtonAction; /** * * @author akivela */ public class MaximizeDockableAction extends SimpleButtonAction { private DockingFramePanel dockingFramePanel = null; public MaximizeDockableAction(DockingFramePanel dfp) { super(false); this.dockingFramePanel = dfp; this.setIcon( UIBox.getIcon("gui/icons/maximize_dockable.png") ); } @Override public String getText(Dockable dckbl) { return "Maximize dockable"; } @Override public String getTooltipText(Dockable dckbl) { return "Maximize (and normalize) dockable"; } @Override public void action(Dockable dockable) { System.out.println("ACTION MaximizeDockableAction TRIGGERED"); try { dockingFramePanel.maximizeDockable(dockable); } catch (Exception ex) { ex.printStackTrace(); } } }
1,974
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
QueryEditorInspectorPanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/queryeditorpanel/QueryEditorInspectorPanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.queryeditorpanel; import javax.swing.JPanel; /** * * @author olli */ public class QueryEditorInspectorPanel extends javax.swing.JPanel { private static final long serialVersionUID = 1L; protected Object selectedObject; protected JPanel editor; /** * Creates new form QueryEditorInspectorPanel */ public QueryEditorInspectorPanel() { initComponents(); this.add(emptyPanel); } public void saveChanges(){ if(this.selectedObject!=null && this.selectedObject instanceof DirectivePanel){ if(editor!=null && editor instanceof DirectiveEditor) ((DirectiveEditor)editor).saveChanges(); } } public void setSelection(Object o){ saveChanges(); this.selectedObject=o; this.removeAll(); if(o==null) this.add(emptyPanel); else if(o instanceof DirectivePanel){ DirectivePanel panel=(DirectivePanel)o; editor=panel.getEditorPanel(); if(editor==null) this.add(new JPanel()); else this.add(editor); } this.revalidate(); this.repaint(); } public Object getSelection(){ return selectedObject; } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { emptyPanel = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); emptyPanel.setLayout(new java.awt.BorderLayout()); jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel1.setText("Nothing selected"); jLabel1.setEnabled(false); emptyPanel.add(jLabel1, java.awt.BorderLayout.CENTER); setLayout(new java.awt.BorderLayout()); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel emptyPanel; private javax.swing.JLabel jLabel1; // End of variables declaration//GEN-END:variables }
3,161
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
ResultsPanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/queryeditorpanel/ResultsPanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * */ package org.wandora.application.gui.topicpanels.queryeditorpanel; import java.awt.BorderLayout; import java.awt.Container; import java.util.ArrayList; import javax.swing.JComponent; import org.wandora.application.Wandora; import org.wandora.application.gui.GetTopicButton; import org.wandora.application.gui.UIBox; import org.wandora.application.gui.search.QueryPanel; import org.wandora.application.gui.table.MixedTopicTable; import org.wandora.query2.Directive; import org.wandora.query2.QueryException; import org.wandora.topicmap.Topic; import org.wandora.topicmap.TopicMapException; /** * * @author olli */ public class ResultsPanel extends javax.swing.JPanel { private static final long serialVersionUID = 1L; protected boolean autoUpdate=true; /** * Creates new form ResultsPanel */ public ResultsPanel() { initComponents(); Object[] buttonStruct = { "Run", UIBox.getIcon(0xF04B), // See gui/fonts/FontAwesome.ttf for alternative icons. new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { runButtonActionPerformed(evt); } } }; JComponent buttonContainer = UIBox.makeButtonContainer(buttonStruct, Wandora.getWandora()); buttonPanel.add(buttonContainer); } public QueryEditorDockPanel findDockPanel(){ Container c=this; while(c!=null && !(c instanceof QueryEditorDockPanel)){ c=c.getParent(); } if(c==null) return null; return (QueryEditorDockPanel)c; } public void clearResults(){ resultsPanel.removeAll(); resultsScroll.setColumnHeaderView(null); } public void executeQuery(){ clearResults(); QueryEditorDockPanel p=findDockPanel(); if(p==null) return; QueryEditorComponent editor=p.getQueryEditor(); if(editor==null) return; Directive directive=editor.buildDirective(); if(directive==null) return; ArrayList<Topic> context=new ArrayList<Topic>(); Topic t=((GetTopicButton)contextTopicButton).getTopic(); if(t!=null) context.add(t); try{ Wandora wandora=Wandora.getWandora(); MixedTopicTable table=QueryPanel.getTopicsByQuery(wandora, wandora.getTopicMap(), directive, context.iterator()); if(table==null) return; resultsPanel.add(table, BorderLayout.CENTER); resultsScroll.setColumnHeaderView(table.getTableHeader()); } catch(QueryException | TopicMapException e){ Wandora.getWandora().handleError(e); } } public void setContextTopic(Topic topic){ try{ ((GetTopicButton)contextTopicButton).setTopic(topic); if(autoUpdate){ if(topic==null) clearResults(); else executeQuery(); } } catch(TopicMapException tme){ Wandora.getWandora().handleError(tme); } } private void runButtonActionPerformed(java.awt.event.ActionEvent evt) { executeQuery(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; toolBar = new javax.swing.JToolBar(); buttonPanel = new javax.swing.JPanel(); fillerPanel = new javax.swing.JPanel(); innerFillerPanel = new javax.swing.JPanel(); jPanel1 = new javax.swing.JPanel(); jPanel2 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); try{ contextTopicButton = new GetTopicButton(); }catch(TopicMapException tme){Wandora.getWandora().handleError(tme);} resultsScroll = new javax.swing.JScrollPane(); resultsPanel = new javax.swing.JPanel(); setLayout(new java.awt.BorderLayout()); toolBar.setFloatable(false); toolBar.setRollover(true); buttonPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 0)); toolBar.add(buttonPanel); fillerPanel.setLayout(new java.awt.GridBagLayout()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; fillerPanel.add(innerFillerPanel, gridBagConstraints); toolBar.add(fillerPanel); add(toolBar, java.awt.BorderLayout.NORTH); jPanel1.setLayout(new java.awt.BorderLayout()); jPanel2.setLayout(new java.awt.GridBagLayout()); jLabel1.setText("Context: "); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; jPanel2.add(jLabel1, gridBagConstraints); contextTopicButton.setText("Topic"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; gridBagConstraints.weightx = 1.0; jPanel2.add(contextTopicButton, gridBagConstraints); jPanel1.add(jPanel2, java.awt.BorderLayout.PAGE_START); resultsPanel.setLayout(new java.awt.BorderLayout()); resultsScroll.setViewportView(resultsPanel); jPanel1.add(resultsScroll, java.awt.BorderLayout.CENTER); add(jPanel1, java.awt.BorderLayout.CENTER); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel buttonPanel; private javax.swing.JButton contextTopicButton; private javax.swing.JPanel fillerPanel; private javax.swing.JPanel innerFillerPanel; private javax.swing.JLabel jLabel1; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel resultsPanel; private javax.swing.JScrollPane resultsScroll; private javax.swing.JToolBar toolBar; // End of variables declaration//GEN-END:variables }
7,404
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
AbstractTypePanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/queryeditorpanel/AbstractTypePanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.queryeditorpanel; import java.awt.Container; import javax.swing.JPanel; import org.wandora.query2.DirectiveUIHints.Parameter; /** * * @author olli */ public abstract class AbstractTypePanel extends JPanel { private static final long serialVersionUID = 1L; protected Parameter parameter; protected DirectivePanel directivePanel; protected String orderingHint=null; public AbstractTypePanel(Parameter parameter,DirectivePanel directivePanel) { this.parameter=parameter; this.directivePanel=directivePanel; } public abstract void setLabel(String label); public void disconnect(){ } public String getOrderingHint() { return orderingHint; } public void setOrderingHint(String orderingHint) { this.orderingHint = orderingHint; } protected QueryEditorComponent getEditor(){ Container parent=getParent(); while(parent!=null && !(parent instanceof QueryEditorComponent)){ parent=parent.getParent(); } if(parent!=null) return (QueryEditorComponent)parent; else return null; } protected DirectivePanel getDirectivePanel(){ if(directivePanel!=null) return directivePanel; Container parent=getParent(); while(parent!=null && !(parent instanceof DirectivePanel)){ parent=parent.getParent(); } if(parent!=null) return (DirectivePanel)parent; else return null; } public abstract void setValue(Object o); public abstract Object getValue(); public abstract String getValueScript(); public Parameter getParameter(){ return parameter; } }
2,598
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
QueryEditorTopicPanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/queryeditorpanel/QueryEditorTopicPanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * */ package org.wandora.application.gui.topicpanels.queryeditorpanel; import java.util.Collection; import javax.swing.Icon; import javax.swing.JMenu; import javax.swing.JPanel; import javax.swing.JPopupMenu; import org.wandora.application.CancelledException; import org.wandora.application.LocatorHistory; import org.wandora.application.gui.UIBox; import org.wandora.application.gui.topicpanels.TopicPanel; import org.wandora.exceptions.OpenTopicNotSupportedException; import org.wandora.topicmap.Association; import org.wandora.topicmap.Locator; import org.wandora.topicmap.Topic; import org.wandora.topicmap.TopicMapException; /** * * @author olli */ public class QueryEditorTopicPanel implements TopicPanel { protected Topic openedTopic; protected QueryEditorDockPanel panel; public QueryEditorTopicPanel(){ } @Override public void init() { panel=new QueryEditorDockPanel(); } @Override public boolean supportsOpenTopic() { return true; } @Override public void open(Topic topic) throws TopicMapException, OpenTopicNotSupportedException { openedTopic=topic; panel.getResultsPanel().setContextTopic(topic); } @Override public void stop() { } @Override public void refresh() throws TopicMapException { } @Override public boolean applyChanges() throws CancelledException, TopicMapException { return true; } @Override public JPanel getGui() { return panel; } @Override public Topic getTopic() throws TopicMapException { return openedTopic; } @Override public String getName() { return "Query editor"; } @Override public String getTitle() { return getName(); } @Override public Icon getIcon() { return UIBox.getIcon("gui/icons/topic_panel_query_editor.png"); } @Override public int getOrder() { return 10000; } @Override public boolean noScroll(){ return true; } @Override public Object[] getViewMenuStruct() { return new Object[0]; } @Override public JMenu getViewMenu() { return null; } @Override public JPopupMenu getViewPopupMenu() { return null; } @Override public LocatorHistory getTopicHistory() { return null; } @Override public void topicSubjectIdentifierChanged(Topic t, Locator added, Locator removed) throws TopicMapException { } @Override public void topicBaseNameChanged(Topic t, String newName, String oldName) throws TopicMapException { } @Override public void topicTypeChanged(Topic t, Topic added, Topic removed) throws TopicMapException { } @Override public void topicVariantChanged(Topic t, Collection<Topic> scope, String newName, String oldName) throws TopicMapException { } @Override public void topicDataChanged(Topic t, Topic type, Topic version, String newValue, String oldValue) throws TopicMapException { } @Override public void topicSubjectLocatorChanged(Topic t, Locator newLocator, Locator oldLocator) throws TopicMapException { } @Override public void topicRemoved(Topic t) throws TopicMapException { } @Override public void topicChanged(Topic t) throws TopicMapException { } @Override public void associationTypeChanged(Association a, Topic newType, Topic oldType) throws TopicMapException { } @Override public void associationPlayerChanged(Association a, Topic role, Topic newPlayer, Topic oldPlayer) throws TopicMapException { } @Override public void associationRemoved(Association a) throws TopicMapException { } @Override public void associationChanged(Association a) throws TopicMapException { } }
4,715
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
DirectiveListLine.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/queryeditorpanel/DirectiveListLine.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * */ package org.wandora.application.gui.topicpanels.queryeditorpanel; import javax.swing.JComponent; import org.wandora.query2.DirectiveUIHints; /** * * @author olli */ public class DirectiveListLine extends javax.swing.JPanel { private static final long serialVersionUID = 1L; protected DirectiveUIHints hints; /** * Creates new form DirectiveListLine */ public DirectiveListLine() { initComponents(); DnDTools.setDragSourceHandler(this, "directiveHints", DnDTools.directiveHintsDataFlavor, new DnDTools.DragSourceCallback<DirectiveUIHints>() { @Override public DirectiveUIHints callback(JComponent component) { return hints; } }); } public DirectiveListLine(DirectiveUIHints hints) { this(); this.hints=hints; this.setLabel(hints.getLabel()); } public void setLabel(String s){ directiveLabel.setText(s); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; directiveLabel = new javax.swing.JLabel(); setLayout(new java.awt.GridBagLayout()); directiveLabel.setText("jLabel1"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; gridBagConstraints.weightx = 1.0; add(directiveLabel, gridBagConstraints); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel directiveLabel; // End of variables declaration//GEN-END:variables }
2,927
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
AddonPanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/queryeditorpanel/AddonPanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * */ package org.wandora.application.gui.topicpanels.queryeditorpanel; import org.wandora.query2.DirectiveUIHints.Addon; import org.wandora.query2.DirectiveUIHints.Parameter; /** * * @author olli */ public class AddonPanel extends javax.swing.JPanel { private static final long serialVersionUID = 1L; protected Addon addon; protected DirectiveEditor parentPanel; protected AbstractTypePanel[] parameterPanels; /** * Creates new form AddonPanel */ public AddonPanel() { initComponents(); } public AddonPanel(DirectiveEditor parent,Addon addon){ this(); this.parentPanel=parent; setAddon(addon); } public Addon getAddon(){ return addon; } public AbstractTypePanel[] getParameterPanels(){ return parameterPanels; } public void populateParametersPanel(){ Parameter[] parameters=addon.getParameters(); this.parameterPanels=DirectiveEditor.populateParametersPanel(parametersPanel, parameters, this.parameterPanels, parentPanel.getDirectivePanel()); this.revalidate(); parametersPanel.repaint(); } public void setAddon(Addon addon) { this.addon = addon; this.addonLabel.setText(addon.getLabel()); populateParametersPanel(); } public void disconnect(){ if(this.parameterPanels!=null){ for(AbstractTypePanel pp : this.parameterPanels){ pp.disconnect(); } } } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; addonLabel = new javax.swing.JLabel(); deleteButton = new javax.swing.JButton(); parametersPanel = new javax.swing.JPanel(); setBorder(javax.swing.BorderFactory.createEtchedBorder()); setLayout(new java.awt.GridBagLayout()); addonLabel.setFont(new java.awt.Font("Ubuntu", 1, 16)); // NOI18N addonLabel.setText("Addon label"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(5, 5, 0, 0); add(addonLabel, gridBagConstraints); deleteButton.setText("Remove addon"); deleteButton.setToolTipText(""); deleteButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { deleteButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END; gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 5); add(deleteButton, gridBagConstraints); parametersPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); parametersPanel.setLayout(new java.awt.GridBagLayout()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.gridwidth = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0); add(parametersPanel, gridBagConstraints); }// </editor-fold>//GEN-END:initComponents private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed parentPanel.removeAddon(this); }//GEN-LAST:event_deleteButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel addonLabel; private javax.swing.JButton deleteButton; private javax.swing.JPanel parametersPanel; // End of variables declaration//GEN-END:variables }
5,162
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
DirectiveParameterPanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/queryeditorpanel/DirectiveParameterPanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.queryeditorpanel; import java.awt.Point; import java.awt.Rectangle; import javax.swing.JComponent; import javax.swing.TransferHandler; import org.wandora.query2.Directive; import org.wandora.query2.DirectiveUIHints; import org.wandora.query2.DirectiveUIHints.Parameter; /** * * @author olli */ public class DirectiveParameterPanel extends AbstractTypePanel { private static final long serialVersionUID = 1L; protected Class<? extends Directive> directiveType; protected ConnectorAnchor fromAnchor; protected DirectivePanel fromPanel; /** * Creates new form DirectiveParameterPanel */ public DirectiveParameterPanel(Parameter parameter,DirectivePanel panel) { super(parameter, panel); initComponents(); disconnectButton.setVisible(false); DnDTools.addDropTargetHandler(directiveAnchor, DnDTools.directiveHintsDataFlavor, new DnDTools.DropTargetCallback<DirectiveUIHints>() { @Override public boolean callback(JComponent component, DirectiveUIHints hints, TransferHandler.TransferSupport support) { if(directiveType!=null && !directiveType.isAssignableFrom(hints.getClass())) return false; DirectivePanel directivePanel=getDirectivePanel(); QueryEditorComponent editor=directivePanel.getEditor(); DirectivePanel panel=editor.addDirective(hints); Point point=support.getDropLocation().getDropPoint(); Rectangle rect=directivePanel.getBounds(); panel.setBounds(rect.x+rect.width+10,rect.y,panel.getWidth(),panel.getHeight()); connectValue(panel); return true; } }); DnDTools.addDropTargetHandler(directiveAnchor, DnDTools.directivePanelDataFlavor, new DnDTools.DropTargetCallback<DirectivePanel>() { @Override public boolean callback(JComponent component, DirectivePanel o, TransferHandler.TransferSupport support) { DirectivePanel directivePanel=getDirectivePanel(); if(o==directivePanel) return false; connectValue(o); return true; } }); } @Override public void disconnect() { super.disconnect(); connectValue(null); } public void connectValue(DirectivePanel p){ if(p==null) { if(fromAnchor!=null) fromAnchor.setTo(null); disconnectButton.setVisible(false); directiveAnchor.setVisible(true); fromPanel=null; fromAnchor=null; return; } fromAnchor=p.getFromConnectorAnchor(); fromPanel=p; getDirectivePanel().connectParamAnchor(fromAnchor,this.orderingHint); disconnectButton.setVisible(true); directiveAnchor.setVisible(false); } public void setDirectiveType(Class<? extends Directive> cls){ directiveType=cls; } @Override public void setLabel(String label){ parameterLabel.setText(label); } @Override public void setValue(Object o){ if(o==null || !(o instanceof DirectivePanel)) { fromAnchor=null; fromPanel=null; disconnectButton.setVisible(false); directiveAnchor.setVisible(true); return; } DirectivePanel p=(DirectivePanel)o; fromPanel=p; fromAnchor=p.getFromConnectorAnchor(); disconnectButton.setVisible(true); directiveAnchor.setVisible(false); } @Override public Object getValue(){ return fromPanel; } @Override public String getValueScript(){ if(fromPanel==null) return null; return fromPanel.buildScript(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; parameterLabel = new javax.swing.JLabel(); directiveAnchor = new javax.swing.JLabel(); disconnectButton = new javax.swing.JButton(); setLayout(new java.awt.GridBagLayout()); parameterLabel.setText("Label"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridheight = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5); add(parameterLabel, gridBagConstraints); directiveAnchor.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); directiveAnchor.setText("Drag directive here"); directiveAnchor.setMaximumSize(new java.awt.Dimension(200, 20)); directiveAnchor.setMinimumSize(new java.awt.Dimension(20, 20)); directiveAnchor.setPreferredSize(new java.awt.Dimension(150, 20)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; add(directiveAnchor, gridBagConstraints); disconnectButton.setText("Disconnect directive"); disconnectButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { disconnectButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END; gridBagConstraints.weightx = 1.0; add(disconnectButton, gridBagConstraints); }// </editor-fold>//GEN-END:initComponents private void disconnectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_disconnectButtonActionPerformed connectValue(null); }//GEN-LAST:event_disconnectButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel directiveAnchor; private javax.swing.JButton disconnectButton; private javax.swing.JLabel parameterLabel; // End of variables declaration//GEN-END:variables }
7,601
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
QueryEditorComponent.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/queryeditorpanel/QueryEditorComponent.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package org.wandora.application.gui.topicpanels.queryeditorpanel; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Point; import java.awt.Rectangle; import java.util.ArrayList; import java.util.HashMap; import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.TransferHandler; import org.wandora.application.Wandora; import org.wandora.application.gui.UIBox; import org.wandora.application.gui.texteditor.TextEditor; import org.wandora.application.gui.topicpanels.queryeditorpanel.DirectiveEditor.DirectiveParameters; import org.wandora.application.gui.topicpanels.queryeditorpanel.QueryLibraryPanel.StoredQuery; import org.wandora.query2.Directive; import org.wandora.query2.DirectiveUIHints; import org.wandora.query2.DirectiveUIHints.Addon; import org.wandora.query2.DirectiveUIHints.Constructor; /** * * @author olli */ public class QueryEditorComponent extends javax.swing.JPanel { private static final long serialVersionUID = 1L; protected final ArrayList<Connector> connectors=new ArrayList<Connector>(); protected DirectivePanel selectedPanel; protected FinalResultPanel finalResultPanel; protected ConnectorAnchor finalResultAnchor; /** * Creates new form QueryEditorComponent */ public QueryEditorComponent() { initComponents(); finalResultPanel=new FinalResultPanel(); addDirectivePanel(finalResultPanel); finalResultPanel.setSize(finalResultPanel.getPreferredSize()); finalResultAnchor=finalResultPanel.getToConnectorAnchor(); DnDTools.addDropTargetHandler(queryGraphPanel, DnDTools.directiveHintsDataFlavor, new DnDTools.DropTargetCallback<DirectiveUIHints>(){ @Override public boolean callback(JComponent component, DirectiveUIHints hints, TransferHandler.TransferSupport support) { DirectivePanel panel=addDirective(hints); Point point=support.getDropLocation().getDropPoint(); panel.setBounds(point.x,point.y,panel.getWidth(),panel.getHeight()); return true; } }); /* DnDTools.addDropTargetHandler(finalResultLabel, DnDTools.directivePanelDataFlavor, new DnDTools.DropTargetCallback<DirectivePanel>(){ @Override public boolean callback(JComponent component, DirectivePanel panel, TransferHandler.TransferSupport support) { finalResultAnchor.setFrom(panel.getFromConnectorAnchor()); return true; } }); */ Object[] buttonStruct = { "New", UIBox.getIcon(0xF016), // See gui/fonts/FontAwesome.ttf for alternative icons. new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { newButtonActionPerformed(evt); } }, "Build script", UIBox.getIcon(0xF085), // See gui/fonts/FontAwesome.ttf for alternative icons. new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buildButtonActionPerformed(evt); } }, "Run", UIBox.getIcon(0xF04B), new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { runButtonActionPerformed(evt); } }, /* "Delete", UIBox.getIcon(0xF014), new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { deleteButtonActionPerformed(evt); } }*/ }; JComponent buttonContainer = UIBox.makeButtonContainer(buttonStruct, Wandora.getWandora()); buttonPanel.add(buttonContainer); } public static DirectivePanel resolveDirectivePanel(Component component){ while(component!=null && !(component instanceof DirectivePanel)){ component=component.getParent(); } return (DirectivePanel)component; // this could be null but the cast will work } public QueryEditorDockPanel findDockPanel(){ Container c=this; while(c!=null && !(c instanceof QueryEditorDockPanel)){ c=c.getParent(); } if(c==null) return null; return (QueryEditorDockPanel)c; } public QueryEditorInspectorPanel findInspector(){ QueryEditorDockPanel p=findDockPanel(); if(p==null) return null; else return p.getInspector(); } public void applyInspectorChanges(){ if(this.selectedPanel!=null) { QueryEditorInspectorPanel inspector=findInspector(); if(inspector!=null){ inspector.saveChanges(); } } } public DirectivePanel getRootPanel(){ ConnectorAnchor from=finalResultAnchor.getFrom(); if(from==null) return null; JComponent component=from.getComponent(); if(component==null) return null; DirectivePanel p=resolveDirectivePanel(component); if(p==null) return null; return p; } public String buildScript(){ applyInspectorChanges(); DirectivePanel p=getRootPanel(); if(p==null) return null; else return "importPackage(org.wandora.query2);\n"+p.buildScript(); } public Directive buildDirective(){ applyInspectorChanges(); DirectivePanel p=getRootPanel(); if(p==null) return null; else return p.buildDirective(); } public StoredQuery getStoredQuery(){ applyInspectorChanges(); DirectivePanel rootPanel=getRootPanel(); if(rootPanel==null) return null; StoredQuery ret=new StoredQuery(); ret.name=null; ret.rootDirective=rootPanel.getDirectiveId(); ArrayList<DirectiveParameters> directiveParams=new ArrayList<>(); for(int i=0;i<queryGraphPanel.getComponentCount();i++){ Component c=queryGraphPanel.getComponent(i); if(c instanceof DirectivePanel){ DirectivePanel panel=(DirectivePanel)c; directiveParams.add(panel.getDirectiveParameters()); } } ret.directiveParameters=directiveParams; return ret; } public void clearQuery(){ ArrayList<Component> remove=new ArrayList<>(); for(int i=0;i<queryGraphPanel.getComponentCount();i++){ Component c=queryGraphPanel.getComponent(i); synchronized(connectors){ connectors.clear(); } selectPanel(null); finalResultAnchor.setFrom(null); if(c instanceof DirectivePanel && c!=finalResultPanel){ remove.add(c); } } for(Component c : remove) queryGraphPanel.remove(c); Rectangle bounds=finalResultPanel.getBounds(); finalResultPanel.setBounds(new Rectangle(0,0,bounds.width,bounds.height)); } public void openStoredQuery(StoredQuery query){ HashMap<String,DirectivePanel> directiveMap=new HashMap<>(); for(DirectiveParameters params : query.directiveParameters){ try{ Class cls=Class.forName(params.cls); DirectivePanel panel=null; if(!Directive.class.isAssignableFrom(cls)) throw new ClassCastException("Stored query class is not a Directive"); if(cls.equals(FinalResultDirective.class)){ panel=finalResultPanel; } else { DirectiveUIHints hints=DirectiveUIHints.getDirectiveUIHints(cls); panel=addDirective(hints); } directiveMap.put(params.id, panel); }catch(ClassNotFoundException | ClassCastException e){ Wandora.getWandora().handleError(e); } } for(DirectiveParameters params : query.directiveParameters){ params.resolveDirectiveValues(directiveMap); } for(DirectiveParameters params : query.directiveParameters){ DirectivePanel panel=directiveMap.get(params.id); panel.setDirectiveParams(params); } updatePanelSize(); } public void selectPanel(DirectivePanel panel){ DirectivePanel old=this.selectedPanel; this.selectedPanel=panel; if(old!=null) old.setSelected(false); if(panel!=null) panel.setSelected(true); this.repaint(); QueryEditorInspectorPanel inspector=findInspector(); if(inspector!=null){ inspector.setSelection(panel); } } public void addConnector(Connector c){ synchronized(connectors){ connectors.add(c); } queryGraphPanel.repaint(); } public void removeConnector(Connector c){ synchronized(connectors){ connectors.remove(c); } queryGraphPanel.repaint(); } public void addDirectivePanel(DirectivePanel panel){ this.queryGraphPanel.add(panel); this.queryGraphPanel.invalidate(); this.queryGraphPanel.repaint(); } public DirectivePanel addDirective(Class<? extends Directive> dir){ return addDirective(DirectiveUIHints.getDirectiveUIHints(dir)); } public DirectivePanel addDirective(DirectiveUIHints hints){ DirectivePanel panel=new DirectivePanel(hints); addDirectivePanel(panel); //panel.setBounds(10, 10, 300, 200); panel.revalidate(); return panel; } public JPanel getGraphPanel(){ return queryGraphPanel; } private void changePanelSize(int width,int height, int offsx, int offsy){ Dimension d=new Dimension(width,height); queryGraphPanel.setMaximumSize(d); queryGraphPanel.setPreferredSize(d); queryGraphPanel.setMinimumSize(d); queryGraphPanel.setSize(d); if(offsx!=0 || offsy!=0){ for(int i=0;i<queryGraphPanel.getComponentCount();i++){ Component c=queryGraphPanel.getComponent(i); Rectangle b=c.getBounds(); c.setBounds(b.x+offsx, b.y+offsy, b.width, b.height); } Point p=queryScrollPane.getViewport().getViewPosition(); queryScrollPane.getViewport().setViewPosition(new Point(p.x+offsx,p.y+offsy)); } } private void updatePanelSize(){ int w=0; int h=0; for(int i=0;i<queryGraphPanel.getComponentCount();i++){ Component c=queryGraphPanel.getComponent(i); if(c instanceof DirectivePanel){ Rectangle rect=c.getBounds(); w=Math.max(w,rect.x+rect.width); h=Math.max(h,rect.y+rect.height); } } if(w!=this.getWidth() || h!=this.getHeight()){ changePanelSize(w,h,0,0); } } public void panelMoved(DirectivePanel panel){ Rectangle rect=panel.getBounds(); if(rect.x<0){ changePanelSize(queryGraphPanel.getWidth()-rect.x,queryGraphPanel.getHeight(),-rect.x,0); rect=panel.getBounds(); } if(rect.y<0){ changePanelSize(queryGraphPanel.getWidth(),queryGraphPanel.getHeight()-rect.y,0,-rect.y); rect=panel.getBounds(); } updatePanelSize(); queryGraphPanel.invalidate(); queryGraphPanel.repaint(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; jScrollPane1 = new javax.swing.JScrollPane(); directiveListPanel = new javax.swing.JPanel(); queryScrollPane = new javax.swing.JScrollPane(); queryGraphPanel = new GraphPanel(); toolBar = new javax.swing.JToolBar(); buttonPanel = new javax.swing.JPanel(); fillerPanel = new javax.swing.JPanel(); innerFillerPanel = new javax.swing.JPanel(); directiveListPanel.setLayout(new java.awt.GridBagLayout()); jScrollPane1.setViewportView(directiveListPanel); setLayout(new java.awt.BorderLayout()); queryGraphPanel.setBackground(new java.awt.Color(255, 255, 255)); queryGraphPanel.setLayout(null); queryScrollPane.setViewportView(queryGraphPanel); add(queryScrollPane, java.awt.BorderLayout.CENTER); toolBar.setFloatable(false); toolBar.setRollover(true); buttonPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 0)); toolBar.add(buttonPanel); fillerPanel.setLayout(new java.awt.GridBagLayout()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; fillerPanel.add(innerFillerPanel, gridBagConstraints); toolBar.add(fillerPanel); add(toolBar, java.awt.BorderLayout.NORTH); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel buttonPanel; private javax.swing.JPanel directiveListPanel; private javax.swing.JPanel fillerPanel; private javax.swing.JPanel innerFillerPanel; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JPanel queryGraphPanel; private javax.swing.JScrollPane queryScrollPane; private javax.swing.JToolBar toolBar; // End of variables declaration//GEN-END:variables public void removeDirective(DirectivePanel panel){ if(panel!=null && panel!=finalResultPanel){ panel.disconnectConnectors(); queryGraphPanel.remove(panel); if(selectedPanel==panel) selectPanel(null); queryGraphPanel.repaint(); } } private void newButtonActionPerformed(java.awt.event.ActionEvent evt) { clearQuery(); } private void runButtonActionPerformed(java.awt.event.ActionEvent evt) { QueryEditorDockPanel p=findDockPanel(); if(p==null) return; p.bringResultsFront(); ResultsPanel res=p.getResultsPanel(); res.executeQuery(); } private void buildButtonActionPerformed(java.awt.event.ActionEvent evt) { try{ String s=buildScript(); TextEditor editor=new TextEditor(Wandora.getWandora(), true, s); editor.setVisible(true); } catch(Exception e){ Wandora.getWandora().handleError(e); } } /* This is just a placeholder class used for the final result panel. It serves no other function than to identify the panel in some cases. */ protected static class FinalResultDirective extends Directive { public FinalResultDirective(){} } protected static class FinalResultPanel extends DirectivePanel { public FinalResultPanel(){ super(new DirectiveUIHints(FinalResultDirective.class, new Constructor[]{}, new Addon[]{}, "Final result", null)); fromDirectiveAnchor.setVisible(false); } @Override public JPanel getEditorPanel() { return null; } } private class GraphPanel extends JPanel { public GraphPanel(){ super(); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); synchronized(connectors){ for(Connector c : connectors){ c.repaint(g); } } } } }
17,827
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
DirectivePanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/queryeditorpanel/DirectivePanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * */ package org.wandora.application.gui.topicpanels.queryeditorpanel; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.Rectangle; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionAdapter; import java.lang.reflect.Array; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collections; import javax.swing.JComponent; import javax.swing.JPanel; import javax.swing.TransferHandler; import org.wandora.application.Wandora; import org.wandora.application.gui.topicpanels.queryeditorpanel.DirectiveEditor.AddonParameters; import org.wandora.application.gui.topicpanels.queryeditorpanel.DirectiveEditor.BoundParameter; import org.wandora.application.gui.topicpanels.queryeditorpanel.DirectiveEditor.DirectiveParameters; import org.wandora.query2.Directive; import org.wandora.query2.DirectiveUIHints; import org.wandora.query2.DirectiveUIHints.Constructor; /** * * @author olli */ public class DirectivePanel extends javax.swing.JPanel { private static final long serialVersionUID = 1L; protected DirectiveUIHints hints; protected DirectivePanel to; protected DirectivePanel from; protected Connector toConnector; protected Connector fromConnector; protected ConnectorAnchor toConnectorAnchor; protected ConnectorAnchor fromConnectorAnchor; // protected final ArrayList<ConnectorAnchor> paramsConnectors=new ArrayList<>(); protected DirectiveParameters directiveParameters; protected final ArrayList<ParamAnchorInfo> paramAnchors=new ArrayList<>(); protected Dimension normalDimensions; /** * Creates new form DirectivePanel */ public DirectivePanel() { initComponents(); this.toConnectorAnchor=new ComponentConnectorAnchor(toDirectiveAnchor,ConnectorAnchor.Direction.RIGHT,true,false); this.fromConnectorAnchor=new ComponentConnectorAnchor(fromDirectiveAnchor,ConnectorAnchor.Direction.LEFT,false,true); } protected boolean dragging=false; protected int dragStartX=-1; protected int dragStartY=-1; public DirectivePanel(DirectiveUIHints hints){ this(); setDirective(hints); titleLabel.addMouseListener(new MouseAdapter(){ @Override public void mouseReleased(MouseEvent e) { dragging=false; } @Override public void mousePressed(MouseEvent e) { dragging=true; dragStartX=e.getX(); dragStartY=e.getY(); QueryEditorComponent editor=getEditor(); if(editor!=null) editor.selectPanel(DirectivePanel.this); } }); titleLabel.addMouseMotionListener(new MouseMotionAdapter(){ @Override public void mouseDragged(MouseEvent e) { QueryEditorComponent editor=getEditor(); if(editor!=null) { Rectangle rect=getBounds(); setBounds( rect.x+e.getX()-dragStartX, rect.y+e.getY()-dragStartY, rect.width,rect.height); editor.panelMoved(DirectivePanel.this); } } }); DnDTools.setDragSourceHandler(fromDirectiveAnchor, "directivePanel", DnDTools.directivePanelDataFlavor, new DnDTools.DragSourceCallback<DirectivePanel>() { @Override public DirectivePanel callback(JComponent component) { return DirectivePanel.this; } }); DnDTools.addDropTargetHandler(toDirectiveAnchor, DnDTools.directivePanelDataFlavor, new DnDTools.DropTargetCallback<DirectivePanel>(){ @Override public boolean callback(JComponent component, DirectivePanel o, TransferHandler.TransferSupport support) { if(o==DirectivePanel.this) return false; toConnectorAnchor.setFrom(o.getFromConnectorAnchor()); return true; } }); } protected static class ParamAnchorInfo implements Comparable { public ConnectorAnchor anchor; public JPanel component; public String order; public ParamAnchorInfo(){} public ParamAnchorInfo(ConnectorAnchor anchor, JPanel component, String order) { this.anchor = anchor; this.component = component; this.order = order; } @Override public int compareTo(Object o) { if(o==null) return 1; if(!o.getClass().equals(this.getClass())) return 1; ParamAnchorInfo p=(ParamAnchorInfo)o; if(this.order==null && p.order==null) return 0; else if(this.order==null && p.order!=null) return -1; else if(this.order!=null && p.order==null) return 1; else return this.order.compareTo(p.order); } } public static DirectivePanel findDirectivePanel(Component c){ while(c!=null && !(c instanceof DirectivePanel) && c instanceof Container){ c=((Container)c).getParent(); } if(c instanceof DirectivePanel) return (DirectivePanel)c; else return null; } public void setDetailsText(String text){ if(text==null) text=""; if(!text.isEmpty()) { text=text.replace("&","&amp;"); text=text.replace("<","&lt;"); text=text.replace("\n", "<br>"); text="<html>"+text+"</html>"; } detailsLabel.setText(text); //int height=titleLabel.getPreferredSize().height+detailsLabel.getPreferredSize().height+5; //this.setSize(this.getSize().width, height); this.setSize(this.getPreferredSize()); this.repaint(); } protected void updateParamAnchors(){ synchronized(paramAnchors){ Collections.sort(paramAnchors); parameterDirectiveAnchors.removeAll(); final GridLayout layout=(GridLayout)parameterDirectiveAnchors.getLayout(); layout.setColumns(paramAnchors.size()); for(ParamAnchorInfo p : paramAnchors){ parameterDirectiveAnchors.add(p.component); } } parameterDirectiveAnchors.revalidate(); getEditor().repaint(); } protected BoundParameter clearParameterValue(BoundParameter param,Object value){ if(param==null) return null; if(param.value==value) return new BoundParameter(param.getParameter(),null); if(param.getParameter().isMultiple()){ for(int i=0;i<Array.getLength(param.value);i++){ if(Array.get(param.value, i)==value) { Array.set(param.value, i, null); } } } return param; } protected void directiveConnectionRemoved(DirectivePanel panel){ if(panel==null) return; if(directiveParameters==null) return; if(directiveParameters.parameters!=null){ for(int i=0;i<directiveParameters.parameters.length;i++){ directiveParameters.parameters[i]=clearParameterValue(directiveParameters.parameters[i],panel); } } if(directiveParameters.addons!=null){ for(AddonParameters a : directiveParameters.addons){ if(a.parameters!=null){ for(int i=0;i<a.parameters.length;i++){ a.parameters[i]=clearParameterValue(a.parameters[i],panel); } } } } } public ConnectorAnchor connectParamAnchor(ConnectorAnchor from,String ordering){ synchronized(paramAnchors){ final JPanel anchorComp=new JPanel(); final ParamAnchorInfo info=new ParamAnchorInfo(null, anchorComp, ordering); ComponentConnectorAnchor anchor=new ComponentConnectorAnchor(anchorComp,ConnectorAnchor.Direction.DOWN, true, false){ @Override public boolean setFrom(ConnectorAnchor from) { ConnectorAnchor oldFromAnchor=getFrom(); DirectivePanel oldFrom=DirectivePanel.findDirectivePanel(oldFromAnchor.getComponent()); directiveConnectionRemoved(oldFrom); boolean ret=super.setFrom(from); if(from==null){ synchronized(paramAnchors){ paramAnchors.remove(info); updateParamAnchors(); updateDetailsText(); } } return ret; } }; info.anchor=anchor; paramAnchors.add(info); from.setTo(anchor); updateParamAnchors(); getEditor().applyInspectorChanges(); updateDetailsText(); return anchor; } } /** * Sets directive parameters and connects any connectors set in the params * as well as sets the panel dimensions. * @param params */ public void setDirectiveParams(DirectiveParameters params){ saveDirectiveParameters(params); Rectangle bounds=getBounds(); setBounds(new Rectangle(params.posx,params.posy,bounds.width,bounds.height)); params.connectAnchors(this); } /** * Sets directive parameters but does not connect connectors, or panel * dimensions, only stores the parameters variable. * @param params */ public void saveDirectiveParameters(DirectiveParameters params){ this.directiveParameters=params; updateDetailsText(); } public void updateDetailsText(){ setDetailsText(buildDetailsText()); } public String buildDetailsLine(String text,String next){ StringBuilder sb=new StringBuilder(text); buildDetailsLine(sb,next); return sb.toString(); } public void buildDetailsLine(StringBuilder text,String next){ int ind=text.lastIndexOf("\n"); int lastLineLength=text.length()-(ind+1); ind=next.indexOf("\n"); int nextLineLength=(ind>=0?ind:(next.length())); if(lastLineLength+nextLineLength>25 && text.length()>0) text.append("\n").append(next); else { if(text.length()>0) text.append(" "); text.append(next); } } public String buildDetailsParamText(Object o){ if(o==null){ return "null"; } else if(o instanceof DirectivePanel){ return "<DIR>"; } else if(o.getClass().isArray()){ StringBuilder sb=new StringBuilder(); for(int i=0;i<Array.getLength(o);i++){ if(i>0) sb.append(","); buildDetailsLine(sb,buildDetailsParamText(Array.get(o, i))); } sb.append("]"); return "["+sb.toString(); } else { String s=o.toString(); if(s.length()>15){ int ind=s.lastIndexOf("#"); if(ind>=0) s=s.substring(ind); else { ind=s.lastIndexOf("/"); if(ind>=0) s=s.substring(ind); } if(s.length()>15) s="..."+s.substring(s.length()-15); else s="..."+s; } if(o instanceof String) return "\""+s+"\""; else return "<"+s+">"; } } public String buildDetailsParamsText(BoundParameter[] params){ StringBuilder sb=new StringBuilder(); for(BoundParameter p : params){ Object o=p.getValue(); String s=buildDetailsParamText(o); if(s!=null) { if(sb.length()>0) sb.append(","); buildDetailsLine(sb,s); } } return sb.toString(); } public String buildDetailsText(){ StringBuilder sb=new StringBuilder(); String constructor=buildDetailsParamsText(this.directiveParameters.parameters); if(constructor.length()>0) sb.append("(").append(constructor).append(")"); AddonParameters[] addons=this.directiveParameters.addons; for(AddonParameters a : addons){ String addon=buildDetailsParamsText(a.parameters); if(addon.length()>0){ if(sb.length()>0) sb.append("\n"); sb.append(".").append(a.addon.getMethod()); sb.append("(").append(addon).append(")"); } } return sb.toString(); } public DirectiveParameters getDirectiveParameters(){ if(directiveParameters==null){ Constructor c=null; if(hints.getConstructors().length>0) c=hints.getConstructors()[0]; BoundParameter[] params=new BoundParameter[0]; if(c!=null && c.getParameters().length>0) params=new BoundParameter[c.getParameters().length]; directiveParameters=new DirectiveParameters(getDirectiveId(),c,params,new AddonParameters[0]); } directiveParameters.id=this.getDirectiveId(); directiveParameters.from=getFromPanel(); directiveParameters.cls=hints.getDirectiveClass().getName(); Rectangle bounds=getBounds(); directiveParameters.posx=bounds.x; directiveParameters.posy=bounds.y; return directiveParameters; } public JPanel getEditorPanel(){ DirectiveEditor editor=new DirectiveEditor(this,hints); return editor; } protected Object buildConstructor(boolean script){ if(!script) throw new RuntimeException("not implemented"); StringBuilder sb=new StringBuilder(); sb.append("new "); sb.append(hints.getDirectiveClass().getSimpleName()); sb.append("("); if(directiveParameters!=null){ Constructor c=directiveParameters.constructor; BoundParameter[] parameters=directiveParameters.parameters; for(int i=0;i<parameters.length;i++){ BoundParameter p=parameters[i]; if(i>0) sb.append(", "); sb.append(p.getScriptValue()); } } sb.append(")"); return sb.toString(); } public DirectivePanel getFromPanel(){ ConnectorAnchor fromA=toConnectorAnchor.getFrom(); if(fromA!=null){ JComponent component=fromA.getComponent(); if(component==null) return null; DirectivePanel p=QueryEditorComponent.resolveDirectivePanel(component); return p; } else return null; } public String buildAddonScript(AddonParameters addon){ StringBuilder sb=new StringBuilder(); sb.append("."); sb.append(addon.addon.getMethod()); sb.append("("); for(int i=0;i<addon.parameters.length;i++){ BoundParameter p=addon.parameters[i]; if(i>0) sb.append(", "); sb.append(p.getScriptValue()); } sb.append(")"); return sb.toString(); } public String buildScript(){ String s=(String)buildConstructor(true); if(directiveParameters!=null){ for(AddonParameters addon : directiveParameters.addons){ String addonScript=buildAddonScript(addon); if(addonScript!=null) s+=addonScript; } } DirectivePanel p=getFromPanel(); if(p!=null){ String s2=p.buildScript(); s2=DirectiveUIHints.indent(s2, 2); s+=".from(\n"+s2+"\n)"; } return s; } public Directive buildDirective(){ Object[] params=null; java.lang.reflect.Constructor constr=null; try{ if(directiveParameters!=null) { constr=directiveParameters.constructor.getReflectConstructor(hints.getDirectiveClass()); params=new Object[directiveParameters.parameters.length]; for(int i=0;i<directiveParameters.parameters.length;i++){ BoundParameter param=directiveParameters.parameters[i]; params[i]=param.getBuildValue(); } } else { Constructor[] cs=hints.getConstructors(); for(Constructor c : cs){ if(c.getParameters().length==0){ constr=c.getReflectConstructor(hints.getDirectiveClass()); params=new Object[0]; break; } } } if(constr!=null){ try{ Object newInst=constr.newInstance(params); Directive dir=(Directive)newInst; if(directiveParameters!=null){ for(AddonParameters addon : directiveParameters.addons){ java.lang.reflect.Method method=addon.addon.resolveMethod(dir.getClass()); Object[] addonParams=new Object[addon.parameters.length]; for(int i=0;i<addon.parameters.length;i++){ BoundParameter param=addon.parameters[i]; addonParams[i]=param.getBuildValue(); } dir=(Directive)method.invoke(dir, addonParams); } } DirectivePanel p=getFromPanel(); if(p!=null){ Directive from=p.buildDirective(); return dir.from(from); } else return dir; } catch(IllegalAccessException | IllegalArgumentException | InstantiationException | InvocationTargetException e){ Wandora.getWandora().handleError(e); } } } catch(NoSuchMethodException e){ Wandora.getWandora().handleError(e); } return null; } public String getDirectiveId(){ return ""+System.identityHashCode(this); } public void setSelected(boolean b){ if(b){ setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 255), 2)); } else { setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2)); } } public ConnectorAnchor getToConnectorAnchor(){ return toConnectorAnchor; } public ConnectorAnchor getFromConnectorAnchor(){ return fromConnectorAnchor; } public void disconnectConnectors(){ toConnectorAnchor.setFrom(null); fromConnectorAnchor.setTo(null); } protected QueryEditorComponent getEditor(){ Container parent=getParent(); while(parent!=null && !(parent instanceof QueryEditorComponent)){ parent=parent.getParent(); } if(parent!=null) return (QueryEditorComponent)parent; else return null; } public void setDirective(DirectiveUIHints hints){ this.hints=hints; this.titleLabel.setText(this.hints.getLabel()); this.setSize(this.getPreferredSize()); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; detailsLabel = new javax.swing.JLabel(); toDirectiveAnchor = new javax.swing.JLabel(); fromDirectiveAnchor = new javax.swing.JLabel(); parameterDirectiveAnchors = new javax.swing.JPanel(); titleLabel = new javax.swing.JLabel(); setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 2)); setLayout(new java.awt.GridBagLayout()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.gridwidth = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; add(detailsLabel, gridBagConstraints); toDirectiveAnchor.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); toDirectiveAnchor.setText("<-"); toDirectiveAnchor.setMaximumSize(new java.awt.Dimension(20, 20)); toDirectiveAnchor.setMinimumSize(new java.awt.Dimension(20, 20)); toDirectiveAnchor.setPreferredSize(new java.awt.Dimension(20, 20)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; add(toDirectiveAnchor, gridBagConstraints); fromDirectiveAnchor.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); fromDirectiveAnchor.setText("<-"); fromDirectiveAnchor.setMaximumSize(new java.awt.Dimension(20, 20)); fromDirectiveAnchor.setMinimumSize(new java.awt.Dimension(20, 20)); fromDirectiveAnchor.setPreferredSize(new java.awt.Dimension(20, 20)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; add(fromDirectiveAnchor, gridBagConstraints); parameterDirectiveAnchors.setMinimumSize(new java.awt.Dimension(1, 1)); parameterDirectiveAnchors.setLayout(new java.awt.GridLayout(1, 0)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.gridwidth = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; add(parameterDirectiveAnchors, gridBagConstraints); titleLabel.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N titleLabel.setText("Title"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.weightx = 1.0; add(titleLabel, gridBagConstraints); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables protected javax.swing.JLabel detailsLabel; protected javax.swing.JLabel fromDirectiveAnchor; private javax.swing.JPanel parameterDirectiveAnchors; private javax.swing.JLabel titleLabel; protected javax.swing.JLabel toDirectiveAnchor; // End of variables declaration//GEN-END:variables }
24,470
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
TopicParameterPanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/queryeditorpanel/TopicParameterPanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.queryeditorpanel; import org.wandora.application.Wandora; import org.wandora.application.gui.GetTopicButton; import org.wandora.query2.DirectiveUIHints.Parameter; import org.wandora.topicmap.Topic; import org.wandora.topicmap.TopicMapException; /** * * @author olli */ public class TopicParameterPanel extends AbstractTypePanel { private static final long serialVersionUID = 1L; /** * Creates new form TopicParameterPanel */ public TopicParameterPanel(Parameter parameter,DirectivePanel panel) { super(parameter,panel); initComponents(); } @Override public void setLabel(String label){ parameterLabel.setText(label); } @Override public void setValue(Object o){ try{ if(o instanceof Topic) ((GetTopicButton)getTopicButton).setTopic((Topic)o); else if(o instanceof String) ((GetTopicButton)getTopicButton).setTopic((String)o); else throw new RuntimeException("Topic value must be a topic or a string"); }catch(TopicMapException tme){ Wandora.getWandora().handleError(tme); } } @Override public Object getValue(){ return ((GetTopicButton)getTopicButton).getTopic(); } @Override public String getValueScript(){ Object o=getValue(); if(o==null) return "null"; if(o instanceof Topic){ try{ return "\""+((Topic)o).getOneSubjectIdentifier().toExternalForm()+"\""; }catch(TopicMapException tme){ Wandora.getWandora().handleError(tme); return null; } } else if(o instanceof String){ return "\""+o+"\""; } else throw new RuntimeException("Topic value must be a topic or a string"); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; parameterLabel = new javax.swing.JLabel(); try{ getTopicButton = new GetTopicButton(); }catch(TopicMapException tme){Wandora.getWandora().handleError(tme);} setLayout(new java.awt.GridBagLayout()); parameterLabel.setText("Label"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5); add(parameterLabel, gridBagConstraints); getTopicButton.setText("Topic"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.weightx = 1.0; add(getTopicButton, gridBagConstraints); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton getTopicButton; private javax.swing.JLabel parameterLabel; // End of variables declaration//GEN-END:variables }
4,086
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
UnknownParameterTypePanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/queryeditorpanel/UnknownParameterTypePanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.queryeditorpanel; import org.wandora.query2.DirectiveUIHints.Parameter; /** * * @author olli */ public class UnknownParameterTypePanel extends AbstractTypePanel { private static final long serialVersionUID = 1L; /** * Creates new form UnknownParameterTypePanel */ public UnknownParameterTypePanel(Parameter parameter,DirectivePanel panel) { super(parameter,panel); initComponents(); } @Override public void setLabel(String label){ parameterLabel.setText(label); } @Override public void setValue(Object o){ } @Override public Object getValue(){ return null; } @Override public String getValueScript(){ return "null"; } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; parameterLabel = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); setLayout(new java.awt.GridBagLayout()); parameterLabel.setText("Label"); add(parameterLabel, new java.awt.GridBagConstraints()); jLabel2.setText("Warning: Unknown parameter type."); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.weightx = 1.0; add(jLabel2, gridBagConstraints); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel jLabel2; private javax.swing.JLabel parameterLabel; // End of variables declaration//GEN-END:variables }
2,760
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
QueryEditorDockPanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/queryeditorpanel/QueryEditorDockPanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.queryeditorpanel; import java.awt.BorderLayout; import javax.swing.JPanel; import bibliothek.gui.DockController; import bibliothek.gui.DockStation; import bibliothek.gui.Dockable; import bibliothek.gui.dock.DefaultDockable; import bibliothek.gui.dock.SplitDockStation; import bibliothek.gui.dock.StackDockStation; import bibliothek.gui.dock.station.split.SplitDockGrid; /** * * @author olli */ public class QueryEditorDockPanel extends JPanel { private static final long serialVersionUID = 1L; protected DockController dockController; protected SplitDockStation dockStation; protected QueryEditorComponent queryEditor; protected DirectivesListPanel directivesList; protected QueryEditorInspectorPanel inspector; protected QueryLibraryPanel queryLibrary; protected ResultsPanel resultsPanel; protected Dockable resultsDockable; protected Dockable editorDockable; public QueryEditorDockPanel() { dockController=new DockController(); dockStation=new SplitDockStation(); dockController.add(dockStation); queryEditor=new QueryEditorComponent(); directivesList=new DirectivesListPanel(); inspector=new QueryEditorInspectorPanel(); queryLibrary=new QueryLibraryPanel(); resultsPanel=new ResultsPanel(); StackDockStation mainStack=new StackDockStation(); editorDockable=new DefaultDockable(queryEditor, "Graph Editor"); mainStack.add(editorDockable, 0); resultsDockable=new DefaultDockable(resultsPanel, "Query results"); mainStack.add(resultsDockable, 1); mainStack.setFrontDockable(editorDockable); StackDockStation topRight=new StackDockStation(); DefaultDockable directivesDockable=new DefaultDockable(directivesList, "Directives list"); topRight.add(directivesDockable, 0); topRight.add(new DefaultDockable(queryLibrary, "QueryLibrary"), 1); topRight.setFrontDockable(directivesDockable); SplitDockGrid grid=new SplitDockGrid(); grid.addDockable(0,0,2,2, mainStack); grid.addDockable(2,0,1,1, topRight); grid.addDockable(2,1,1,1, new DefaultDockable(inspector, "Inspector")); dockStation.dropTree( grid.toTree() ); this.setLayout(new BorderLayout()); this.add(dockStation.getComponent()); } public QueryEditorComponent getQueryEditor() { return queryEditor; } public DirectivesListPanel getDirectivesList() { return directivesList; } public QueryEditorInspectorPanel getInspector() { return inspector; } public QueryLibraryPanel getQueryLibrary() { return queryLibrary; } public ResultsPanel getResultsPanel() { return resultsPanel; } public void bringEditorFront(){ DockStation station=editorDockable.getDockParent(); station.setFrontDockable(editorDockable); } public void bringResultsFront(){ DockStation station=resultsDockable.getDockParent(); station.setFrontDockable(resultsDockable); } }
4,067
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
TopicOperandParameterPanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/queryeditorpanel/TopicOperandParameterPanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.queryeditorpanel; import org.wandora.query2.DirectiveUIHints.Parameter; import org.wandora.topicmap.Topic; /** * * @author olli */ public class TopicOperandParameterPanel extends OperandParameterPanel { private static final long serialVersionUID = 1L; public TopicOperandParameterPanel(Parameter parameter,DirectivePanel panel){ super(parameter,panel); } @Override public void setValue(Object o){ if(o instanceof Topic){ operandTypeComboBox.setSelectedItem("Topic"); operandTypeChanged(); parameterPanel.setValue(o); } else if(o instanceof String){ operandTypeComboBox.setSelectedItem("Subject Identifier"); operandTypeChanged(); parameterPanel.setValue(o); } else super.setValue(o); } @Override protected void setOperandTypes() { super.setOperandTypes(); operandTypeComboBox.removeItem("String"); operandTypeComboBox.addItem("Subject Identifier"); operandTypeComboBox.addItem("Topic"); } @Override protected boolean operandTypeChanged(){ if(super.operandTypeChanged()) return true; Object o=operandTypeComboBox.getSelectedItem(); if(o==null) return false; // shouldn't happen as super takes care of this String type=o.toString(); if(type.equalsIgnoreCase("Topic")){ operandPanel.removeAll(); TopicParameterPanel p=new TopicParameterPanel(parameter,this.directivePanel); p.setLabel(""); p.setOrderingHint(this.orderingHint); operandPanel.add(p); this.revalidate(); operandPanel.repaint(); parameterPanel=p; return true; } else if(type.equalsIgnoreCase("Subject Identifier")){ operandPanel.removeAll(); StringParameterPanel p=new StringParameterPanel(parameter,this.directivePanel); p.setLabel(""); p.setOrderingHint(this.orderingHint); operandPanel.add(p); this.revalidate(); operandPanel.repaint(); parameterPanel=p; return true; } else return false; } }
3,122
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
StringParameterPanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/queryeditorpanel/StringParameterPanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.queryeditorpanel; import org.wandora.query2.DirectiveUIHints.Parameter; /** * * @author olli */ public class StringParameterPanel extends AbstractTypePanel { private static final long serialVersionUID = 1L; /** * Creates new form StringParameterPanel */ public StringParameterPanel(Parameter parameter,DirectivePanel panel) { super(parameter,panel); initComponents(); } @Override public void setValue(Object o){ if(o==null) valueTextField.setText(""); else valueTextField.setText(o.toString()); } @Override public Object getValue(){ return valueTextField.getText(); } @Override public String getValueScript(){ String s=valueTextField.getText().trim(); return "\""+(s.replace("\\","\\\\").replace("\"","\\\""))+"\""; } public void setLabel(String label){ parameterLabel.setText(label); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; parameterLabel = new javax.swing.JLabel(); valueTextField = new javax.swing.JTextField(); setLayout(new java.awt.GridBagLayout()); parameterLabel.setText("Label"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5); add(parameterLabel, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; add(valueTextField, gridBagConstraints); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel parameterLabel; private javax.swing.JTextField valueTextField; // End of variables declaration//GEN-END:variables }
3,110
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
DnDTools.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/queryeditorpanel/DnDTools.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.queryeditorpanel; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; import java.awt.datatransfer.UnsupportedFlavorException; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.IOException; import javax.swing.JComponent; import javax.swing.TransferHandler; import org.wandora.query2.DirectiveUIHints; /** * * @author olli */ public class DnDTools { public static class ChainedTransferHandler extends TransferHandler { private static final long serialVersionUID = 1L; protected ChainedTransferHandler next; public ChainedTransferHandler(){ } public ChainedTransferHandler(ChainedTransferHandler next){ this.next=next; } public ChainedTransferHandler(ChainedTransferHandler next,String property){ super(property); this.next=next; } public boolean chainCanImport(TransferHandler.TransferSupport support){return false;} @Override public boolean canImport(TransferHandler.TransferSupport support) { if(chainCanImport(support)) return true; else if(next!=null) return next.canImport(support); else return super.canImport(support); } public boolean chainImportData(TransferHandler.TransferSupport support){return false;} @Override public boolean importData(TransferHandler.TransferSupport support) { if(chainImportData(support)) return true; else if(next!=null) return next.importData(support); else return super.importData(support); } @Override protected Transferable createTransferable(JComponent c) { if(next!=null) return next.createTransferable(c); else return super.createTransferable(c); } @Override public int getSourceActions(JComponent c) { if(next!=null) return next.getSourceActions(c); else return super.getSourceActions(c); } } public static <K> void addDropTargetHandler(final JComponent component,final DataFlavor flavor,final DropTargetCallback<K> callback){ final TransferHandler old=component.getTransferHandler(); if(old!=null && !(old instanceof ChainedTransferHandler)){ throw new RuntimeException("Tried to chain transfer handlers but existing handler is not a chained version."); } component.setTransferHandler(new ChainedTransferHandler((ChainedTransferHandler)old){ @Override public boolean chainCanImport(TransferHandler.TransferSupport support) { return support.isDataFlavorSupported(flavor); } @Override public boolean chainImportData(TransferHandler.TransferSupport support) { if(!chainCanImport(support)) return false; Transferable t=support.getTransferable(); try{ Object data=t.getTransferData(flavor); K cast=(K)data; return callback.callback(component, cast, support); } catch(UnsupportedFlavorException | IOException e){return false;} } }); } public static <K> void setDragSourceHandler(final JComponent component,final String property, final WrapperDataFlavor<K> dataFlavor,final DragSourceCallback<K> callback){ final TransferHandler old=component.getTransferHandler(); if(old!=null && !(old instanceof ChainedTransferHandler)){ throw new RuntimeException("Tried to chain transfer handlers but existing handler is not a chained version."); } component.setTransferHandler(new ChainedTransferHandler((ChainedTransferHandler)old,property){ @Override protected Transferable createTransferable(JComponent c) { K wrapped=callback.callback(component); if(wrapped!=null) return makeTransferable(dataFlavor, wrapped); else return super.createTransferable(c); } @Override public int getSourceActions(JComponent c) { return TransferHandler.COPY|super.getSourceActions(c); } }); component.addMouseListener(new MouseAdapter(){ @Override public void mousePressed(MouseEvent e) { JComponent comp=(JComponent)e.getSource(); TransferHandler th = comp.getTransferHandler(); th.exportAsDrag(comp, e, TransferHandler.COPY); } }); } public static interface DropTargetCallback<K>{ public boolean callback(JComponent component,K o, TransferHandler.TransferSupport support); } public static interface DragSourceCallback<K>{ public K callback(JComponent component); } public static class WrapperDataFlavor<K> extends DataFlavor { private final Class<K> cls; public WrapperDataFlavor(String mimeType,Class<K> cls) throws ClassNotFoundException { super(mimeType); this.cls=cls; } public Class<K> getDataClass(){return cls;} } public static <K> WrapperDataFlavor makeDataFlavor(Class<K> cls){ try{ return new WrapperDataFlavor<>(DataFlavor.javaJVMLocalObjectMimeType+";class="+cls.getName(),cls); }catch(ClassNotFoundException cnfe){ throw new RuntimeException(cnfe); } } public static final WrapperDataFlavor<DirectiveUIHints> directiveHintsDataFlavor=makeDataFlavor(DirectiveUIHints.class); public static final WrapperDataFlavor<DirectivePanel> directivePanelDataFlavor=makeDataFlavor(DirectivePanel.class); public static class WrapperTransferable<K> implements Transferable { private final K wrapped; private final WrapperDataFlavor<K> dataFlavor; public WrapperTransferable(WrapperDataFlavor<K> dataFlavor,K wrapped){ this.dataFlavor=dataFlavor; this.wrapped=wrapped; } @Override public DataFlavor[] getTransferDataFlavors() { return new DataFlavor[]{dataFlavor}; } @Override public boolean isDataFlavorSupported(DataFlavor flavor) { return flavor.equals(dataFlavor); } @Override public K getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { if(flavor.equals(dataFlavor)) return wrapped; else throw new UnsupportedFlavorException(flavor); } } public static <K> WrapperTransferable<K> makeTransferable(WrapperDataFlavor<K> dataFlavor,K wrapped){ return new WrapperTransferable<>(dataFlavor,wrapped); } public static WrapperTransferable<DirectiveUIHints> makeDirectiveHintsTransferable(DirectiveUIHints hints){ return makeTransferable(directiveHintsDataFlavor,hints); } public static WrapperTransferable<DirectivePanel> makeDirectivePanelTransferable(DirectivePanel directivePanel){ return makeTransferable(directivePanelDataFlavor,directivePanel); } }
8,204
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
ComponentConnectorAnchor.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/queryeditorpanel/ComponentConnectorAnchor.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.queryeditorpanel; import java.awt.Container; import java.awt.Point; import javax.swing.JComponent; /** * * @author olli */ public class ComponentConnectorAnchor extends ConnectorAnchor { protected JComponent component; protected Direction exitDirection; public ComponentConnectorAnchor(JComponent component,Direction exitDirection){ this.component=component; this.exitDirection=exitDirection; } public ComponentConnectorAnchor(JComponent component,Direction exitDirection,boolean hasFrom,boolean hasTo){ this(component,exitDirection); this.hasFromAnchor=hasFrom; this.hasToAnchor=hasTo; } @Override public JComponent getComponent(){ return this.component; } @Override public JComponent getRootComponent() { return findEditor().getGraphPanel(); } @Override public QueryEditorComponent getEditor(){ return findEditor(); } public DirectivePanel findDirectivePanel(){ Container parent=getComponent().getParent(); while(parent!=null && !(parent instanceof DirectivePanel)){ parent=parent.getParent(); } if(parent!=null) return (DirectivePanel)parent; else return null; } protected QueryEditorComponent findEditor(){ Container parent=getComponent().getParent(); while(parent!=null && !(parent instanceof QueryEditorComponent)){ parent=parent.getParent(); } if(parent!=null) return (QueryEditorComponent)parent; else return null; } @Override public Point getAnchorPoint(){ switch(exitDirection){ case UP: return new Point(this.component.getWidth()/2,0); case RIGHT: return new Point(this.component.getWidth(),this.component.getHeight()/2); case DOWN: return new Point(this.component.getWidth()/2,this.component.getHeight()); case LEFT: return new Point(0,this.component.getHeight()/2); } // shouldn't happen return new Point(0,0); } @Override public Direction getExitDirection(){ return exitDirection; } }
3,111
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
OperandParameterPanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/queryeditorpanel/OperandParameterPanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.queryeditorpanel; import java.awt.Component; import org.wandora.query2.DirectiveUIHints.Parameter; /** * * @author olli */ public class OperandParameterPanel extends AbstractTypePanel { private static final long serialVersionUID = 1L; protected AbstractTypePanel parameterPanel; /** * Creates new form OperandParameterPanel */ public OperandParameterPanel(Parameter parameter,DirectivePanel panel) { super(parameter,panel); initComponents(); setOperandTypes(); } @Override public void disconnect() { super.disconnect(); for(Component c : operandPanel.getComponents()){ if(c instanceof AbstractTypePanel) ((AbstractTypePanel)c).disconnect(); } } @Override public void setValue(Object o){ /*if(o instanceof Directive){ operandTypeComboBox.setSelectedItem("Directive"); operandTypeChanged(); parameterPanel.setValue(o); }*/ if(o instanceof DirectivePanel){ operandTypeComboBox.setSelectedItem("Directive"); operandTypeChanged(); parameterPanel.setValue(o); } else if(o instanceof String){ operandTypeComboBox.setSelectedItem("String"); operandTypeChanged(); parameterPanel.setValue(o); } } @Override public Object getValue(){ if(parameterPanel==null) return null; return parameterPanel.getValue(); } @Override public String getValueScript(){ if(parameterPanel==null) return "null"; return parameterPanel.getValueScript(); } @Override public void setLabel(String label){ parameterLabel.setText(label); } protected void setOperandTypes(){ operandTypeComboBox.addItem("String"); operandTypeComboBox.addItem("Directive"); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; parameterLabel = new javax.swing.JLabel(); operandTypeComboBox = new javax.swing.JComboBox(); operandPanel = new javax.swing.JPanel(); setLayout(new java.awt.GridBagLayout()); parameterLabel.setText("Label"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 6); add(parameterLabel, gridBagConstraints); operandTypeComboBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { operandTypeComboBoxActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5); add(operandTypeComboBox, gridBagConstraints); operandPanel.setLayout(new javax.swing.BoxLayout(operandPanel, javax.swing.BoxLayout.LINE_AXIS)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.gridwidth = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.FIRST_LINE_START; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 5); add(operandPanel, gridBagConstraints); }// </editor-fold>//GEN-END:initComponents protected boolean operandTypeChanged(){ if(parameterPanel!=null) parameterPanel.disconnect(); parameterPanel=null; Object o=operandTypeComboBox.getSelectedItem(); if(o==null){ operandPanel.removeAll(); this.revalidate(); operandPanel.repaint(); return true; } String type=o.toString(); if(type.equalsIgnoreCase("String")){ operandPanel.removeAll(); StringParameterPanel p=new StringParameterPanel(parameter,this.directivePanel); p.setLabel(""); p.setOrderingHint(this.orderingHint); operandPanel.add(p); this.revalidate(); operandPanel.repaint(); parameterPanel=p; return true; } else if(type.equalsIgnoreCase("Directive")){ operandPanel.removeAll(); DirectiveParameterPanel p=new DirectiveParameterPanel(parameter,this.directivePanel); p.setLabel(""); p.setOrderingHint(this.orderingHint); operandPanel.add(p); this.revalidate(); operandPanel.repaint(); parameterPanel=p; return true; } else return false; } @Override public void setOrderingHint(String orderingHint) { super.setOrderingHint(orderingHint); //To change body of generated methods, choose Tools | Templates. if(this.parameterPanel!=null) this.parameterPanel.setOrderingHint(orderingHint); } private void operandTypeComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_operandTypeComboBoxActionPerformed operandTypeChanged(); }//GEN-LAST:event_operandTypeComboBoxActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables protected javax.swing.JPanel operandPanel; protected javax.swing.JComboBox operandTypeComboBox; private javax.swing.JLabel parameterLabel; // End of variables declaration//GEN-END:variables }
6,884
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
IntegerParameterPanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/queryeditorpanel/IntegerParameterPanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.queryeditorpanel; import org.wandora.query2.DirectiveUIHints.Parameter; /** * * @author olli */ public class IntegerParameterPanel extends AbstractTypePanel { private static final long serialVersionUID = 1L; /** * Creates new form StringParameterPanel */ public IntegerParameterPanel(Parameter parameter,DirectivePanel panel) { super(parameter,panel); initComponents(); } @Override public void setLabel(String label){ parameterLabel.setText(label); } @Override public void setValue(Object o){ valueSpinner.setValue(o); } @Override public Object getValue(){ return valueSpinner.getValue(); } @Override public String getValueScript(){ return getValue().toString(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; parameterLabel = new javax.swing.JLabel(); valueSpinner = new javax.swing.JSpinner(); setLayout(new java.awt.GridBagLayout()); parameterLabel.setText("Label"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5); add(parameterLabel, gridBagConstraints); valueSpinner.setPreferredSize(new java.awt.Dimension(100, 28)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; gridBagConstraints.weightx = 1.0; add(valueSpinner, gridBagConstraints); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel parameterLabel; private javax.swing.JSpinner valueSpinner; // End of variables declaration//GEN-END:variables }
3,038
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
ConnectorAnchor.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/queryeditorpanel/ConnectorAnchor.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.queryeditorpanel; import java.awt.Point; import javax.swing.JComponent; /** * * @author olli */ public abstract class ConnectorAnchor { protected boolean hasFromAnchor=false; protected boolean hasToAnchor=false; protected ConnectorAnchor to; protected ConnectorAnchor from; protected Connector toConnector; protected Connector fromConnector; public static boolean setLink(QueryEditorComponent editor,ConnectorAnchor from,ConnectorAnchor to){ // Things are nulled seemingly unnecessarily because the recursive calls // would otherwise cause infinite recursion. Nulling them acts as a // marker that we've done that anchor already. if(from==null || from.to!=to){ if(from!=null){ if(from.toConnector!=null){ editor.removeConnector(from.getToConnector()); from.toConnector=null; } ConnectorAnchor old=from.to; from.to=null; if(old!=null) old.setFrom(null); from.to=to; } if(to!=null){ if(to.fromConnector!=null){ editor.removeConnector(to.fromConnector); to.fromConnector=null; } ConnectorAnchor old=to.from; to.from=null; if(old!=null) old.setTo(null); to.from=from; if(from!=null){ from.toConnector=new Connector(from.getRootComponent(), from, to); to.fromConnector=from.toConnector; editor.addConnector(from.toConnector); } } } return true; } public ConnectorAnchor getFrom(){return from;} public ConnectorAnchor getTo(){return to;} public Connector getFromConnector(){return fromConnector;} public Connector getToConnector(){return toConnector;} public boolean setTo(ConnectorAnchor to){ if(!this.hasToAnchor()) return false; return setLink(getEditor(), this, to); } public boolean setFrom(ConnectorAnchor from){ if(!this.hasFromAnchor()) return false; return setLink(getEditor(), from, this); } public boolean hasFromAnchor(){return hasFromAnchor;} public boolean hasToAnchor(){return hasToAnchor;} public abstract QueryEditorComponent getEditor(); public abstract Point getAnchorPoint(); public abstract JComponent getComponent(); public abstract JComponent getRootComponent(); public Direction getExitDirection(){ return Direction.RIGHT; } public static enum Direction { UP, RIGHT, DOWN, LEFT; } }
3,658
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
QueryLibraryPanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/queryeditorpanel/QueryLibraryPanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.queryeditorpanel; import java.awt.Container; import java.awt.event.ActionEvent; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import javax.swing.DefaultListModel; import javax.swing.JComponent; import javax.swing.ListModel; import org.wandora.application.Wandora; import org.wandora.application.gui.UIBox; import org.wandora.application.gui.WandoraOptionPane; import org.wandora.application.gui.topicpanels.queryeditorpanel.DirectiveEditor.DirectiveParameters; import org.wandora.utils.JsonMapper; import org.wandora.utils.Options; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.ObjectMapper; /** * * @author olli */ public class QueryLibraryPanel extends javax.swing.JPanel { private static final long serialVersionUID = 1L; protected String openedName; protected final ArrayList<StoredQuery> storedQueries=new ArrayList<StoredQuery>(); public static class StoredQueries { public StoredQuery[] queries; public StoredQueries(){} public StoredQueries(StoredQuery[] queries){this.queries=queries;} public StoredQueries(ArrayList<StoredQuery> queries){this.queries=queries.toArray(new StoredQuery[queries.size()]);} @JsonIgnore public StoredQueries duplicate(){ StoredQueries ret=new StoredQueries(); ret.queries=new StoredQuery[queries.length]; for(int i=0;i<queries.length;i++){ ret.queries[i]=queries[i].duplicate(); } return ret; } } public static class StoredQuery { public String name; public ArrayList<DirectiveParameters> directiveParameters; public String rootDirective; public StoredQuery() { } public StoredQuery(String name, ArrayList<DirectiveParameters> directiveParameters, String rootDirective) { this.name = name; this.directiveParameters = directiveParameters; this.rootDirective = rootDirective; } @Override public String toString(){return name;} @JsonIgnore public DirectiveParameters getRootParameters(){ for(DirectiveParameters p : directiveParameters){ if(p.id!=null && p.id.equals(rootDirective)) return p; } return null; } @JsonIgnore public StoredQuery duplicate(){ ArrayList<DirectiveParameters> newParams=new ArrayList<>(); for(DirectiveParameters p : directiveParameters) newParams.add(p.duplicate()); return new StoredQuery(name,newParams,rootDirective); } } /** * Creates new form QueryLibraryPanel */ public QueryLibraryPanel() { initComponents(); Object[] buttonStruct = { "Open", UIBox.getIcon(0xF07C), new java.awt.event.ActionListener(){ @Override public void actionPerformed(ActionEvent e) { openClicked(); } }, "Save", UIBox.getIcon(0xF0C7), new java.awt.event.ActionListener(){ @Override public void actionPerformed(ActionEvent e) { saveClicked(); } }, "Delete", UIBox.getIcon(0xF014), new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { deleteClicked(); } } }; JComponent buttonContainer = UIBox.makeButtonContainer(buttonStruct, Wandora.getWandora()); buttonPanel.add(buttonContainer); readQueries(Wandora.getWandora().getOptions()); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; toolBar = new javax.swing.JToolBar(); buttonPanel = new javax.swing.JPanel(); fillerPanel = new javax.swing.JPanel(); innerFillerPanel = new javax.swing.JPanel(); jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); nameField = new javax.swing.JTextField(); jScrollPane2 = new javax.swing.JScrollPane(); queryList = new javax.swing.JList(); setLayout(new java.awt.GridBagLayout()); toolBar.setFloatable(false); toolBar.setRollover(true); buttonPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 0)); toolBar.add(buttonPanel); fillerPanel.setLayout(new java.awt.GridBagLayout()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; fillerPanel.add(innerFillerPanel, gridBagConstraints); toolBar.add(fillerPanel); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; add(toolBar, gridBagConstraints); jPanel1.setLayout(new java.awt.GridBagLayout()); jLabel1.setText("Query name"); jPanel1.add(jLabel1, new java.awt.GridBagConstraints()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; jPanel1.add(nameField, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; add(jPanel1, gridBagConstraints); queryList.setModel(new DefaultListModel()); jScrollPane2.setViewportView(queryList); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; add(jScrollPane2, gridBagConstraints); }// </editor-fold>//GEN-END:initComponents public QueryEditorComponent findGraph(){ Container c=this; while(c!=null && !(c instanceof QueryEditorDockPanel)){ c=c.getParent(); } if(c==null) return null; return ((QueryEditorDockPanel)c).getQueryEditor(); } public void readQueries(Options options){ StoredQuery[] queries=null; String queriesJson=options.get(OPTIONS_KEY); if(queriesJson!=null){ ObjectMapper objectMapper=new ObjectMapper(); try{ StoredQueries wrapper=(StoredQueries)objectMapper.readValue(queriesJson,StoredQueries.class); queries=wrapper.queries; } catch(IOException ioe){Wandora.getWandora().handleError(ioe);} } else queries=new StoredQuery[0]; if(queries!=null){ synchronized(storedQueries){ storedQueries.clear(); storedQueries.addAll(Arrays.asList(queries)); DefaultListModel model=(DefaultListModel)queryList.getModel(); model.clear(); for(StoredQuery q : storedQueries){ model.addElement(q); } } } } private static final String OPTIONS_KEY="options.queryeditor.storedqueries"; public void writeQueries(Options options){ JsonMapper mapper=new JsonMapper(); String json=null; synchronized(storedQueries){ json=mapper.writeValue(new StoredQueries(storedQueries)); } options.put(OPTIONS_KEY,json); } public void save(String name){ QueryEditorComponent graph=findGraph(); StoredQuery query=graph.getStoredQuery(); if(query==null) return; query.name=name; // cycle through serialisation and deserialisation to make everything consistent ObjectMapper objectMapper=new ObjectMapper(); JsonMapper jsonMapper=new JsonMapper(); String json=jsonMapper.writeValue(query); try{ query=objectMapper.readValue(json, StoredQuery.class); } catch(IOException e){Wandora.getWandora().handleError(e); return;} synchronized(storedQueries){ boolean saved=false; for(int i=0;i<storedQueries.size();i++){ StoredQuery q=storedQueries.get(i); if(q.name!=null && q.name.equals(name)){ saved=true; storedQueries.set(i, query); break; } } if(!saved){ storedQueries.add(query); DefaultListModel model=(DefaultListModel)queryList.getModel(); model.addElement(query); } } writeQueries(Wandora.getWandora().getOptions()); } public void openQuery(StoredQuery query){ nameField.setText(query.name); QueryEditorComponent graph=findGraph(); graph.clearQuery(); graph.openStoredQuery(query.duplicate()); } public void open(String name){ synchronized(storedQueries) { for(StoredQuery q : storedQueries){ if(q.name.equals(name)){ openQuery(q); return; } } WandoraOptionPane.showMessageDialog(Wandora.getWandora(), "Query not found."); } } public void deleteClicked(){ Object o=queryList.getSelectedValue(); if(o==null) return; String openName=o.toString(); if(WandoraOptionPane.showConfirmDialog(Wandora.getWandora(), "Do you want to delete query "+openName) == WandoraOptionPane.YES_OPTION ){ synchronized(storedQueries) { for(StoredQuery q : storedQueries){ if(q.name.equals(openName)){ storedQueries.remove(q); DefaultListModel model=(DefaultListModel)queryList.getModel(); model.removeElement(o); writeQueries(Wandora.getWandora().getOptions()); break; } } } } } public void saveClicked(){ String name=nameField.getText().trim(); if(name.length()==0){ WandoraOptionPane.showMessageDialog(Wandora.getWandora(), "Name is empty."); return; } else { ListModel listModel=queryList.getModel(); for(int i=0;i<listModel.getSize();i++){ Object o=listModel.getElementAt(i); if(name.equals(o)){ if(openedName==null || !openedName.equals(name)){ // TODO: confirm overwrite } break; } } } openedName=name; save(name); } public void openClicked(){ // TODO: save confirm? Object o=queryList.getSelectedValue(); if(o==null) return; openedName=o.toString(); open(openedName); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel buttonPanel; private javax.swing.JPanel fillerPanel; private javax.swing.JPanel innerFillerPanel; private javax.swing.JLabel jLabel1; private javax.swing.JPanel jPanel1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTextField nameField; private javax.swing.JList queryList; private javax.swing.JToolBar toolBar; // End of variables declaration//GEN-END:variables }
13,543
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
Connector.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/queryeditorpanel/Connector.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.queryeditorpanel; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Container; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; import java.awt.geom.Path2D; import javax.swing.JComponent; /** * * @author olli */ public class Connector { protected ConnectorAnchor from; protected ConnectorAnchor to; protected JComponent root; public Connector(JComponent root,ConnectorAnchor from,ConnectorAnchor to){ this.root=root; this.from=from; this.to=to; } protected Point getRootCoordinates(JComponent c,int x,int y){ Container co=c; Point d=new Point(x,y); while(co!=null && co!=root){ Rectangle rect=co.getBounds(); d.setLocation(d.getX()+rect.x, d.getY()+rect.y); co=co.getParent(); } return d; } protected Point clampPoint(Point p,JComponent c,int margin,ConnectorAnchor anchor){ Point cp=getRootCoordinates(c,0,0); Rectangle rect=c.getBounds(); int w=rect.width; int h=rect.height; switch(anchor.getExitDirection()){ case LEFT: return new Point(cp.x,Math.max(cp.y+margin, Math.min(cp.y+h-margin,p.y))); case RIGHT: return new Point(cp.x+w,Math.max(cp.y+margin, Math.min(cp.y+h-margin,p.y))); case UP: return new Point(Math.max(cp.x+margin, Math.min(cp.x+w-margin,p.x)),cp.y); case DOWN: return new Point(Math.max(cp.x+margin, Math.min(cp.x+w-margin,p.x)),cp.y+h); default: throw new RuntimeException("unknown exit direction"); // shouldn't happen, case for all possible directions } } protected Point getAnchorCoordinates(ConnectorAnchor anchor){ Point p=anchor.getAnchorPoint(); Point rp=getRootCoordinates(anchor.getComponent(),p.x,p.y); if(anchor instanceof ComponentConnectorAnchor){ DirectivePanel dp=((ComponentConnectorAnchor)anchor).findDirectivePanel(); if(dp!=null) rp=clampPoint(rp,dp,10,anchor); } return rp; } public Rectangle getBoundingBox(){ Point f=getAnchorCoordinates(from); Point t=getAnchorCoordinates(to); int x=Math.min(f.x, t.x); int y=Math.min(f.y, t.y); int w=Math.abs(f.x-t.x); int h=Math.abs(f.y-t.y); return new Rectangle(x, y, w, h); } protected LineSegment[] rotateIcon(LineSegment[] icon,double angle){ double ca=Math.cos(angle); double sa=Math.sin(angle); LineSegment[] ret=new LineSegment[icon.length]; for(int i=0;i<icon.length;i++){ LineSegment line=icon[i]; Point p1=new Point((int)Math.round(line.p1.x*ca-line.p1.y*sa), (int)Math.round(line.p1.x*sa+line.p1.y*ca)); Point p2=new Point((int)Math.round(line.p2.x*ca-line.p2.y*sa), (int)Math.round(line.p2.x*sa+line.p2.y*ca)); ret[i]=new LineSegment(p1,p2); } return ret; } protected void drawIcon(Graphics2D g2,LineSegment[] icon,Point offset){ for(LineSegment line : icon){ g2.drawLine(line.p1.x+offset.x, line.p1.y+offset.y, line.p2.x+offset.x, line.p2.y+offset.y); } } public static class LineSegment { public Point p1; public Point p2; public LineSegment(){} public LineSegment(Point p1,Point p2){this.p1=p1; this.p2=p2;} } public static final LineSegment[] arrowIcon=new LineSegment[]{ new LineSegment(new Point(-10,-10),new Point(0,0)), new LineSegment(new Point(-10, 10),new Point(0,0)) }; protected Point paintExit(Graphics2D g2,ConnectorAnchor anchor,boolean in){ Point p=getAnchorCoordinates(anchor); Point exitPoint=null; switch(anchor.getExitDirection()){ case LEFT: exitPoint=new Point(p.x-20,p.y); if(in) drawIcon(g2,arrowIcon,p); break; case RIGHT: exitPoint=new Point(p.x+20,p.y); if(in) drawIcon(g2,rotateIcon(arrowIcon,Math.PI),p); break; case UP: exitPoint=new Point(p.x,p.y-20); if(in) drawIcon(g2,rotateIcon(arrowIcon,Math.PI/2),p); break; case DOWN: exitPoint=new Point(p.x,p.y+20); if(in) drawIcon(g2,rotateIcon(arrowIcon,-Math.PI/2),p); break; } g2.drawLine(p.x,p.y,exitPoint.x,exitPoint.y); return exitPoint; } public void repaint(Graphics g){ Graphics2D g2=(Graphics2D)g; g2.setStroke(new BasicStroke(2)); g2.setColor(Color.BLACK); Point f=paintExit(g2,from,false); Point t=paintExit(g2,to,true); // g2.drawLine(f.x, f.y, t.x, t.y); Point f0=getAnchorCoordinates(from); Point t0=getAnchorCoordinates(to); double b=5; int dx=t.x-f.x; int dy=t.y-f.y; int l2=dx*dx+dy*dy; if(l2<40000){ double l=Math.sqrt(l2); b=l/2.0/20.0; } Path2D.Double curve=new Path2D.Double(); curve.moveTo(f.x, f.y); curve.curveTo(f.x+(f.x-f0.x)*b, f.y+(f.y-f0.y)*b, t.x+(t.x-t0.x)*b, t.y+(t.y-t0.y)*b, t.x, t.y); g2.draw(curve); } }
6,593
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
DirectivesListPanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/queryeditorpanel/DirectivesListPanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.queryeditorpanel; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import javax.swing.JComponent; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; import org.wandora.query2.Directive; import org.wandora.query2.DirectiveManager; import org.wandora.query2.DirectiveUIHints; /** * * @author olli */ public class DirectivesListPanel extends javax.swing.JPanel { private static final long serialVersionUID = 1L; /** * Creates new form DirectivesListPanel */ public DirectivesListPanel() { initComponents(); populateDirectiveList(); directivesTree.setTransferHandler(null); DnDTools.setDragSourceHandler(directivesTree, "directiveHints", DnDTools.directiveHintsDataFlavor, new DnDTools.DragSourceCallback<DirectiveUIHints>() { @Override public DirectiveUIHints callback(JComponent component) { JTree tree=(JTree)component; TreePath path=tree.getSelectionPath(); if(path==null) return null; DefaultMutableTreeNode n=(DefaultMutableTreeNode)path.getLastPathComponent(); Object o=n.getUserObject(); if(o instanceof DirectiveUIHints){ return (DirectiveUIHints)o; } else return null; } }); } protected void populateDirectiveList(){ DefaultTreeModel treeModel=(DefaultTreeModel)directivesTree.getModel(); DefaultMutableTreeNode root=new DefaultMutableTreeNode("Directives"); DefaultMutableTreeNode other=new DefaultMutableTreeNode("Other"); DirectiveManager directiveManager=DirectiveManager.getDirectiveManager(); List<Class<? extends Directive>> directives=directiveManager.getDirectives(); List<DirectiveUIHints> hints=new ArrayList<>(); for(Class<? extends Directive> dir : directives){ DirectiveUIHints h=DirectiveUIHints.getDirectiveUIHints(dir); hints.add(h); } Collections.sort(hints,new Comparator<DirectiveUIHints>(){ @Override public int compare(DirectiveUIHints o1, DirectiveUIHints o2) { String l1=o1.getLabel(); String l2=o2.getLabel(); if(l1==null && l2!=null) return -1; else if(l1!=null && l2==null) return 1; else if(l1==null && l2==null) return 0; else return l1.compareTo(l2); } }); ArrayList<DefaultMutableTreeNode> categoryNodes=new ArrayList<>(); categoryNodes.add(other); for(DirectiveUIHints h: hints){ boolean added=false; String categoryAll=h.getCategory(); if(categoryAll==null) categoryAll=""; String[] categories=categoryAll.split(";"); for(String category : categories){ DefaultMutableTreeNode parent=null; if(category!=null && category.trim().length()>0) { category=category.trim(); if(!category.equalsIgnoreCase("Other")) { for(DefaultMutableTreeNode n : categoryNodes ){ String name=n.toString(); if(name!=null && name.equalsIgnoreCase(category)) { parent=n; break; } } if(parent==null){ parent=new DefaultMutableTreeNode(category); categoryNodes.add(parent); } } } if(parent!=null){ DefaultMutableTreeNode node=new DefaultMutableTreeNode(h); parent.add(node); added=true; } } if(!added){ DefaultMutableTreeNode node=new DefaultMutableTreeNode(h); other.add(node); } } Collections.sort(categoryNodes,new Comparator<DefaultMutableTreeNode>(){ @Override public int compare(DefaultMutableTreeNode o1, DefaultMutableTreeNode o2) { return o1.toString().compareTo(o2.toString()); } }); for(DefaultMutableTreeNode n: categoryNodes) { root.add(n); } treeModel.setRoot(root); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jScrollPane2 = new javax.swing.JScrollPane(); directivesTree = new javax.swing.JTree(); setLayout(new java.awt.BorderLayout()); javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("Directives"); directivesTree.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1)); jScrollPane2.setViewportView(directivesTree); add(jScrollPane2, java.awt.BorderLayout.CENTER); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JTree directivesTree; private javax.swing.JScrollPane jScrollPane2; // End of variables declaration//GEN-END:variables }
6,788
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
MultipleParameterPanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/queryeditorpanel/MultipleParameterPanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.queryeditorpanel; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import javax.swing.JButton; import org.wandora.application.Wandora; import org.wandora.query2.DirectiveUIHints.Parameter; /** * * @author olli */ public class MultipleParameterPanel extends AbstractTypePanel { private static final long serialVersionUID = 1L; protected Class<? extends AbstractTypePanel> typeCls; protected final ArrayList<Row> rows=new ArrayList<Row>(); protected static class Row { public AbstractTypePanel panel; public JButton removeButton; public Row(AbstractTypePanel panel, JButton removeButton) { this.panel = panel; this.removeButton = removeButton; } public Row(){} } /** * Creates new form MultipleParameterPanel */ public MultipleParameterPanel(Parameter parameter,Class<? extends AbstractTypePanel> typeCls,DirectivePanel panel) { super(parameter,panel); initComponents(); this.typeCls=typeCls; } @Override public synchronized void setValue(Object o){ for(Row row : rows){ row.panel.disconnect(); } parametersPanel.removeAll(); rows.clear(); if(o!=null){ Object[] a=(Object[])o; for (Object ao : a) { addParameter(); Row row=rows.get(rows.size()-1); row.panel.setValue(ao); } } } @Override public Object getValue() { Object[] ret=new Object[rows.size()]; for(int i=0;i<rows.size();i++){ Row row=rows.get(i); ret[i]=row.panel.getValue(); } return ret; } @Override public String getValueScript() { StringBuilder sb=new StringBuilder(); sb.append("new "); sb.append(parameter.getType().getSimpleName()); sb.append("[]{"); boolean first=true; for(Row row : rows){ if(!first) sb.append(", "); else first=false; sb.append(row.panel.getValueScript()); } sb.append("}"); return sb.toString(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; parameterLabel = new javax.swing.JLabel(); addButton = new javax.swing.JButton(); parametersPanel = new javax.swing.JPanel(); setBorder(null); setLayout(new java.awt.GridBagLayout()); parameterLabel.setText("Label"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; gridBagConstraints.weightx = 1.0; add(parameterLabel, gridBagConstraints); addButton.setText("Add"); addButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { addButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END; gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 5); add(addButton, gridBagConstraints); parametersPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder()); parametersPanel.setLayout(new java.awt.GridBagLayout()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.gridwidth = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.ipadx = 5; gridBagConstraints.ipady = 5; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(5, 0, 5, 5); add(parametersPanel, gridBagConstraints); }// </editor-fold>//GEN-END:initComponents private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed addParameter(); }//GEN-LAST:event_addButtonActionPerformed public synchronized void addParameter(){ final AbstractTypePanel paramPanel; try{ Constructor c=typeCls.getConstructor(Parameter.class,DirectivePanel.class); paramPanel=(AbstractTypePanel)c.newInstance(this.parameter,this.directivePanel); }catch(IllegalAccessException | InstantiationException | NoSuchMethodException | IllegalArgumentException | InvocationTargetException | SecurityException e){ Wandora.getWandora().handleError(e); return; } GridBagConstraints gbc=new GridBagConstraints(); gbc.gridx=0; gbc.gridy=rows.size(); gbc.insets=new Insets(5, 5, 0, 5); JButton removeButton=new JButton(); removeButton.setText("X"); removeButton.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e) { removeParameter(paramPanel); } }); parametersPanel.add(removeButton,gbc); gbc.gridx=1; gbc.weightx=1.0; gbc.fill=GridBagConstraints.HORIZONTAL; paramPanel.setLabel(""); parametersPanel.add(paramPanel,gbc); if(this.orderingHint!=null) { paramPanel.setOrderingHint(orderingHint+rows.size()); } this.revalidate(); parametersPanel.repaint(); rows.add(new Row(paramPanel, removeButton)); } public synchronized void removeParameter(int index){ GridBagLayout layout=(GridBagLayout)parametersPanel.getLayout(); Row row=rows.get(index); row.panel.disconnect(); parametersPanel.remove(row.panel); parametersPanel.remove(row.removeButton); rows.remove(index); for(int i=index;i<rows.size();i++){ row=rows.get(i); GridBagConstraints gbc=layout.getConstraints(row.panel); gbc.gridy--; layout.setConstraints(row.panel, gbc); gbc=layout.getConstraints(row.removeButton); gbc.gridy--; layout.setConstraints(row.removeButton, gbc); if(this.orderingHint!=null) row.panel.setOrderingHint(this.orderingHint+i); } this.revalidate(); parametersPanel.repaint(); } @Override public void setOrderingHint(String orderingHint) { super.setOrderingHint(orderingHint); for(int i=0;i<rows.size();i++){ Row row=rows.get(i); if(this.orderingHint!=null) row.panel.setOrderingHint(this.orderingHint+i); else row.panel.setOrderingHint(null); } } public synchronized void removeParameter(AbstractTypePanel panel){ for(int i=0;i<rows.size();i++){ if(rows.get(i).panel==panel) { removeParameter(i); break; } } } @Override public void setLabel(String label){ parameterLabel.setText(label); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton addButton; private javax.swing.JLabel parameterLabel; private javax.swing.JPanel parametersPanel; // End of variables declaration//GEN-END:variables }
9,139
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
DirectiveEditor.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/queryeditorpanel/DirectiveEditor.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * */ package org.wandora.application.gui.topicpanels.queryeditorpanel; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.Rectangle; import java.lang.reflect.Array; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Map; import java.util.Objects; import javax.swing.JPanel; import org.wandora.application.Wandora; import org.wandora.query2.Directive; import org.wandora.query2.DirectiveUIHints; import org.wandora.query2.DirectiveUIHints.Addon; import org.wandora.query2.DirectiveUIHints.Constructor; import org.wandora.query2.DirectiveUIHints.Parameter; import org.wandora.query2.Operand; import org.wandora.query2.TopicOperand; import org.wandora.topicmap.Topic; import org.wandora.topicmap.TopicMapException; import com.fasterxml.jackson.annotation.JsonIgnore; /** * * @author olli */ public class DirectiveEditor extends javax.swing.JPanel { private static final long serialVersionUID = 1L; protected DirectiveUIHints.Constructor selectedConstructor; protected AbstractTypePanel[] constructorParamPanels; protected final ArrayList<AddonPanel> addonPanels=new ArrayList<AddonPanel>(); protected DirectivePanel directivePanel; protected DirectiveUIHints hints; /** * Creates new form DirectiveEditor */ public DirectiveEditor(DirectivePanel directivePanel,DirectiveUIHints hints) { this.directivePanel=directivePanel; initComponents(); setDirective(hints); setDirectiveParameters(directivePanel.getDirectiveParameters()); } public DirectivePanel getDirectivePanel(){ return directivePanel; } public void setDirective(DirectiveUIHints hints){ this.hints=hints; this.directiveLabel.setText(hints.getLabel()); for(DirectiveUIHints.Constructor c : hints.getConstructors()){ String label="("; boolean first=true; for(DirectiveUIHints.Parameter p : c.getParameters()){ if(!first) label+=","; else first=false; label+=p.getLabel(); } label+=")"; constructorComboBox.addItem(new ConstructorComboItem(c,label)); } constructorComboBox.setMinimumSize(new Dimension(50,constructorComboBox.getMinimumSize().height)); constructorComboBox.setPreferredSize(new Dimension(50,constructorComboBox.getPreferredSize().height)); DirectiveUIHints.Addon[] addons=hints.getAddons(); if(addons!=null){ for(DirectiveUIHints.Addon a : addons) { String label=a.getLabel()+"("; boolean first=true; for(DirectiveUIHints.Parameter p : a.getParameters()){ if(!first) label+=","; else first=false; label+=p.getLabel(); } label+=")"; addonComboBox.addItem(new AddonComboItem(a,label)); } } addonComboBox.setMinimumSize(new Dimension(50,addonComboBox.getMinimumSize().height)); addonComboBox.setPreferredSize(new Dimension(50,addonComboBox.getPreferredSize().height)); } private class ConstructorComboItem { public DirectiveUIHints.Constructor c; public String label; public ConstructorComboItem(DirectiveUIHints.Constructor c,String label){ this.c=c; this.label=label; } @Override public String toString() { return label; } } private class AddonComboItem { public DirectiveUIHints.Addon a; public String label; public AddonComboItem(DirectiveUIHints.Addon a,String label){ this.a=a; this.label=label; } @Override public String toString() { return label; } } public void saveChanges(){ if(directivePanel!=null){ directivePanel.saveDirectiveParameters(getDirectiveParameters()); } } public void setDirectiveParameters(DirectiveParameters params){ if(params==null){ constructorComboBox.setSelectedIndex(0); populateParametersPanel(((ConstructorComboItem)constructorComboBox.getItemAt(0)).c); } else { Constructor c=params.constructor; for(int i=0;i<constructorComboBox.getItemCount();i++){ Object o=constructorComboBox.getItemAt(i); if(o instanceof ConstructorComboItem){ if(((ConstructorComboItem)o).c.equals(c)) { constructorComboBox.setSelectedIndex(i); break; } } } this.selectedConstructor=c; populateParametersPanel(c); for(int i=0;i<constructorParamPanels.length;i++){ AbstractTypePanel panel=constructorParamPanels[i]; Object value=null; if(params.parameters.length>i && params.parameters[i]!=null) value=params.parameters[i].getValue(); panel.setValue(value); } for(AddonParameters ap : params.addons){ Addon addon=ap.addon; for(int i=0;i<addonComboBox.getItemCount();i++){ Object o=addonComboBox.getItemAt(i); if(o instanceof AddonComboItem){ if(((AddonComboItem)o).a.equals(addon)){ AddonPanel addonPanel=addAddon(addon); for(int j=0;j<addonPanel.parameterPanels.length;j++){ AbstractTypePanel valuePanel=addonPanel.parameterPanels[j]; Object value=null; if(j<ap.parameters.length && ap.parameters[j]!=null) { value=ap.parameters[j].value; } valuePanel.setValue(value); } break; } } } } } } public DirectiveParameters getDirectiveParameters(){ Object o=constructorComboBox.getSelectedItem(); if(o==null || !(o instanceof ConstructorComboItem)) return null; Constructor c=((ConstructorComboItem)o).c; BoundParameter[] constructorParams=getParameters(constructorParamPanels); AddonParameters[] addonParams=getAddonParameters(); DirectiveParameters params=new DirectiveParameters(directivePanel.getDirectiveId(),c,constructorParams,addonParams); params.from=directivePanel.getFromPanel(); params.cls=hints.getDirectiveClass().getName(); Rectangle bounds=directivePanel.getBounds(); params.posx=bounds.x; params.posy=bounds.y; return params; } public AddonParameters[] getAddonParameters(){ AddonParameters[] ret=new AddonParameters[addonPanels.size()]; for(int i=0;i<addonPanels.size();i++){ AddonPanel panel=addonPanels.get(i); BoundParameter[] params=getParameters(panel.getParameterPanels()); ret[i]=new AddonParameters(panel.getAddon(), params); } return ret; } public BoundParameter[] getParameters(AbstractTypePanel[] panels){ BoundParameter[] ret=new BoundParameter[panels.length]; for(int i=0;i<panels.length;i++){ AbstractTypePanel paramPanel=panels[i]; String s=paramPanel.getValueScript(); Parameter param=paramPanel.getParameter(); Object value=paramPanel.getValue(); ret[i]=new BoundParameter(param, value); } return ret; } public void setParameters(AbstractTypePanel[] panels, BoundParameter[] values){ for(int i=0;i<panels.length;i++){ AbstractTypePanel paramPanel=panels[i]; paramPanel.setValue(values[i]); } } public static class DirectiveParameters { public String id; public String cls; public Constructor constructor; public BoundParameter[] parameters; public AddonParameters[] addons; public int posx; public int posy; @JsonIgnore public Object from; // this can be a DirectivePanel or the id for the directive public DirectiveParameters(){} public DirectiveParameters(String directiveId,Constructor constructor, BoundParameter[] parameters, AddonParameters[] addons) { this.id=directiveId; this.constructor = constructor; this.parameters = parameters; this.addons = addons; } public Object getFrom() { if(from instanceof DirectivePanel) return ((DirectivePanel)from).getDirectiveId(); else return from; } public void setFrom(Object from) { this.from = from; // DirectivePanel and id mapping handled later when references are fixed } @JsonIgnore public DirectivePanel getFromPanel(){ if(from!=null && from instanceof DirectivePanel) return (DirectivePanel)from; else return null; } @JsonIgnore public void resolveDirectiveValues(Map<String,DirectivePanel> directiveMap){ for(BoundParameter p : parameters){ p.resolveDirectiveValues(directiveMap); } for(AddonParameters a : addons){ a.resolveDirectiveValues(directiveMap); } if(from!=null && from instanceof String){ from=directiveMap.get((String)from); } } @JsonIgnore public void connectAnchors(DirectivePanel panel){ for(int i=0;i<parameters.length;i++){ BoundParameter p=parameters[i]; p.connectAnchors(panel,(i<10?"0":"")+i); } for(int i=0;i<addons.length;i++){ AddonParameters a=addons[i]; a.connectAnchors(panel,"a"+(i<10?"0":"")+i); } if(from!=null){ DirectivePanel p=(DirectivePanel)from; p.getFromConnectorAnchor().setTo(panel.getToConnectorAnchor()); } } @JsonIgnore public DirectiveParameters duplicate(){ BoundParameter[] newParams=new BoundParameter[parameters.length]; AddonParameters[] newAddons=new AddonParameters[addons.length]; for(int i=0;i<parameters.length;i++){ newParams[i]=parameters[i].duplicate(); } for(int i=0;i<addons.length;i++){ newAddons[i]=addons[i].duplicate(); } DirectiveParameters ret=new DirectiveParameters(id, constructor, newParams, newAddons); ret.cls=this.cls; ret.posx=this.posx; ret.posy=this.posy; ret.from=this.from; return ret; } } public static class AddonParameters { public Addon addon; public BoundParameter[] parameters; public AddonParameters(){} public AddonParameters(Addon addon, BoundParameter[] parameters) { this.addon = addon; this.parameters = parameters; } @JsonIgnore public void resolveDirectiveValues(Map<String,DirectivePanel> directiveMap){ for(BoundParameter p : parameters){ p.resolveDirectiveValues(directiveMap); } } @JsonIgnore public void connectAnchors(DirectivePanel panel,String orderingHint){ for(int i=0;i<parameters.length;i++){ BoundParameter p=parameters[i]; p.connectAnchors(panel,orderingHint+(i<10?"0":"")+i); } } @JsonIgnore public AddonParameters duplicate(){ BoundParameter[] newParams=new BoundParameter[parameters.length]; for(int i=0;i<parameters.length;i++){ newParams[i]=parameters[i].duplicate(); } return new AddonParameters(addon,newParams); } } public static class TypedValue { public String parser; public Object value; public TypedValue[] array; public TypedValue(){}; public TypedValue(String parser, Object value) { this.parser = parser; this.value = value; } public TypedValue(TypedValue[] array) { this.parser = "array"; this.array=array; } } public static class BoundParameter { @JsonIgnore protected Parameter parameter; @JsonIgnore protected Object value; public BoundParameter(){} public BoundParameter(Parameter parameter,Object value){ this.parameter=parameter; this.value=value; } public Parameter getParameter(){return parameter;} public void setParameter(Parameter p){this.parameter=p;} @JsonIgnore public Object getBuildValue(Parameter parameter,Object value,boolean multipleComponent){ if(value==null) return null; if(!multipleComponent && parameter.isMultiple()){ Object array=Array.newInstance(parameter.getReflectType().getComponentType(), Array.getLength(value)); for(int i=0;i<Array.getLength(value);i++){ Object v=Array.get(value, i); Array.set(array, i, getBuildValue(parameter,v,true)); } return array; } else{ if(TopicOperand.class.isAssignableFrom(parameter.getType())){ if(value instanceof DirectivePanel) return new TopicOperand(((DirectivePanel)value).buildDirective()); else return new TopicOperand(value); } else if(Operand.class.isAssignableFrom(parameter.getType())){ if(value instanceof DirectivePanel) return new Operand(((DirectivePanel)value).buildDirective()); else return new Operand(value); } else if(Directive.class.isAssignableFrom(parameter.getType())){ return ((DirectivePanel)value).buildDirective(); } else return value; } } @JsonIgnore public Object getBuildValue(){ return getBuildValue(parameter,value,false); } @JsonIgnore public Object getValue(){ return value; } @JsonIgnore public String getScriptValue(){ return getScriptValue(parameter,value,false); } @JsonIgnore public static String escapeString(Object o){ if(o==null) return "null"; return "\""+(o.toString().replace("\\","\\\\").replace("\"","\\\""))+"\""; } @JsonIgnore private static String getScriptValue(Parameter parameter,Object value,boolean multipleComponent){ if(value==null) return "null"; if(!multipleComponent && parameter.isMultiple()){ /* // This is the way you'd create arrays in java usually but // Mozilla Rhino doesn't support this. We have to use // a helper class to get this done. StringBuilder sb=new StringBuilder(); sb.append("new "); sb.append(parameter.getType().getSimpleName()); sb.append("[]{"); boolean first=true; for(int i=0;i<Array.getLength(value);i++){ if(!first) sb.append(", "); else first=false; Object v=Array.get(value, i); sb.append(getScriptValue(parameter,v,true)); } sb.append("}"); return sb.toString();*/ StringBuilder sb=new StringBuilder(); sb.append("new org.wandora.utils.ScriptManager.ArrayBuilder(").append(parameter.getType().getName()).append(")"); for(int i=0;i<Array.getLength(value);i++){ Object v=Array.get(value, i); sb.append(".add("); sb.append(getScriptValue(parameter,v,true)); sb.append(")"); } sb.append(".finalise()"); return sb.toString(); } else if(parameter.getType().equals(String.class)) return escapeString(value); else if(Number.class.isAssignableFrom(parameter.getType())) return value.toString(); else if(Topic.class.isAssignableFrom(parameter.getType())) { try{ return escapeString(((Topic)value).getOneSubjectIdentifier()); }catch(TopicMapException tme){ Wandora.getWandora().handleError(tme); return null; } } else if(TopicOperand.class.isAssignableFrom(parameter.getType())){ if(value instanceof DirectivePanel) return "new TopicOperand("+((DirectivePanel)value).buildScript()+")"; else if(value instanceof Topic) { try{ return "new TopicOperand("+escapeString(((Topic)value).getOneSubjectIdentifier())+")"; }catch(TopicMapException tme){ Wandora.getWandora().handleError(tme); return null; } } else return "new TopicOperand("+escapeString(value)+")"; // Subject identifier string } else if(Operand.class.isAssignableFrom(parameter.getType())){ if(value instanceof DirectivePanel) return "new Operand("+((DirectivePanel)value).buildScript()+")"; else return "new Operand("+escapeString(value)+")"; } else if(Directive.class.isAssignableFrom(parameter.getType())){ return ((DirectivePanel)value).buildScript(); } else throw new RuntimeException("Unable to convert value to script"); } @JsonIgnore protected static TypedValue getJsonValue(Object value,Parameter parameter,boolean multipleComponent){ if(parameter!=null && parameter.isMultiple() && !multipleComponent){ TypedValue[] ret=new TypedValue[Array.getLength(value)]; for(int i=0;i<Array.getLength(value);i++){ Object v=Array.get(value,i); ret[i]=getJsonValue(v,parameter,true); } return new TypedValue(ret); } else { if(value instanceof DirectivePanel){ return new TypedValue("directive",((DirectivePanel)value).getDirectiveId()); } else if(value instanceof Topic){ try{ return new TypedValue("topic",((Topic)value).getOneSubjectIdentifier().toExternalForm()); }catch(TopicMapException tme){Wandora.getWandora().handleError(tme);return null;} } else if(value instanceof TypedValue){ return (TypedValue)value; } else return new TypedValue("default",value); } } @JsonIgnore public static Object parseJsonValue(TypedValue value){ if(value==null) return null; switch (value.parser) { case "directive": return value; case "topic": return value.value; case "array": Object[] ret=new Object[Array.getLength(value.array)]; for(int i=0;i<Array.getLength(value.array);i++){ Object v=Array.get(value.array,i); ret[i]=parseJsonValue((TypedValue)v); } return ret; case "default": return value.value; default: throw new RuntimeException("Unknown type in stored json"); } } public TypedValue getJsonValue(){ return getJsonValue(value,parameter,false); } public void setJsonValue(TypedValue o){ // Directive references are resolved later in resolveDirectiveValues. // Topics can be stored as SI Strings, they are resolved to Topic objects // automatically as needed. value=parseJsonValue(o); } @JsonIgnore public static Object resolveDirectiveValues(Object value,Parameter parameter,Map<String,DirectivePanel> directiveMap){ if(value==null) return null; if(parameter!=null && parameter.isMultiple()){ Object[] os=new Object[Array.getLength(value)]; for(int i=0;i<Array.getLength(value);i++){ Object v=Array.get(value,i); os[i]=resolveDirectiveValues(v,null,directiveMap); } return os; } else { if(value instanceof TypedValue){ TypedValue pv=(TypedValue)value; switch (pv.parser) { case "directive": return directiveMap.get((String)pv.value); default: throw new RuntimeException("No handling for parameter value type "+pv.parser); } } else return value; } } @JsonIgnore public void resolveDirectiveValues(Map<String,DirectivePanel> directiveMap){ value=resolveDirectiveValues(value,parameter,directiveMap); /* if(parameter.getType().equals(Directive.class)){ if(value==null) return; if(parameter.isMultiple()){ Object[] os=new Object[Array.getLength(value)]; for(int i=0;i<Array.getLength(value);i++){ Object v=Array.get(value,i); if(v==null) os[i]=null; else if(v instanceof String) os[i]=directiveMap.get((String)v); else os[i]=v; } value=os; } else { if(value!=null && value instanceof String) value=directiveMap.get((String)value); } } */ } @JsonIgnore public void connectAnchors(DirectivePanel panel,String orderingHint){ if(parameter.isMultiple()){ for(int i=0;i<Array.getLength(value);i++){ Object v=Array.get(value,i); if(v instanceof DirectivePanel) panel.connectParamAnchor( ((DirectivePanel)v).getFromConnectorAnchor(), orderingHint+i); } } else if(value instanceof DirectivePanel){ panel.connectParamAnchor( ((DirectivePanel)value).getFromConnectorAnchor(), orderingHint); } } @JsonIgnore public BoundParameter duplicate(){ return new BoundParameter(parameter, value); } @Override public int hashCode() { int hash = 7; hash = 37 * hash + Objects.hashCode(this.parameter); hash = 37 * hash + Objects.hashCode(this.value); return hash; } @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final BoundParameter other = (BoundParameter) obj; if (!Objects.equals(this.parameter, other.parameter)) { return false; } if (!Objects.equals(this.value, other.value)) { return false; } return true; } } public static AbstractTypePanel makeMultiplePanel(DirectiveUIHints.Parameter param,Class<? extends AbstractTypePanel> typePanel,String label,DirectivePanel directivePanel){ MultipleParameterPanel p=new MultipleParameterPanel(param,typePanel,directivePanel); p.setLabel(label); return p; } public static Class<? extends AbstractTypePanel> getTypePanelClass(DirectiveUIHints.Parameter p){ Class<?> cls=p.getType(); if(cls.equals(Integer.class) || cls.equals(Integer.TYPE)) return IntegerParameterPanel.class; else if(cls.equals(String.class)) return StringParameterPanel.class; else if(cls.equals(TopicOperand.class)) return TopicOperandParameterPanel.class; else if(cls.equals(Operand.class)) return OperandParameterPanel.class; else if(Directive.class.isAssignableFrom(cls)) return DirectiveParameterPanel.class; // this is a guess really else if(cls.equals(Object.class)) return TopicOperandParameterPanel.class; else return UnknownParameterTypePanel.class; } public static AbstractTypePanel[] populateParametersPanel(JPanel panelContainer,DirectiveUIHints.Parameter[] parameters,AbstractTypePanel[] oldPanels,DirectivePanel directivePanel){ if(oldPanels!=null){ for(AbstractTypePanel p : oldPanels){ p.disconnect(); } } panelContainer.removeAll(); GridBagConstraints gbc=new GridBagConstraints(); gbc.gridx=0; gbc.gridy=0; gbc.insets=new Insets(5, 5, 0, 5); gbc.weightx=1.0; gbc.fill=GridBagConstraints.HORIZONTAL; AbstractTypePanel[] panels=new AbstractTypePanel[parameters.length]; for(int i=0;i<parameters.length;i++){ DirectiveUIHints.Parameter p=parameters[i]; Class<? extends AbstractTypePanel> panelCls=getTypePanelClass(p); if(panelCls==null) continue; AbstractTypePanel panel; if(p.isMultiple()){ panel=makeMultiplePanel(p, panelCls, p.getLabel(),directivePanel); panel.setOrderingHint("0"+(i<10?"0":"")+i); } else { try{ java.lang.reflect.Constructor<? extends AbstractTypePanel> panelConstructor=panelCls.getConstructor(DirectiveUIHints.Parameter.class,DirectivePanel.class); panel=panelConstructor.newInstance(p,directivePanel); panel.setLabel(p.getLabel()); panel.setOrderingHint("0"+(i<10?"0":"")+i); if(panel instanceof DirectiveParameterPanel){ if(!p.getType().equals(Directive.class)){ Class<? extends Directive> cls=(Class<? extends Directive>)p.getType(); ((DirectiveParameterPanel)panel).setDirectiveType(cls); } } }catch(IllegalAccessException | InstantiationException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e){ Wandora.getWandora().handleError(e); return null; } } panels[i]=panel; panelContainer.add(panel,gbc); gbc.gridy++; } return panels; } protected void populateParametersPanel(DirectiveUIHints.Constructor c){ if(c==null) return; DirectiveUIHints.Parameter[] parameters=c.getParameters(); this.constructorParamPanels=populateParametersPanel(constructorParameters,parameters,this.constructorParamPanels,directivePanel); this.revalidate(); constructorParameters.repaint(); } public AddonPanel addAddon(Addon addon){ AddonPanel addonPanel=new AddonPanel(this,addon); GridBagConstraints gbc=new GridBagConstraints(); gbc.fill=GridBagConstraints.HORIZONTAL; gbc.weightx=1.0; gbc.gridx=0; gbc.gridy=addonPanels.size(); gbc.insets=new Insets(5, 0, 0, 0); addonPanelContainer.add(addonPanel,gbc); addonPanels.add(addonPanel); return addonPanel; } public void removeAddon(AddonPanel addonPanel){ synchronized(addonPanels){ int index=addonPanels.indexOf(addonPanel); if(index<0) return; addonPanel.disconnect(); GridBagLayout gbl=(GridBagLayout)addonPanelContainer.getLayout(); for(int i=index+1;i<addonPanels.size();i++){ AddonPanel p=addonPanels.get(i); GridBagConstraints gbc=gbl.getConstraints(p); gbc.gridy--; gbl.setConstraints(p, gbc); } addonPanels.remove(index); addonPanelContainer.remove(addonPanel); } this.revalidate(); addonPanelContainer.repaint(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; jScrollPane1 = new javax.swing.JScrollPane(); jPanel2 = new javax.swing.JPanel(); directiveLabel = new javax.swing.JLabel(); deleteButton = new javax.swing.JButton(); constructorComboBox = new javax.swing.JComboBox(); constructorParameters = new javax.swing.JPanel(); jPanel1 = new javax.swing.JPanel(); addAddonButton = new javax.swing.JButton(); addonComboBox = new javax.swing.JComboBox(); jLabel2 = new javax.swing.JLabel(); addonPanelContainer = new javax.swing.JPanel(); fillerPanel = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); setLayout(new java.awt.BorderLayout()); jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); jPanel2.setLayout(new java.awt.GridBagLayout()); directiveLabel.setFont(new java.awt.Font("Ubuntu", 1, 18)); // NOI18N directiveLabel.setText("Directive label"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(5, 5, 10, 5); jPanel2.add(directiveLabel, gridBagConstraints); deleteButton.setText("Remove"); deleteButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { deleteButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridwidth = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END; gridBagConstraints.insets = new java.awt.Insets(5, 5, 10, 5); jPanel2.add(deleteButton, gridBagConstraints); constructorComboBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { constructorComboBoxActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.gridwidth = 4; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5); jPanel2.add(constructorComboBox, gridBagConstraints); constructorParameters.setBorder(javax.swing.BorderFactory.createTitledBorder("")); constructorParameters.setLayout(new java.awt.GridBagLayout()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.gridwidth = 5; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); jPanel2.add(constructorParameters, gridBagConstraints); jPanel1.setLayout(new java.awt.GridBagLayout()); addAddonButton.setText("Add addon"); addAddonButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { addAddonButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0); jPanel1.add(addAddonButton, gridBagConstraints); addonComboBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { addonComboBoxActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 1.0; jPanel1.add(addonComboBox, gridBagConstraints); jLabel2.setFont(new java.awt.Font("Ubuntu", 1, 18)); // NOI18N jLabel2.setText("Addons"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0); jPanel1.add(jLabel2, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 3; gridBagConstraints.gridwidth = 5; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(5, 5, 0, 5); jPanel2.add(jPanel1, gridBagConstraints); addonPanelContainer.setLayout(new java.awt.GridBagLayout()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; gridBagConstraints.gridwidth = 5; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5); jPanel2.add(addonPanelContainer, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 5; gridBagConstraints.weighty = 1.0; jPanel2.add(fillerPanel, gridBagConstraints); jLabel1.setText("Constructor"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0); jPanel2.add(jLabel1, gridBagConstraints); jScrollPane1.setViewportView(jPanel2); add(jScrollPane1, java.awt.BorderLayout.CENTER); }// </editor-fold>//GEN-END:initComponents private void constructorComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_constructorComboBoxActionPerformed Object o=constructorComboBox.getSelectedItem(); ConstructorComboItem c=(ConstructorComboItem)o; this.selectedConstructor=c.c; populateParametersPanel(c.c); }//GEN-LAST:event_constructorComboBoxActionPerformed private void addAddonButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addAddonButtonActionPerformed synchronized(addonPanels){ Object o=addonComboBox.getSelectedItem(); if(o==null || !(o instanceof AddonComboItem)) return; AddonComboItem aci=(AddonComboItem)o; Addon addon=aci.a; addAddon(addon); } this.revalidate(); addonPanelContainer.repaint(); }//GEN-LAST:event_addAddonButtonActionPerformed private void addonComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addonComboBoxActionPerformed }//GEN-LAST:event_addonComboBoxActionPerformed private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed if(directivePanel==null) return; QueryEditorComponent editor=directivePanel.getEditor(); if(editor==null) return; editor.removeDirective(directivePanel); }//GEN-LAST:event_deleteButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton addAddonButton; private javax.swing.JComboBox addonComboBox; private javax.swing.JPanel addonPanelContainer; private javax.swing.JComboBox constructorComboBox; private javax.swing.JPanel constructorParameters; private javax.swing.JButton deleteButton; private javax.swing.JLabel directiveLabel; private javax.swing.JPanel fillerPanel; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JScrollPane jScrollPane1; // End of variables declaration//GEN-END:variables }
40,482
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
MapItem.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/treemap/MapItem.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * Created on Oct 19, 2011, 8:12:21 PM */ package org.wandora.application.gui.topicpanels.treemap; /** * * @author elias, akivela */ public class MapItem { protected double size; protected Rect bounds; protected int order = 0; protected int depth; public void setDepth(int depth) { this.depth=depth; } public int getDepth() { return depth; } public MapItem() { this(1,0); } public MapItem(double size, int order) { this.size = size; this.order = order; bounds = new Rect(); } public double getSize() { return size; } public void setSize(double size) { this.size = size; } public Rect getBounds() { return bounds; } public void setBounds(Rect bounds) { this.bounds = bounds; } public void setBounds(double x, double y, double w, double h) { bounds.setRect(x, y, w, h); } public int getOrder() { return order; } public void setOrder(int order) { this.order = order; } }
1,896
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
Rect.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/treemap/Rect.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * Created on Oct 19, 2011, 8:12:21 PM */ package org.wandora.application.gui.topicpanels.treemap; /** * * @author elias, akivela */ public class Rect { public double x=0; public double y=0; public double w=1; public double h=1; public Rect() { this(0,0,1,1); } public Rect(Rect r) { setRect(r.x, r.y, r.w, r.h); } public Rect(double x, double y, double w, double h) { setRect(x, y, w, h); } public void setRect(double x, double y, double w, double h) { this.x = x; this.y = y; this.w = w; this.h = h; } public double aspectRatio() { return Math.max(w/h, h/w); } public double distance(Rect r) { return Math.sqrt((r.x-x)*(r.x-x)+ (r.y-y)*(r.y-y)+ (r.w-w)*(r.w-w)+ (r.h-h)*(r.h-h)); } public Rect copy() { return new Rect(x,y,w,h); } @Override public String toString() { return "Rect: "+x+", "+y+", "+w+", "+h; } }
1,878
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
TreeMapComponent.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/treemap/TreeMapComponent.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * Created on Oct 19, 2011, 8:12:21 PM */ package org.wandora.application.gui.topicpanels.treemap; import java.awt.Color; import java.awt.Component; import java.awt.Cursor; import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; import java.util.ArrayList; import java.util.Collection; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; import javax.swing.JComponent; import javax.swing.JPopupMenu; import javax.swing.JScrollPane; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreeNode; import org.wandora.application.contexts.PreContext; import org.wandora.application.gui.UIBox; import org.wandora.application.gui.topicpanels.TreeMapTopicPanel; import org.wandora.application.gui.topicstringify.TopicToString; import org.wandora.application.tools.navigate.OpenTopic; import org.wandora.topicmap.Association; import org.wandora.topicmap.Topic; import org.wandora.topicmap.TopicMapException; /** * * @author elias, akivela */ public class TreeMapComponent extends JComponent implements ComponentListener, MouseListener, MouseMotionListener, ActionListener, MouseWheelListener { private static final long serialVersionUID = 1L; private static final int topicFontSize = 12; private static final int typeFontSize = 9; private static final int textLineY = 15; private Topic topic = null; private int mouseX; private int mouseY; private boolean isMouseOver = false; private int width; private int height; private float zoom = 1; private Rect zoomRect; private Rect zoomDrawArea = null; private int iterationDepth = 2; private int treeMapWidth, treeMapHeight, treeMapX, treeMapY; private Rect bounds; private TopicInfo[] viewedTopics = null; private static Font sansFont; private static final String TYPE_INSTANCE = "instance-of"; private static final String TYPE_CLASS = "class-of"; private static final Color colorOfInstances = new Color(0x2ca02c); private static final Color colorOfClasses = new Color(0xd62728); private static final Color[] colorList = new Color[] { new Color(0x393b79), new Color(0x393b79), new Color(0x5254a3), new Color(0x6b6ecf), new Color(0x9c9ede), new Color(0x637939), new Color(0x8ca252), new Color(0xb5cf6b), new Color(0xcedb9c), new Color(0x8c6d31), new Color(0xbd9e39), new Color(0xe7ba52), new Color(0xe7cb94), new Color(0x843c39), new Color(0xad494a), new Color(0xd6616b), new Color(0xe7969c), new Color(0x7b4173), new Color(0xa55194), new Color(0xce6dbd), new Color(0xde9ed6), }; private static Map<String,Color> topicColors = new HashMap<>(); private static Map<Topic, HashMap<Topic, Collection<Topic>>> associationTopicsCache = new HashMap<>(); private static Map<Topic, Integer> associationTopicsSizeCache = new HashMap<>(); private Set<Topic> knownAssociationTypes = new LinkedHashSet<>(); private Set<Topic> filteredAssociationTypes = new LinkedHashSet<>(); private boolean filterClasses = false; private boolean filterInstances = false; private Graphics g = null; private StripTreeMap algorithm; private TreeModel model; private DefaultMutableTreeNode tree; private JPopupMenu popup = null; private TreeMapTopicPanel treeMapTopicPanel = null; public TreeMapComponent(TreeMapTopicPanel topicPanel) { treeMapTopicPanel = topicPanel; sansFont = new Font("SansSerif", Font.PLAIN, 12); addComponentListener(this); addMouseListener(this); addMouseMotionListener(this); addMouseWheelListener(this); this.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); this.g = this.getGraphics(); } public void setIterationDepth(int d) { if(d < 10 && d > 0) { this.iterationDepth = d; initialize(topic); } else { System.out.println("Illegal iteration depth used ("+d+"). Rejecting."); } } public int getIterationDepth() { return iterationDepth; } public void initialize(Topic t) { topic = t; tree = createNode(topic, 0, 0, TYPE_INSTANCE); model = new TopicTree(tree); algorithm = new StripTreeMap(); prepareDraw(); repaint(); } public void updateZoom(int steps) { /* boolean needsUpdating = false; boolean isZoomingIn = false; if(mouseX < treeMapX || mouseY < treeMapY || mouseX > (treeMapX+treeMapWidth) || mouseY > (treeMapY+treeMapHeight)) { return; } steps = steps * -1; if(steps > 0) { if(zoom < 5) { needsUpdating = true; zoom += (float)(steps/10f); if(zoom > 5) zoom = 5; isZoomingIn = true; } } else if(steps < 0) { if(zoom > 1) { needsUpdating = true; zoom += (float)(steps/10f); if(zoom < 1) zoom = 1; } } if(needsUpdating) { zoomRect.w = bounds.w/zoom; zoomRect.h = bounds.h/zoom; float zoomX = ((float)(mouseX - treeMapX) / (float)treeMapWidth - 0.5f); // Ranges from -0.5 to 0.5 float zoomY = ((float)(mouseY - treeMapY) / (float)treeMapHeight - 0.5f); float addX = (float)zoomRect.w / 2f * zoomX; float addY = (float)zoomRect.h / 2f * zoomY; if(isZoomingIn) { // Disable zoom movement if zooming out zoomRect.x += addX; zoomRect.y += addY; } if(zoomRect.x < 0) zoomRect.x = 0f; if(zoomRect.y < 0) zoomRect.y = 0f; if(zoomRect.x+zoomRect.w > bounds.w) zoomRect.x = bounds.w-zoomRect.w; if(zoomRect.y+zoomRect.h > bounds.h) zoomRect.y = bounds.h-zoomRect.h; zoomDrawArea.x = zoomRect.x / bounds.w * (float)treeMapWidth * zoom; zoomDrawArea.y = zoomRect.y / bounds.h * (float)treeMapHeight * zoom; } * */ } public void resetZoom() { zoom = 1; prepareDraw(); repaint(); } RenderingHints qualityHints = new RenderingHints( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); RenderingHints antialiasHints = new RenderingHints( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); RenderingHints antialiasText = new RenderingHints( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); RenderingHints lcdText = new RenderingHints( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); private void initializePaint(Graphics g) { if(g instanceof Graphics2D) { ((Graphics2D) g).addRenderingHints(lcdText); //((Graphics2D) g).addRenderingHints(qualityHints); //((Graphics2D) g).addRenderingHints(antialiasHints); //((Graphics2D) g).addRenderingHints(antialiasText); } } @Override public void paint(Graphics g) { //super.paint(g); if(g != null) { initializePaint(g); //g.setClip(0, 0, this.getWidth()+1, this.getHeight()+1); //g.setColor(this.getBackground()); //g.fillRect(0, 0, this.getWidth()+5, this.getHeight()+5); this.g = g; draw(); super.paint(g); } } public void prepareDraw() { width = this.getWidth(); height = this.getHeight(); treeMapWidth = width; // 515; treeMapHeight = height-22; //450; treeMapX = 0; // width/2 - treeMapWidth/2; treeMapY = 22; // (int)((height/2 - treeMapHeight/2) * 0.7); bounds = new Rect(0f,0f,(float)treeMapWidth/(float)treeMapHeight,1f); if(model != null && algorithm != null) { model.layout(algorithm, bounds); } zoomRect = new Rect(0f,0f,bounds.w,bounds.h); zoomDrawArea = new Rect(0f, 0f, (float)treeMapWidth, (float)treeMapHeight); } public void draw() { isMouseOver = false; viewedTopics = null; drawNodeTree((DefaultMutableTreeNode)tree); drawMouseOverCanvas(); drawInfoWindow(); // Must come AFTER the drawNodeTree } public void drawNodeTree(DefaultMutableTreeNode node) { //System.out.println("drawing node: "+node.getChildCount()); int w=treeMapWidth; int h=treeMapHeight; int tx=treeMapX; int ty=treeMapY; if(g != null) { //g.setClip(tx, ty, w, h); } //itemCount++; TopicInfo ti = (TopicInfo)node.getUserObject(); Rect r = ti.getBounds(); //System.out.println("bounds: "+r); if(r.x > zoomRect.x+zoomRect.w || r.y > zoomRect.y+zoomRect.h || r.x+r.w < zoomRect.x || r.y+r.h < zoomRect.y) { return; } int x=(int)Math.round(w*r.x/bounds.w); int width=(int)Math.round(w*(r.x+r.w)/bounds.w)-x; int y=(int)Math.round(h*r.y/bounds.h); int height=(int)Math.round(h*(r.y+r.h)/bounds.h)-y; x *= zoom; y *= zoom; width *= zoom; height *= zoom; x -= zoomDrawArea.x; y -= zoomDrawArea.y; x += tx; y += ty; ti.rectArea = new Rect(x, y, width, height); setColor(solveMapAreaColor(ti.type, ti.getOrder())); drawFilledRect(x,y,width,height); setColor(Color.BLACK); drawRect(x,y,width,height); Enumeration<TreeNode> children = node.children(); if(children != null) { while (children.hasMoreElements()) { drawNodeTree((DefaultMutableTreeNode) children.nextElement()); } } if(!isMouseOver && ti.depth > 1 && overTopic(x, y, width ,height)) { viewedTopics = new TopicInfo[ti.depth-1]; viewedTopics[ti.depth-2] = ti; DefaultMutableTreeNode currentNode = node; for(int i=ti.depth-3; i>=0; i--) { DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) currentNode.getParent(); viewedTopics[i] = (TopicInfo)parentNode.getUserObject(); currentNode = parentNode; } isMouseOver = true; } } private Color solveMapAreaColor(String t) { return solveMapAreaColor(t, 0); } private Color solveMapAreaColor(String t, int order) { Color c = topicColors.get(t); if(c == null) c = Color.BLUE; return c; } private void drawMouseOverCanvas() { if(isMouseOver) { if(g != null) { //g.setClip(0,0,width+2, height+2); } for(TopicInfo t : viewedTopics) { Rect rect = t.rectArea; setColor(Color.WHITE); drawRect(rect.x, rect.y, rect.w, rect.h); drawRect(rect.x-1, rect.y-1, rect.w+2, rect.h+2); drawRect(rect.x-2, rect.y-2, rect.w+4, rect.h+4); } } } private void drawInfoWindow() { if(g != null) { //g.setClip(0,0,width,height); } int currentX = width-10; if(isMouseOver) { String[] names = new String[viewedTopics.length+1]; String[] types = new String[viewedTopics.length]; names[0] = getTopicName(); for(int i=0;i<viewedTopics.length;i++) { TopicInfo t = viewedTopics[i]; names[i+1] = t.name; if(t.name.length() > 80) { names[i+1] = t.name.substring(0, 77) + "..."; } types[i] = t.type; } currentX = width-10; for(int i=0; i<names.length; i++) { setColor(Color.BLACK); textFont(sansFont, topicFontSize); currentX -= textWidth(names[i]); drawText(names[i], (float)currentX, textLineY); if(i<names.length-1) { textFont(sansFont, typeFontSize); int textWidth = textWidth(types[i]); currentX -= textWidth + 10; drawText(types[i], (float)currentX, textLineY); setColor(solveMapAreaColor(viewedTopics[i].type)); drawFilledRect(currentX, 0, textWidth, 3); currentX -= 10; } } } else { textFont(sansFont, topicFontSize); currentX -= textWidth(getTopicName()); drawText(getTopicName(), currentX, textLineY); } //textFont(sans_font,10); //String zoom_str = "zoom "+ (int)(zoom * 100) + "%"; //text(zoom_str, width-textWidth(zoom_str)-2, 14); } public boolean overTopic(int x, int y, int width, int height) { return mouseX >= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height; } // ------------------------------------------------------------------------- public String getTopicName(Topic t) { return TopicToString.toString(t); } public String getTopicName() { return getTopicName(topic); } // ------------------------------------------------------------------------- public void setColor(Color c) { if(g != null) { g.setColor(c); } } public void setColor(int c) { if(g != null) { g.setColor(new Color(c)); } } public void drawRect(double x, double y, double w, double h) { drawRect((int) Math.round(x), (int) Math.round(y), (int) Math.round(w), (int) Math.round(h)); } public void drawRect(int x, int y, int w, int h) { if(g != null) { g.drawRect(x, y, w, h); } } public void drawFilledRect(float x, float y, float w, float h) { drawFilledRect(Math.round(x), Math.round(y), Math.round(w), Math.round(h)); } public void drawFilledRect(int x, int y, int w, int h) { if(g != null) { g.fillRect(x, y, w, h); } } public void textFont(Font f, int s) { if(g != null) { g.setFont(f.deriveFont(Font.PLAIN, s)); } } public int textWidth(String str) { if(g != null) { FontMetrics fm = g.getFontMetrics(); return fm.stringWidth(str); } else { return 0; } } public void drawText(String str, int x, int y) { if(g != null) g.drawString(str, x, y); } public void drawText(String str, float x, int y) { if(g != null) g.drawString(str, Math.round(x), Math.round(y)); } // ------------------------------------------------------------------------- @Override public void mouseClicked(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent evt) { if(isMouseOver) { for(TopicInfo t : viewedTopics) { if(overTopic((int)t.rectArea.x, (int)t.rectArea.y, (int)t.rectArea.w, (int)t.rectArea.h)) { Object [] struct = new Object[viewedTopics.length*2]; for(int j=0;j<viewedTopics.length;j++) { TopicInfo t2 = viewedTopics[j]; int index = j*2; struct[index] = t2.name; try { struct[index+1] = new OpenTopic(new PreContext( t2.t.getOneSubjectIdentifier() )); } catch(Exception e){}; } //System.out.println("popup created!"); popup = UIBox.makePopupMenu(struct, this); Object[] optionsStruct = new Object[] { "---", "Add filter", getAddFiltersMenuStruct(), "Remove filter", getRemoveFiltersMenuStruct(), "Remove all filters", this, "---", "Options", treeMapTopicPanel.getViewMenuStruct(), }; popup = UIBox.attachPopup(popup, optionsStruct, treeMapTopicPanel); popup.show(this, mouseX-2, mouseY-2); break; } } } } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } // ------------------------------------------------------------------------- @Override public void componentResized(ComponentEvent e) { handleComponentEvent(e); } @Override public void componentMoved(ComponentEvent e) { } @Override public void componentShown(ComponentEvent e) { handleComponentEvent(e); } @Override public void componentHidden(ComponentEvent e) { } public void handleComponentEvent(ComponentEvent e) { try { Dimension size = getSize(); Component c = this.getParent().getParent().getParent(); if(c != null) { if(!(c instanceof JScrollPane)) { size = c.getSize(); } if(!size.equals(getSize())) { //System.out.println("new size treemapcomponent: "+size); setPreferredSize(size); setMinimumSize(size); setSize(size); } } revalidate(); prepareDraw(); repaint(); } catch(Exception ex) { // SKIP } } // ------------------------------------------------------------------------- public void clearCaches() { associationTopicsCache = new HashMap<>(); associationTopicsSizeCache = new HashMap<>(); //topicColors = new HashMap(); } private DefaultMutableTreeNode createNode(Topic curTopic, int curOrder, int curDepth, String type) { try { Collection<Topic> instances = null; if(filterInstances) { instances = new ArrayList<>(); } else { instances = curTopic.getTopicMap().getTopicsOfType(curTopic); } Collection<Topic> classes = null; if(filterClasses) { classes = new ArrayList<>(); } else { classes = curTopic.getTypes(); } HashMap<Topic, Collection<Topic>> associationTopics = associationTopicsCache.get(curTopic); int associationTopicsSize = 0; if(associationTopics == null) { associationTopics = new LinkedHashMap<>(); Collection<Association> associations = curTopic.getAssociations(); associationTopicsSize = 0; for(Association a : associations) { Topic at = a.getType(); knownAssociationTypes.add(at); if(!filteredAssociationTypes.contains(at)) { Collection<Topic> linkedTopics = associationTopics.get(at); if(linkedTopics == null) { linkedTopics = new ArrayList<>(); associationTopics.put(at, linkedTopics); } Topic player = null; boolean skipCurrentTopic = true; for(Topic role : a.getRoles()) { player = a.getPlayer(role); if(skipCurrentTopic && player.mergesWithTopic(curTopic)) { skipCurrentTopic = false; continue; } linkedTopics.add(player); associationTopicsSize++; } } } associationTopicsSizeCache.put(curTopic, Integer.valueOf(associationTopicsSize)); associationTopicsCache.put(curTopic, associationTopics); } associationTopicsSize = associationTopicsSizeCache.get(curTopic); DefaultMutableTreeNode node = new DefaultMutableTreeNode( new TopicInfo(curTopic, associationTopicsSize+instances.size()+classes.size(), curOrder, curDepth, type) ); if(curDepth < iterationDepth) { // *** Instances *** int counter = 0; if(!topicColors.containsKey(TYPE_INSTANCE)) topicColors.put(TYPE_INSTANCE, colorOfInstances); for(Topic t : instances) { DefaultMutableTreeNode leaf = createNode(t, counter, curDepth+1, TYPE_INSTANCE); node.add(leaf); counter++; } // *** Types aka classes *** counter = 0; if(!topicColors.containsKey(TYPE_CLASS)) topicColors.put(TYPE_CLASS, colorOfClasses); for(Topic t : classes) { DefaultMutableTreeNode leaf = createNode(t, counter, curDepth+1, TYPE_CLASS); node.add(leaf); counter++; } // *** Associations *** for(Topic key : associationTopics.keySet()) { counter = 0; Collection<Topic> linkedTopics = associationTopics.get(key); String atype = getTopicName(key); if(!topicColors.containsKey(atype)) { topicColors.put(atype, colorList[topicColors.size() % colorList.length]); } for(Topic t : linkedTopics) { DefaultMutableTreeNode leaf = createNode(t, counter, curDepth+1, atype); node.add(leaf); counter++; } } } return node; } catch(TopicMapException tme) { } catch(Exception ex) { //Logger.getLogger(SketchTemplate.class.getName()).log(Level.SEVERE, null, ex); } return null; } // ------------------------------------------------------------------------- // ------------------------------------------------------------------------- // ------------------------------------------------------------------------- @Override public void mouseDragged(MouseEvent e) { mouseX = e.getX(); mouseY = e.getY(); repaint(); } @Override public void mouseMoved(MouseEvent e) { mouseX = e.getX(); mouseY = e.getY(); if(popup != null) { if(popup.isVisible()) { popup.setVisible(false); } } repaint(); } @Override public void mouseWheelMoved(MouseWheelEvent e) { int steps = e.getWheelRotation(); updateZoom(steps); repaint(); } // ------------------------------------------------------------------------- public void addAssociationTypeFilter(Topic typeTopic) { filteredAssociationTypes.add(typeTopic); } public void removeAssociationTypeFilter(Topic typeTopic) { filteredAssociationTypes.remove(typeTopic); } public void removeAllAssociationTypeFilters() { filteredAssociationTypes = new LinkedHashSet<>(); filterClasses = false; filterInstances = false; } public void setFilterClasses(boolean f) { filterClasses = f; } public void setFilterInstances(boolean f) { filterInstances = f; } private Object[] getRemoveFiltersMenuStruct() { List<Object> struct = new ArrayList<>(); for(Topic filteredAssociationType : filteredAssociationTypes) { try { if(filteredAssociationType != null && !filteredAssociationType.isRemoved()) { struct.add("Remove filter for '"+TopicToString.toString(filteredAssociationType)+"'"); struct.add(new TreeMapFilterActionListener(filteredAssociationType, false)); } } catch(Exception e) {} } if(filterClasses || filterInstances) { if(!struct.isEmpty()) { struct.add("---"); } if(filterClasses) { struct.add("Remove filter for classes"); struct.add(this); } if(filterInstances) { struct.add("Remove filter for instances"); struct.add(this); } } if(struct.isEmpty()) { struct.add("[No filters to remove]"); } return struct.toArray(); } private Object[] getAddFiltersMenuStruct() { List<Object> struct = new ArrayList<>(); for(Topic knownAssociationType : knownAssociationTypes) { try { if(knownAssociationType != null && !knownAssociationType.isRemoved()) { if(!filteredAssociationTypes.contains(knownAssociationType)) { struct.add("Add filter for '"+TopicToString.toString(knownAssociationType)+"'"); struct.add(new TreeMapFilterActionListener(knownAssociationType, true)); } } } catch(Exception e) {} } if(!filterClasses || !filterInstances) { if(!struct.isEmpty()) { struct.add("---"); } if(!filterClasses) { struct.add("Add filter for classes"); struct.add(this); } if(!filterInstances) { struct.add("Add filter for instances"); struct.add(this); } } if(struct.isEmpty()) { struct.add("[No filters to add]"); } return struct.toArray(); } @Override public void actionPerformed(ActionEvent event) { //System.out.println("TreeMapComponent captured action event '"+event+"'"); if(event != null) { String eventName = event.getActionCommand(); if("Add filter for classes".equalsIgnoreCase(eventName)) { setFilterClasses(true); } else if("Add filter for instances".equalsIgnoreCase(eventName)) { setFilterInstances(true); } else if("Remove filter for classes".equalsIgnoreCase(eventName)) { setFilterClasses(false); } else if("Remove filter for instances".equalsIgnoreCase(eventName)) { setFilterInstances(false); } else if("Remove all filters".equalsIgnoreCase(eventName)) { removeAllAssociationTypeFilters(); } initialize(topic); } } // ------------------------------------------------------------------------- private class TreeMapFilterActionListener implements ActionListener { private Topic associationType = null; private boolean addFilter = false; public TreeMapFilterActionListener(Topic t, boolean f) { addFilter = f; associationType = t; } @Override public void actionPerformed(ActionEvent e) { if(associationType != null) { if(addFilter) { filteredAssociationTypes.add(associationType); } else { filteredAssociationTypes.remove(associationType); } clearCaches(); initialize(topic); } } } }
30,449
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
TreeModel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/treemap/TreeModel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * Created on Oct 19, 2011, 8:12:21 PM */ package org.wandora.application.gui.topicpanels.treemap; import java.util.ArrayList; import java.util.List; /** * * @author elias, akivela */ public class TreeModel { private MapItem mapItem; private MapItem[] childItems; private MapItem[] cachedTreeItems; // we assume tree structure doesn't change. private TreeModel[] cachedLeafModels; private TreeModel parent; private List<TreeModel> children=new ArrayList<>(); private boolean sumsChildren; public TreeModel() { this.mapItem=new MapItem(); sumsChildren=true; } public TreeModel(MapItem mapItem) { this.mapItem=mapItem; } public void setOrder(int order) { mapItem.setOrder(order); } public TreeModel[] getLeafModels() { if(cachedLeafModels!=null) return cachedLeafModels; List<TreeModel> v=new ArrayList<>(); addLeafModels(v); int n=v.size(); TreeModel[] m=new TreeModel[n]; v.toArray(m); cachedLeafModels=m; return m; } private List<TreeModel> addLeafModels(List<TreeModel> v) { if(!hasChildren()) { System.err.println("Somehow tried to get child model for leaf!!!"); return v; } if(!getChild(0).hasChildren()) v.add(this); else for (int i=childCount()-1; i>=0; i--) getChild(i).addLeafModels(v); return v; } public int depth() { if(parent==null) return 0; return 1+parent.depth(); } public void layout(StripTreeMap tiling) { layout(tiling, mapItem.getBounds()); } public void layout(StripTreeMap tiling, Rect bounds) { mapItem.setBounds(bounds); if(!hasChildren()) return; double s=sum(); tiling.layout(this, bounds); for (int i=childCount()-1; i>=0; i--) getChild(i).layout(tiling); } public MapItem[] getTreeItems() { if(cachedTreeItems!=null) return cachedTreeItems; List<MapItem> v=new ArrayList<>(); addTreeItems(v); int n=v.size(); MapItem[] m=new MapItem[n]; v.toArray(m); cachedTreeItems=m; return m; } private void addTreeItems(List<MapItem> v) { if(!hasChildren()) v.add(mapItem); else for(int i=childCount()-1; i>=0; i--) getChild(i).addTreeItems(v); } private double sum() { if(!sumsChildren) return mapItem.getSize(); double s=0; for(int i=childCount()-1; i>=0; i--) s+=getChild(i).sum(); mapItem.setSize(s); return s; } public MapItem[] getItems() { if(childItems!=null) return childItems; int n=childCount(); childItems=new MapItem[n]; for(int i=0; i<n; i++) { childItems[i]=getChild(i).getMapItem(); childItems[i].setDepth(1+depth()); } return childItems; } public MapItem getMapItem() { return mapItem; } public void addChild(TreeModel child) { child.setParent(this); children.add(child); childItems=null; } public void setParent(TreeModel parent) { for(TreeModel p=parent; p!=null; p=p.getParent()) if(p==this) throw new IllegalArgumentException("Circular ancestry!"); this.parent=parent; } public TreeModel getParent() { return parent; } public int childCount() { return children.size(); } public TreeModel getChild(int n) { return (TreeModel)children.get(n); } public boolean hasChildren() { return !children.isEmpty(); } public void print() { print(""); } private void print(String prefix) { System.out.println(prefix+"size="+mapItem.getSize()); for(int i=0; i<childCount(); i++) getChild(i).print(prefix+".."); } }
4,861
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
StripTreeMap.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/treemap/StripTreeMap.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * Created on Oct 19, 2011, 8:12:21 PM */ package org.wandora.application.gui.topicpanels.treemap; /** * * @author elias, akivela */ public class StripTreeMap { MapItem[] items; Rect layoutBox; boolean lookahead = true; public StripTreeMap() { } public String getName() { return "StripTreeMap"; } public String getDescription() { return "An Ordered Squarified TreeMap"; } public void setLookahead(boolean lookahead) { this.lookahead = lookahead; } public void layout(TreeModel modelx, Rect bounds) { items = modelx.getItems(); layoutBox = bounds; int i; double totalSize = 0; for (i=0; i<items.length; i++) { totalSize += items[i].getSize(); //System.out.println(items[i].getSize()); } double area = layoutBox.w * layoutBox.h; double scaleFactor = Math.sqrt(area / totalSize); int finishedIndex = 0; int numItems = 0; double prevAR = 0; double ar = 0; double height; double yoffset = 0; Rect box = new Rect(layoutBox); box.x /= scaleFactor; box.y /= scaleFactor; box.w /= scaleFactor; box.h /= scaleFactor; while(finishedIndex < items.length) { debug("A: finishedIndex = " + finishedIndex); // Layout strip numItems = layoutStrip(box, finishedIndex); // Lookahead to second strip if(lookahead) { if((finishedIndex + numItems) < items.length) { int numItems2; double ar2a; double ar2b; // Layout 2nd strip and compute AR of first strip plus 2nd strip numItems2 = layoutStrip(box, finishedIndex + numItems); ar2a = computeAverageAspectRatio(finishedIndex, numItems + numItems2); // Layout 1st and 2nd strips together computeHorizontalBoxLayout(box, finishedIndex, numItems + numItems2); ar2b = computeAverageAspectRatio(finishedIndex, numItems + numItems2); debug("F: numItems2 = " + numItems2 + ", ar2a="+ar2a+", ar2b="+ar2b); if(ar2b < ar2a) { numItems += numItems2; debug("G: numItems = " + numItems); } else { computeHorizontalBoxLayout(box, finishedIndex, numItems); debug("H: backup numItems = " + numItems); } } } for(i=finishedIndex; i<(finishedIndex+numItems); i++) { items[i].getBounds().y += yoffset; } height = items[finishedIndex].getBounds().h; yoffset += height; box.y += height; box.h -= height; finishedIndex += numItems; } Rect rect; for(i=0; i<items.length; i++) { rect = items[i].getBounds(); rect.x *= scaleFactor; rect.y *= scaleFactor; rect.w *= scaleFactor; rect.h *= scaleFactor; rect.x += bounds.x; rect.y += bounds.y; items[i].setBounds(rect); } } protected int layoutStrip(Rect box, int index) { int numItems = 0; double prevAR; double ar = Double.MAX_VALUE; double height; do { prevAR = ar; numItems++; height = computeHorizontalBoxLayout(box, index, numItems); ar = computeAverageAspectRatio(index, numItems); debug("L.1: numItems="+numItems+", prevAR="+prevAR+", ar="+ar); } while ((ar < prevAR) && ((index + numItems) < items.length)); if(ar >= prevAR) { numItems--; height = computeHorizontalBoxLayout(box, index, numItems); ar = computeAverageAspectRatio(index, numItems); debug("L.2: backup: numItems="+numItems); } return numItems; } protected double computeHorizontalBoxLayout(Rect box, int index, int numItems) { int i; double totalSize = computeSize(index, numItems); double height = totalSize / box.w; double width; double x = 0; for(i=0; i<numItems; i++) { width = items[i + index].getSize() / height; items[i + index].setBounds(x, 0, width, height); x += width; } return height; } public void debug(String str) { /*if (DEBUG) { System.out.println(str); }*/ } double computeSize(int index, int num) { double size = 0; for(int i=0; i<num; i++) { size += items[i+index].getSize(); } return size; } double computeAverageAspectRatio(int index, int numItems) { double ar; double tar = 0; double w, h; int i; for(i=0; i<numItems; i++) { w = items[i+index].getBounds().w; h = items[i+index].getBounds().h; ar = Math.max((w / h), (h / w)); tar += ar; } tar /= numItems; return tar; } double computeAspectRatio(int index) { double w = items[index].getBounds().w; double h = items[index].getBounds().h; double ar = Math.max((w / h), (h / w)); return ar; } }
6,365
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
TopicTree.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/treemap/TopicTree.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * Created on Oct 19, 2011, 8:12:21 PM */ package org.wandora.application.gui.topicpanels.treemap; import javax.swing.tree.DefaultMutableTreeNode; /** * * @author elias, akivela */ public class TopicTree extends TreeModel { public TopicTree(DefaultMutableTreeNode root) { addChild(submodel(root)); } private TreeModel submodel(DefaultMutableTreeNode leaf) { if(leaf.getChildCount()==0) { return new TreeModel((TopicInfo) leaf.getUserObject()); } TreeModel t=new TreeModel((TopicInfo) leaf.getUserObject()); for(int i=0; i<leaf.getChildCount(); i++) { t.addChild(submodel((DefaultMutableTreeNode)leaf.getChildAt(i))); } return t; } }
1,550
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
TopicInfo.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/treemap/TopicInfo.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * Created on Oct 19, 2011, 8:12:21 PM */ package org.wandora.application.gui.topicpanels.treemap; import org.wandora.application.gui.topicstringify.TopicToString; import org.wandora.topicmap.Topic; /** * * @author elias, akivela */ public class TopicInfo extends MapItem { public String name; public String type; public int instances; public Topic t; public Rect rectArea; public TopicInfo(Topic t, int instances, int order, int depth) { //this(t, instances, order, depth, TYPE_INSTANCE); this(t, instances, order, depth, ""); } public TopicInfo(Topic t, int instances, int order, int depth, String type) { this.rectArea = null; this.type = type; this.t = t; this.name = getTopicInfoString(t); this.instances = instances; this.order = order; this.size = instances+1; this.bounds = new Rect(); this.depth = depth; } private String getTopicInfoString(Topic t) { try { return TopicToString.toString(t); } catch(Exception e) { return "[error]"; } } }
1,971
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
SphericalWorld.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graph3d/SphericalWorld.java
package org.wandora.application.gui.topicpanels.graph3d; import java.awt.Color; import java.util.ArrayList; import java.util.Collection; /** * * @author olli */ public class SphericalWorld implements World { private final ArrayList<SphericalNode> nodes=new ArrayList<SphericalNode>(); private final ArrayList<SphericalEdge> edges=new ArrayList<SphericalEdge>(); private static final double REPEL_FORCE=0.1; private static final double EDGE_FORCE=0.1; public double repelForce=REPEL_FORCE; public double edgeForce=EDGE_FORCE; public double edgeLength=10.0; public void setProperty(String prop, Object value) { if(prop.equals("repelForce")) repelForce=(Double)value; else if(prop.equals("edgeForce")) edgeForce=(Double)value; else if(prop.equals("edgeLength")) edgeLength=(Double)value; } public Edge addEdge(Node node1, Node node2) { if(!(node1 instanceof SphericalNode) || !(node2 instanceof SphericalNode)) throw new ClassCastException(); synchronized(nodes){ // synchronize both nodes and edges with nodes list SphericalEdge e=new SphericalEdge((SphericalNode)node1, (SphericalNode)node2); edges.add(e); return e; } } public Node addNode(Object nodeObject) { synchronized(nodes){ SphericalNode n=new SphericalNode(nodeObject); nodes.add(n); return n; } } public void removeEdge(Edge edge) { synchronized(nodes){ for(int i=0;i<edges.size();i++){ if(edges.get(i)==edge) { edges.remove(i); return; } } } } public void removeNode(Node node) { synchronized(nodes){ for(int i=0;i<nodes.size();i++){ if(nodes.get(i)==node){ nodes.remove(i); return; } } } } public Collection<? extends Node> getNodes(){ return nodes; } public Collection<? extends Edge> getEdges(){ return edges; } public void simulate(double t){ synchronized(nodes){ double edgeLength=this.edgeLength/(double)nodes.size(); for(int i=0;i<nodes.size();i++){ SphericalNode n1=nodes.get(i); if(!n1.isVisible()) continue; for(int j=i+1;j<nodes.size();j++){ SphericalNode n2=nodes.get(j); if(!n2.isVisible()) continue; Vector3 v1=n1.getPos(); Vector3 v2=n2.getPos(); Vector3 c=v1.cross(v2); double cl=c.length(); // this is the angle between v1 and v2, and thus effectively // the distance between the two points double d=Math.atan2(cl, v1.dot(v2)); double f=repelForce/(d*d); c=c.mul(1/cl); // normalize c Vector3 c1=v1.cross(c).mul(f); n1.addDelta(c1); Vector3 c2=c.cross(v2).mul(f); n2.addDelta(c2); } } for(int i=0;i<edges.size();i++){ SphericalEdge e=edges.get(i); SphericalNode n1=(SphericalNode)e.getNode1(); SphericalNode n2=(SphericalNode)e.getNode2(); if(!n1.isVisible() || !n2.isVisible() || !e.isVisible()) continue; Vector3 v1=n1.getPos(); Vector3 v2=n2.getPos(); Vector3 c=v1.cross(v2); double cl=c.length(); // this is the angle between v1 and v2, and thus effectively // the distance between the two points double d=Math.atan2(cl, v1.dot(v2)); if(d>edgeLength){ double f=(d-edgeLength)/edgeLength*edgeForce; c=c.mul(1/cl); // normalize c Vector3 c1=c.cross(v1).mul(f); n1.addDelta(c1); Vector3 c2=v2.cross(c).mul(f); n2.addDelta(c2); } } for(int i=0;i<nodes.size();i++){ SphericalNode n=nodes.get(i); if(!n.isPinned()){ Vector3 v=n.getPos(); Vector3 d=n.getDelta(); Vector3 c=v.cross(d); double theta=c.length(); if(Math.abs(theta)>1e-10){ c=c.mul(1/theta); theta*=t; double costheta=Math.cos(theta); Vector3 newpos=v.mul(costheta).add(c.cross(v).mul(Math.sin(theta))).add(c.mul(c.dot(v)*(1.0-costheta))); n.setPos(newpos); } } n.resetDelta(); } } } public void makeRandomWorld(int numNodes, int numEdges){ for(int i=0;i<numNodes;i++){ SphericalNode n=(SphericalNode)addNode( i ); // not uniform distribution but good enough n.randomPos(); n.setSize(Math.random()*5.0); Vector3 c=new Vector3(Math.random()*1.0, Math.random()*1.0, Math.random()*1.0); c=c.normalize(); n.setColor(new Color((float)c.x,(float)c.y,(float)c.z)); } for(int i=0;i<numEdges;i++){ int i1=(int)(Math.random()*(double)nodes.size()); int i2=(int)(Math.random()*(double)(nodes.size()-1)); if(i2>=i1) i2++; Node n1=nodes.get(i1); Node n2=nodes.get(i2); addEdge(n1, n2); } } }
5,820
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
Vector3.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graph3d/Vector3.java
package org.wandora.application.gui.topicpanels.graph3d; /** * * @author olli */ public class Vector3 { public double x,y,z; public Vector3(){}; public Vector3(double x, double y, double z) { this.x = x; this.y = y; this.z = z; } public double lengthSquared(){ return x*x+y*y+z*z; } public double length(){ return Math.sqrt(x*x+y*y+z*z); } public boolean isZero(){ return x==0 && y==0 && z==0; } public Vector3 mul(double m){ return new Vector3(x*m,y*m,z*m); } public Vector3 add(Vector3 v){ return new Vector3(x+v.x,y+v.y,z+v.z); } public Vector3 diff(Vector3 v){ return new Vector3(v.x-x,v.y-y,v.z-z); } public Vector3 normalize(){ double l=length(); if(l>0) return new Vector3(x/l,y/l,z/l); else return this; } public double dot(Vector3 v){ return v.x*x+v.y*y+v.z*z; } public Vector3 cross(Vector3 v){ return new Vector3( y*v.z-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x ); } public double angle(Vector3 v){ return Math.acos(this.dot(v)); } }
1,245
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
AbstractNode.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graph3d/AbstractNode.java
package org.wandora.application.gui.topicpanels.graph3d; import java.awt.Color; /** * * @author olli */ public class AbstractNode implements Node { protected Object nodeObject; protected Vector3 pos=new Vector3(1.0,0.0,0.0); protected Vector3 delta=new Vector3(); protected Color color=Color.WHITE; protected double size=1.0; protected boolean visible=true; protected boolean pinned=false; public AbstractNode() { } public AbstractNode(Object nodeObject) { this.nodeObject = nodeObject; } public boolean isPinned() { return pinned; } public void setPinned(boolean pinned) { this.pinned = pinned; } public Object getNodeObject() { return nodeObject; } public Vector3 getPos() { return pos; } public void setPos(Vector3 pos){ this.pos=pos; } public void setDelta(Vector3 delta){ this.delta=delta; } public Vector3 getDelta(){ return delta; } public void addDelta(Vector3 d){ delta=delta.add(d); } public void resetDelta(){ delta=new Vector3(0.0,0.0,0.0); } public Color getColor() { return color; } public void setColor(Color color) { this.color = color; } public double getSize() { return size; } public void setSize(double size) { this.size = size; } public void randomPos(){ Vector3 p=new Vector3(Math.random()*2.0-1.0,Math.random()*2.0-1.0,Math.random()*2.0-1.0); p=p.normalize(); this.setPos(p); } public boolean isVisible() { return visible; } public void setVisible(boolean visible) { this.visible = visible; } }
1,771
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
EuclideanWorld.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graph3d/EuclideanWorld.java
package org.wandora.application.gui.topicpanels.graph3d; import java.awt.Color; import java.util.ArrayList; import java.util.Collection; /** * * @author olli */ public class EuclideanWorld implements World { private final ArrayList<EuclideanNode> nodes=new ArrayList<EuclideanNode>(); private final ArrayList<EuclideanEdge> edges=new ArrayList<EuclideanEdge>(); private static final double REPEL_FORCE=0.0; private static final double EDGE_FORCE=0.0; public double repelForce=REPEL_FORCE; public double edgeForce=EDGE_FORCE; public double edgeLength=1.0; public void setProperty(String prop, Object value) { if(prop.equals("repelForce")) repelForce=(Double)value; else if(prop.equals("edgeForce")) edgeForce=(Double)value; else if(prop.equals("edgeLength")) edgeLength=(Double)value; } public Edge addEdge(Node node1, Node node2) { if(!(node1 instanceof EuclideanNode) || !(node2 instanceof EuclideanNode)) throw new ClassCastException(); synchronized(nodes){ // synchronize both nodes and edges with nodes list EuclideanEdge e=new EuclideanEdge((EuclideanNode)node1, (EuclideanNode)node2); edges.add(e); return e; } } public Node addNode(Object nodeObject) { synchronized(nodes){ EuclideanNode n=new EuclideanNode(nodeObject); nodes.add(n); return n; } } public void removeEdge(Edge edge) { synchronized(nodes){ for(int i=0;i<edges.size();i++){ if(edges.get(i)==edge) { edges.remove(i); return; } } } } public void removeNode(Node node) { synchronized(nodes){ for(int i=0;i<nodes.size();i++){ if(nodes.get(i)==node){ nodes.remove(i); return; } } } } public Collection<? extends Node> getNodes(){ return nodes; } public Collection<? extends Edge> getEdges(){ return edges; } public void simulate(double t){ synchronized(nodes){ double edgeLength=this.edgeLength/(double)nodes.size(); for(int i=0;i<nodes.size();i++){ EuclideanNode n1=nodes.get(i); if(!n1.isVisible()) continue; for(int j=i+1;j<nodes.size();j++){ EuclideanNode n2=nodes.get(j); if(!n2.isVisible()) continue; Vector3 v1=n1.getPos(); Vector3 v2=n2.getPos(); Vector3 d=v1.diff(v2); double f=1.0/d.lengthSquared(); if(f>10.0) f=10.0; f*=repelForce; d=d.normalize(); n1.addDelta(d.mul(-f)); n2.addDelta(d.mul(f)); } } for(int i=0;i<edges.size();i++){ EuclideanEdge e=edges.get(i); EuclideanNode n1=(EuclideanNode)e.getNode1(); EuclideanNode n2=(EuclideanNode)e.getNode2(); if(!n1.isVisible() || !n2.isVisible() || !e.isVisible()) continue; Vector3 v1=n1.getPos(); Vector3 v2=n2.getPos(); Vector3 d=v1.diff(v2); double l=d.length(); d.mul(1.0/l); if(l>edgeLength){ double f=(l-edgeLength)/edgeLength*edgeForce; n1.addDelta(d.mul(f)); n2.addDelta(d.mul(-f)); } } for(int i=0;i<nodes.size();i++){ EuclideanNode n=nodes.get(i); if(!n.isPinned()){ Vector3 v=n.getPos(); Vector3 d=n.getDelta(); n.setPos(v.add(d)); } n.resetDelta(); } } } public void makeRandomWorld(int numNodes, int numEdges){ for(int i=0;i<numNodes;i++){ SphericalNode n=(SphericalNode)addNode( i ); // not uniform distribution but good enough n.randomPos(); n.setSize(Math.random()*5.0); Vector3 c=new Vector3(Math.random()*1.0, Math.random()*1.0, Math.random()*1.0); c=c.normalize(); n.setColor(new Color((float)c.x,(float)c.y,(float)c.z)); } for(int i=0;i<numEdges;i++){ int i1=(int)(Math.random()*(double)nodes.size()); int i2=(int)(Math.random()*(double)(nodes.size()-1)); if(i2>=i1) i2++; Node n1=nodes.get(i1); Node n2=nodes.get(i2); addEdge(n1, n2); } } }
4,831
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
Edge.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graph3d/Edge.java
package org.wandora.application.gui.topicpanels.graph3d; import java.awt.Color; /** * * @author olli */ public interface Edge { public Node getNode1(); public Node getNode2(); public void setEdgeObject(Object o); public Object getEdgeObject(); public Color getColor(); public void setColor(Color c); public boolean isVisible(); public void setVisible(boolean b); public Vector3[] line3(double granularity); }
451
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
SphericalEdge.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graph3d/SphericalEdge.java
package org.wandora.application.gui.topicpanels.graph3d; /** * * @author olli */ public class SphericalEdge extends AbstractEdge { public SphericalEdge(SphericalNode n1, SphericalNode n2) { super(n1,n2); } public Vector3[] line3(double granularity){ Vector3 a=n1.getPos(); Vector3 b=n2.getPos(); double theta0=a.angle(b); int segments=(int)Math.ceil(theta0/granularity)+1; Vector3[] ret=new Vector3[segments]; double dtheta=theta0/(double)(segments-1); Vector3 rot=a.cross(b); if(rot.isZero()) rot=new Vector3(a.y,a.z,a.x); else rot=rot.normalize(); Vector3 rotcrossa=rot.cross(a); double rotdota=rot.dot(a); double theta=0; for(int i=0;i<segments;i++,theta+=dtheta){ double costheta=Math.cos(theta); ret[i]=a.mul(costheta).add(rotcrossa.mul(Math.sin(theta))).add(rot.mul(rotdota).mul(1-costheta)); } return ret; } }
998
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
AbstractEdge.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graph3d/AbstractEdge.java
package org.wandora.application.gui.topicpanels.graph3d; import java.awt.Color; /** * * @author olli */ public abstract class AbstractEdge implements Edge{ protected Object edgeObject; protected AbstractNode n1; protected AbstractNode n2; protected Color color=Color.WHITE; protected boolean visible=true; public AbstractEdge(AbstractNode n1, AbstractNode n2) { this.n1 = n1; this.n2 = n2; } public Color getColor() { return color; } public void setColor(Color color) { this.color = color; } public Node getNode1() { return n1; } public Node getNode2() { return n2; } public boolean isVisible() { return visible; } public void setVisible(boolean visible) { this.visible = visible; } public Object getEdgeObject() { return edgeObject; } public void setEdgeObject(Object edgeObject) { this.edgeObject = edgeObject; } }
1,007
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
Node.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graph3d/Node.java
package org.wandora.application.gui.topicpanels.graph3d; import java.awt.Color; /** * * @author olli */ public interface Node { public Object getNodeObject(); public Vector3 getPos(); public void setPos(Vector3 pos); public double getSize(); public void setSize(double s); public Color getColor(); public void setColor(Color c); public boolean isVisible(); public void setVisible(boolean b); }
436
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
EuclideanNode.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graph3d/EuclideanNode.java
package org.wandora.application.gui.topicpanels.graph3d; /** * * @author olli */ public class EuclideanNode extends AbstractNode { public EuclideanNode() { } public EuclideanNode(Object nodeObject) { super(nodeObject); } public double distance(SphericalNode n){ return n.pos.diff(pos).length(); } }
348
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
SphericalNode.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graph3d/SphericalNode.java
package org.wandora.application.gui.topicpanels.graph3d; /** * * @author olli */ public class SphericalNode extends AbstractNode { public SphericalNode() { } public SphericalNode(Object nodeObject) { super(nodeObject); } public double distance(SphericalNode n){ return pos.angle(n.pos); } public void randomPos(){ Vector3 p=new Vector3(Math.random()*2.0-1.0,Math.random()*2.0-1.0,Math.random()*2.0-1.0); p=p.normalize(); this.setPos(p); } }
525
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
World.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graph3d/World.java
package org.wandora.application.gui.topicpanels.graph3d; import java.util.Collection; /** * * @author olli */ public interface World { public void simulate(double time); public Node addNode(Object nodeObject); public Edge addEdge(Node node1,Node node2); public void removeNode(Node node); public void removeEdge(Edge edge); public Collection<? extends Node> getNodes(); public Collection<? extends Edge> getEdges(); public void setProperty(String prop,Object value); }
507
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
EuclideanEdge.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graph3d/EuclideanEdge.java
package org.wandora.application.gui.topicpanels.graph3d; /** * * @author olli */ public class EuclideanEdge extends AbstractEdge { public EuclideanEdge(EuclideanNode n1, EuclideanNode n2) { super(n1,n2); } public Vector3[] line3(double granularity) { Vector3 v1=n1.getPos(); Vector3 v2=n2.getPos(); Vector3 d=v1.diff(v2); double l=d.length(); int segments=Math.min((int)Math.ceil(l/granularity)+1,100); d=d.mul(1.0/(segments-1)); Vector3[] ret=new Vector3[segments]; Vector3 p=v1; for(int i=0;i<ret.length;i++){ ret[i]=p; p=p.add(d); } return ret; } }
698
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
AbstractTraditionalTopicPanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/traditional/AbstractTraditionalTopicPanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * AbstractTraditionalTopicPanel.java * * Created on 19. lokakuuta 2005, 16:32 * */ package org.wandora.application.gui.topicpanels.traditional; import java.awt.Color; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; import java.awt.event.ActionListener; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseListener; import java.awt.print.Printable; import java.io.File; import java.io.FileInputStream; import java.io.FileReader; import java.io.Reader; import java.io.StringReader; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.RowSorter; import javax.swing.TransferHandler; import javax.swing.border.Border; import javax.swing.border.TitledBorder; import javax.swing.table.TableColumn; import javax.swing.table.TableColumnModel; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.text.PDFTextStripper; import org.wandora.application.RefreshListener; import org.wandora.application.Wandora; import org.wandora.application.gui.DnDHelper; import org.wandora.application.gui.OccurrenceTableAll; import org.wandora.application.gui.OccurrenceTableSingleType; import org.wandora.application.gui.UIBox; import org.wandora.application.gui.UIConstants; import org.wandora.application.gui.simple.AssociationTypeLink; import org.wandora.application.gui.simple.OccurrenceTypeLink; import org.wandora.application.gui.simple.SimpleButton; import org.wandora.application.gui.simple.SimpleField; import org.wandora.application.gui.simple.TopicLink; import org.wandora.application.gui.table.AssociationTable; import org.wandora.application.gui.table.ClassTable; import org.wandora.application.gui.table.InstanceTable; import org.wandora.application.gui.table.SITable; import org.wandora.application.gui.topicpanels.TopicPanel; import org.wandora.application.gui.topicstringify.TopicToString; import org.wandora.application.tools.topicnames.AddScopeTopicToVariantName; import org.wandora.application.tools.topicnames.DeleteScopeTopicInVariantName; import org.wandora.application.tools.topicnames.DeleteVariantName; import org.wandora.topicmap.Association; import org.wandora.topicmap.Locator; import org.wandora.topicmap.SchemaBox; import org.wandora.topicmap.TMBox; import org.wandora.topicmap.Topic; import org.wandora.topicmap.TopicMap; import org.wandora.topicmap.TopicMapException; import org.wandora.topicmap.TopicMapListener; import org.wandora.topicmap.TopicMapReadOnlyException; import org.wandora.topicmap.XTMPSI; import org.wandora.utils.IObox; import org.wandora.utils.IteratedMap; import org.wandora.utils.MSOfficeBox; import org.wandora.utils.Options; import org.wandora.utils.Textbox; /** * * @author akivela */ public abstract class AbstractTraditionalTopicPanel extends JPanel implements Printable, MouseListener, TopicMapListener, RefreshListener { private static final long serialVersionUID = 1L; public static final String VARIANT_GUITYPE_SCHEMA = "schema"; public static final String VARIANT_GUITYPE_USED = "used"; public String variantGUIType = VARIANT_GUITYPE_SCHEMA; public static final String OPTIONS_PREFIX = "gui.traditionalTopicPanel."; public static final String OPTIONS_VIEW_PREFIX = OPTIONS_PREFIX + "view."; public static final String VARIANT_GUITYPE_OPTIONS_KEY = OPTIONS_PREFIX + "nameUI"; public static final Color tableBorderColor = new Color(153,153,153); public static final Border leftTableBorder = BorderFactory.createMatteBorder(0, 1, 0, 0, tableBorderColor); public static final Border leftTopTableBorder = BorderFactory.createMatteBorder(1, 1, 0, 0, tableBorderColor); public int ASSOCIATIONS_WHERE_PLAYER = 1; public int ASSOCIATIONS_WHERE_TYPE = 2; protected OccurrenceTableAll occurrenceTable; protected Collection<OccurrenceTableSingleType> occurrenceTables; protected Map<Set<Topic>,SimpleField> nameTable; protected Map<SimpleField,Set<Topic>> invNameTable; protected Map<Collection<Topic>,String> originalNameTable; // this is never cleared so in some cases may collect topics that aren't anymore visible, // this might result in some unnecessary refreshing protected Set<Locator> visibleTopics; protected Set<Locator> openTopic; protected boolean needsRefresh; /** Creates a new instance of AbstractTraditionalTopicPanel **/ public AbstractTraditionalTopicPanel() { visibleTopics=new HashSet<>(); openTopic=new HashSet<>(); needsRefresh=false; } public void toggleVisibility(String componentName) {} public boolean supportsOpenTopic() { return true; } // ------------------------------------------------------------------------- // --------------------------------------------------------- Mouse Event --- // ------------------------------------------------------------------------- @Override public void mouseClicked(java.awt.event.MouseEvent mouseEvent) { mouseEvent.consume(); } @Override public void mouseEntered(java.awt.event.MouseEvent mouseEvent) { mouseEvent.consume(); } @Override public void mouseExited(java.awt.event.MouseEvent mouseEvent) { mouseEvent.consume(); } @Override public void mousePressed(java.awt.event.MouseEvent mouseEvent) { mouseEvent.consume(); } @Override public void mouseReleased(java.awt.event.MouseEvent mouseEvent) { mouseEvent.consume(); } // ------------------------------------------------------------------------- // ----------------------------------------------------------- Build GUI --- // ------------------------------------------------------------------------- public void buildAssociationsPanel(JPanel associationPanel, JLabel numberLabel, Topic topic, Options options, Wandora wandora) { buildAssociationsPanel(associationPanel, numberLabel, topic, ASSOCIATIONS_WHERE_PLAYER, options, wandora); } public void buildAssociationsPanel(JPanel associationPanel, JLabel numberLabel, Topic topic, int option, Options options, Wandora wandora) { java.awt.GridBagConstraints gbc; try { Map<Association,List<Topic>> selectedAssociationWithRoles = new HashMap<>(); Map<Topic,List<? extends RowSorter.SortKey>> sortKeys = new HashMap<>(); Map<Topic,List<Integer>> columnProperties = new HashMap<>(); if(associationPanel.getComponentCount() > 0) { for(int i=0; i<associationPanel.getComponentCount(); i++) { Component associationTableComponent = associationPanel.getComponent(i); if(associationTableComponent != null && associationTableComponent instanceof AssociationTable) { AssociationTable associationTable = (AssociationTable) associationTableComponent; selectedAssociationWithRoles.putAll(associationTable.getSelectedAssociationsWithSelectedRoles()); Topic associationTypeTopic = associationTable.getAssociationTypeTopic(); sortKeys.put(associationTypeTopic, associationTable.getRowSorter().getSortKeys()); List<Integer> columnProps = new ArrayList<>(); TableColumnModel tcm = associationTable.getColumnModel(); for(int j=0; j<associationTable.getColumnCount(); j++) { TableColumn tc = tcm.getColumn(j); columnProps.add(tc.getModelIndex()); } columnProperties.put(associationTypeTopic, columnProps); } } } associationPanel.removeAll(); Collection<Association> associations=null; associations = new ArrayList<>(); if((option & ASSOCIATIONS_WHERE_PLAYER) != 0) associations.addAll(topic.getAssociations()); if((option & ASSOCIATIONS_WHERE_TYPE) != 0) associations.addAll(topic.getTopicMap().getAssociationsOfType(topic)); associations = TMBox.sortAssociations(associations, "en"); associationPanel.setLayout(new java.awt.GridBagLayout()); List<Association> sameTypes=new ArrayList<>(); Topic lastType=null; Iterator<Association> iter=associations.iterator(); int acounter=0; while(iter.hasNext()){ Association a=iter.next(); if(lastType==null || a.getType()==lastType) { if(lastType==null) lastType=a.getType(); sameTypes.add(a); } else { gbc=new java.awt.GridBagConstraints(); gbc.gridy=acounter++; gbc.gridx=0; gbc.anchor=GridBagConstraints.WEST; gbc.weightx=1.0; gbc.fill=GridBagConstraints.HORIZONTAL; if(acounter!=1) gbc.insets=new java.awt.Insets(10,0,0,0); AssociationTable table=new AssociationTable(sameTypes, wandora, topic); table.setBorder(leftTableBorder); table.getTableHeader().setBorder(leftTopTableBorder); AssociationTypeLink label=new AssociationTypeLink(table, lastType, wandora); label.setFont(UIConstants.h3Font); label.setLimitLength(false); JPopupMenu popup = this.getAssociationTypeMenu(); label.setComponentPopupMenu(popup); associationPanel.add(label,gbc); gbc=new java.awt.GridBagConstraints(); gbc.gridy=acounter++; gbc.gridx=0; gbc.weightx=1.0; gbc.fill=GridBagConstraints.HORIZONTAL; associationPanel.add(table.getTableHeader(),gbc); gbc=new java.awt.GridBagConstraints(); gbc.gridy=acounter++; gbc.gridx=0; gbc.weightx=1.0; gbc.fill=GridBagConstraints.HORIZONTAL; associationPanel.add(table,gbc); lastType=a.getType(); sameTypes=new ArrayList<>(); sameTypes.add(a); } { visibleTopics.addAll(a.getType().getSubjectIdentifiers()); for(Topic role : a.getRoles()){ visibleTopics.addAll(role.getSubjectIdentifiers()); visibleTopics.addAll(a.getPlayer(role).getSubjectIdentifiers()); } } } if(!sameTypes.isEmpty()) { gbc=new java.awt.GridBagConstraints(); gbc.gridy=acounter++; gbc.gridx=0; gbc.anchor=GridBagConstraints.WEST; gbc.weightx=1.0; gbc.fill=GridBagConstraints.HORIZONTAL; if(acounter!=1) gbc.insets=new java.awt.Insets(10,0,0,0); AssociationTable table=new AssociationTable(sameTypes, wandora, topic); AssociationTypeLink label=new AssociationTypeLink(table, lastType, wandora); label.setFont(UIConstants.h3Font); label.setLimitLength(false); JPopupMenu popup = this.getAssociationTypeMenu(); label.setComponentPopupMenu(popup); associationPanel.add(label,gbc); gbc=new java.awt.GridBagConstraints(); gbc.gridy=acounter++; gbc.gridx=0; gbc.weightx=1.0; gbc.fill=GridBagConstraints.HORIZONTAL; table.getTableHeader().setBorder(leftTopTableBorder); table.setBorder(leftTableBorder); associationPanel.add(table.getTableHeader(),gbc); gbc=new java.awt.GridBagConstraints(); gbc.gridy=acounter++; gbc.gridx=0; gbc.weightx=1.0; gbc.fill=GridBagConstraints.HORIZONTAL; associationPanel.add(table,gbc); } // ---- int n = associations.size(); if(numberLabel != null) { numberLabel.setText(""+n); } setParentVisibility(associationPanel, n); // Finally select all previously selected association. for(int i=0; i<associationPanel.getComponentCount(); i++) { Component associationTableComponent = associationPanel.getComponent(i); if(associationTableComponent != null && associationTableComponent instanceof AssociationTable) { AssociationTable associationTable = (AssociationTable) associationTableComponent; Topic associationTypeTopic = associationTable.getAssociationTypeTopic(); List<? extends RowSorter.SortKey> sortKeysForAssociationType = sortKeys.get(associationTypeTopic); if(sortKeysForAssociationType != null) { associationTable.getRowSorter().setSortKeys(sortKeysForAssociationType); } TableColumnModel tcm = associationTable.getColumnModel(); List<Integer> columnProps = columnProperties.get(associationTypeTopic); if(columnProps != null && !columnProps.isEmpty()) { TableColumn[] sortedTableColumns = new TableColumn[columnProps.size()]; for(int j=0; j<columnProps.size(); j++) { if(j < tcm.getColumnCount()) { Integer index = columnProps.get(j); TableColumn tc = tcm.getColumn(j); sortedTableColumns[index] = tc; } } while (tcm.getColumnCount() > 0) { tcm.removeColumn(tcm.getColumn(0)); } for(int j=0; j<columnProps.size(); j++) { if(sortedTableColumns[j] != null) { tcm.addColumn(sortedTableColumns[j]); } } } if(!selectedAssociationWithRoles.isEmpty()) { associationTable.selectAssociations(selectedAssociationWithRoles); } } } } catch(Exception e) { System.out.println("Failed to initialize associationss!"); e.printStackTrace(); } } public void buildClassesPanel(JPanel classesPanel, JLabel numberLabel, Topic topic, Options options, Wandora wandora) { GridBagConstraints gbc; try { Topic[] selectedClasses = null; if(classesPanel.getComponentCount() > 0) { Component oldClassTableComponent = classesPanel.getComponent(0); if(oldClassTableComponent != null && oldClassTableComponent instanceof ClassTable) { ClassTable oldClassTable = (ClassTable) oldClassTableComponent; selectedClasses = oldClassTable.getSelectedTopics(); } } classesPanel.removeAll(); classesPanel.setLayout(new java.awt.GridBagLayout()); gbc=new java.awt.GridBagConstraints(); gbc.gridx=0; gbc.gridy=0; gbc.fill=GridBagConstraints.HORIZONTAL; gbc.weightx=1.0; ClassTable ct = new ClassTable(topic, wandora); ct.setBorder(leftTopTableBorder); classesPanel.add(ct, gbc); int n = ct.getRowCount(); if(numberLabel != null) { numberLabel.setText(""+n); } setParentVisibility(classesPanel, n); { for(Topic t : topic.getTypes()){ visibleTopics.addAll(t.getSubjectIdentifiers()); } } if(selectedClasses != null && selectedClasses.length > 0) { ct.selectTopics(selectedClasses); } } catch(Exception e) { System.out.println("Failed to classes instances!"); e.printStackTrace(); } } public void buildSubjectIdentifierPanel(JPanel subjectIdentifierPanel, Topic topic, Options options, Wandora wandora) { try { Locator[] selectedSIs = null; if(subjectIdentifierPanel.getComponentCount() > 0) { Component oldSITableComponent = subjectIdentifierPanel.getComponent(0); if(oldSITableComponent != null && oldSITableComponent instanceof SITable) { SITable oldSITable = (SITable) oldSITableComponent; selectedSIs = oldSITable.getSelectedLocators(); } } GridBagConstraints gbc; subjectIdentifierPanel.removeAll(); subjectIdentifierPanel.setLayout(new java.awt.GridBagLayout()); gbc=new java.awt.GridBagConstraints(); gbc.gridx=0; gbc.gridy=0; gbc.fill=GridBagConstraints.HORIZONTAL; gbc.weightx=1.0; SITable sit = new SITable(topic, wandora); sit.setBorder(leftTopTableBorder); subjectIdentifierPanel.add(sit,gbc); visibleTopics.addAll(topic.getSubjectIdentifiers()); openTopic.addAll(topic.getSubjectIdentifiers()); if(selectedSIs != null && selectedSIs.length > 0) { sit.selectLocators(selectedSIs); } } catch(Exception e) { System.out.println("Failed to initialize sis!"); e.printStackTrace(); } } public void buildInstancesPanel(JPanel instancesPanel, JLabel numberLabel, Topic topic, Options options, Wandora wandora) { try { Topic[] selectedInstances = null; if(instancesPanel.getComponentCount() > 0) { Component oldInstanceTableComponent = instancesPanel.getComponent(0); if(oldInstanceTableComponent != null && oldInstanceTableComponent instanceof InstanceTable) { InstanceTable oldInstanceTable = (InstanceTable) oldInstanceTableComponent; selectedInstances = oldInstanceTable.getSelectedTopics(); } } GridBagConstraints gbc; instancesPanel.removeAll(); instancesPanel.setLayout(new java.awt.GridBagLayout()); gbc=new java.awt.GridBagConstraints(); gbc.gridx=0; gbc.gridy=0; gbc.fill=GridBagConstraints.HORIZONTAL; gbc.weightx=1.0; InstanceTable it = new InstanceTable(topic, wandora); it.setBorder(leftTopTableBorder); instancesPanel.add(it,gbc); int n = it.getRowCount(); if(numberLabel != null) { numberLabel.setText(""+n); } setParentVisibility(instancesPanel, n); { for(Topic t : topic.getTopicMap().getTopicsOfType(topic)){ visibleTopics.addAll(t.getSubjectIdentifiers()); } } if(selectedInstances != null && selectedInstances.length > 0) { it.selectTopics(selectedInstances); } } catch(Exception e) { System.out.println("Failed to initialize instances!"); e.printStackTrace(); } } public void buildOccurrencesPanel(JPanel dataPanel, JLabel numberLabel, Topic topic, Options options, Wandora wandora) { try { GridBagConstraints gbc; dataPanel.removeAll(); dataPanel.setLayout(new java.awt.GridBagLayout()); occurrenceTables = new ArrayList<>(); int n=0; int y=0; gbc=new java.awt.GridBagConstraints(); for(Topic occurrenceType : topic.getDataTypes()) { OccurrenceTableSingleType occurrenceTableSingle = new OccurrenceTableSingleType(topic, occurrenceType, options, wandora); occurrenceTableSingle.setBorder(leftTableBorder); occurrenceTableSingle.getTableHeader().setBorder(leftTopTableBorder); if(occurrenceTableSingle.getRowCount() > 0) { OccurrenceTypeLink label = new OccurrenceTypeLink(occurrenceTableSingle, occurrenceType, wandora); label.setFont(UIConstants.h3Font); label.setLimitLength(false); JPopupMenu popup = this.getOccurrenceTypeMenu(occurrenceType); label.setComponentPopupMenu(popup); gbc.gridx=0; gbc.gridy=y++; gbc.fill=GridBagConstraints.HORIZONTAL; gbc.weightx=1.0; if(y > 1) { gbc.insets=new java.awt.Insets(10,0,0,0); } else { gbc.insets=new java.awt.Insets(0,0,0,0); } dataPanel.add(label,gbc); gbc.gridy=y++; gbc.insets=new java.awt.Insets(0,0,0,0); dataPanel.add(occurrenceTableSingle.getTableHeader(),gbc); gbc.gridy=y++; dataPanel.add(occurrenceTableSingle,gbc); } { visibleTopics.addAll(occurrenceType.getSubjectIdentifiers()); for(Topic version : topic.getData(occurrenceType).keySet()) { visibleTopics.addAll(version.getSubjectIdentifiers()); n++; } } } if(numberLabel != null) { numberLabel.setText(""+n); } setParentVisibility(dataPanel, n); } catch(Exception e) { System.out.println("Failed to initialize occurrences!"); e.printStackTrace(); } } public void buildOccurrencesPanelOld(JPanel dataPanel, JLabel numberLabel, Topic topic, Options options, Wandora wandora) { try { GridBagConstraints gbc; dataPanel.removeAll(); dataPanel.setLayout(new java.awt.GridBagLayout()); occurrenceTable = null; int n = topic.getDataTypes().size(); if(n > 0) { occurrenceTable=new OccurrenceTableAll(topic, options, wandora); gbc=new java.awt.GridBagConstraints(); gbc.gridx=0; gbc.gridy=0; gbc.fill=GridBagConstraints.HORIZONTAL; gbc.weightx=1.0; dataPanel.add(occurrenceTable.getTableHeader(),gbc); gbc=new java.awt.GridBagConstraints(); gbc.gridx=0; gbc.gridy=1; gbc.fill=GridBagConstraints.HORIZONTAL; gbc.weightx=1.0; dataPanel.add(occurrenceTable,gbc); { for(Topic type : topic.getDataTypes()) { visibleTopics.addAll(type.getSubjectIdentifiers()); for(Topic version : topic.getData(type).keySet()) { visibleTopics.addAll(version.getSubjectIdentifiers()); } } } } else occurrenceTable=null; if(numberLabel != null) { numberLabel.setText(""+n); } setParentVisibility(dataPanel, n); } catch(Exception e) { System.out.println("Failed to initialize occurrences!"); e.printStackTrace(); } } public void buildNamePanel(JPanel variantPanel, JLabel numberLabel, Topic topic, TopicPanel topicPanel, Options options, Wandora wandora) { buildAllNamesPanel(variantPanel, numberLabel, topic, topicPanel, options, wandora); //buildHorizontalNamePanel(variantPanel, parent, topic); } public void buildHorizontalNamePanel(JPanel variantPanel, JLabel numberLabel, Topic topic, final TopicPanel topicPanel, Options options, Wandora wandora) { try { TopicMap tm = wandora.getTopicMap(); GridBagConstraints gbc = new java.awt.GridBagConstraints(); nameTable=new LinkedHashMap<>(); invNameTable=new LinkedHashMap<>(); originalNameTable=new IteratedMap<>(); variantPanel.removeAll(); Topic[] langTopics = null; Topic[] verTopics = null; String[] langs = TMBox.getLanguageSIs(tm); String[] vers = TMBox.getNameVersionSIs(tm); langTopics = tm.getTopics(langs); verTopics = tm.getTopics(vers); variantPanel.setLayout(new java.awt.GridBagLayout()); int x = 1; for(Topic langTopic : langTopics) { if(langTopic != null) { gbc.gridx=x; gbc.gridy=0; gbc.fill=GridBagConstraints.HORIZONTAL; gbc.weightx=1.0; variantPanel.add(new TopicLink(langTopic, wandora), gbc); x++; } } int y = 1; for(Topic verTopic : verTopics) { if(verTopic != null) { gbc.gridx=0; gbc.gridy=y; gbc.fill=GridBagConstraints.HORIZONTAL; gbc.weightx=0.0; gbc.insets = new Insets(0,0,0,10); variantPanel.add(new TopicLink(verTopic, wandora), gbc); x = 1; for (Topic langTopic : langTopics) { if (langTopic != null) { Set<Topic> s=new LinkedHashSet<>(); s.add(verTopic); s.add(langTopic); String name=topic.getVariant(s); SimpleField field = new SimpleField(name==null ? "" : name); field.setCaretPosition(0); //field.setPreferredSize(new java.awt.Dimension(130,21)); field.addKeyListener( new KeyAdapter() { @Override public void keyReleased(java.awt.event.KeyEvent evt) { try { if(topicPanel != null && evt.getKeyCode()==KeyEvent.VK_ENTER) { topicPanel.applyChanges(); } } catch(Exception e) {} } }); field.addFocusListener( new FocusAdapter() { private String originalText = null; @Override public void focusGained(FocusEvent e) { originalText = ((SimpleField) e.getComponent()).getText(); e.getComponent().setBackground(UIConstants.editableBackgroundColor); } @Override public void focusLost(FocusEvent e) { try { String modifiedText = ((SimpleField) e.getComponent()).getText(); if(!originalText.equals(modifiedText) && topicPanel != null) { topicPanel.applyChanges(); e.getComponent().setBackground(UIConstants.editableBackgroundColor); } else { if(originalText.length() == 0) { e.getComponent().setBackground(UIConstants.noContentBackgroundColor); } } } catch(Exception ex) { } } }); if(name == null) { field.setBackground(UIConstants.noContentBackgroundColor); } Color c = wandora.topicHilights.getVariantColor(topic,s); if(c!=null) field.setForeground(c); nameTable.put(s,field); invNameTable.put(field,s); originalNameTable.put(s,field.getText()); gbc.gridx=x; gbc.gridy=y; gbc.fill=GridBagConstraints.HORIZONTAL; gbc.weightx=1.0; gbc.insets=new Insets(0,0,0,0); variantPanel.add(field,gbc); x++; } } y++; } } int n = topic.getVariantScopes().size(); if(numberLabel != null) { numberLabel.setText(""+n); } setParentVisibility(variantPanel, n); } catch(Exception e) { System.out.println("Failed to initialize names!"); e.printStackTrace(); } } public void buildVerticalNamePanel(JPanel variantPanel, JLabel numberLabel, Topic topic, final TopicPanel topicPanel, Options options, Wandora wandora) { if(wandora == null) return; if(variantPanel == null) return; if(topic == null) return; try { TopicMap tm = wandora.getTopicMap(); GridBagConstraints gbc = new java.awt.GridBagConstraints(); Insets rightGapInsets = new Insets(0,0,0,10); Insets noGapsInsets = new Insets(0,0,0,0); Dimension defaultFieldSize = new java.awt.Dimension(100,27); nameTable = new HashMap<>(); invNameTable = new HashMap<>(); originalNameTable = new IteratedMap<>(); variantPanel.removeAll(); Topic[] langTopics = null; Topic[] verTopics = null; String[] langs = TMBox.getLanguageSIs(tm); String[] vers = TMBox.getNameVersionSIs(tm); langTopics = tm.getTopics(langs); verTopics = tm.getTopics(vers); variantPanel.setLayout(new java.awt.GridBagLayout()); int x = 1; for(Topic verTopic : verTopics) { if(verTopic != null) { gbc.gridx=x; gbc.gridy=0; gbc.fill=GridBagConstraints.HORIZONTAL; gbc.weightx=0.0; variantPanel.add(new TopicLink(verTopic, wandora), gbc); x++; } } int y = 1; for(Topic langTopic : langTopics) { if(langTopic != null) { gbc.gridx=0; gbc.gridy=y; gbc.fill=GridBagConstraints.NONE; gbc.weightx=0.0; gbc.anchor=GridBagConstraints.WEST; gbc.insets = rightGapInsets; variantPanel.add(new TopicLink(langTopic, wandora), gbc); x = 1; for(Topic verTopic : verTopics) { if(verTopic != null) { Set<Topic> s = new LinkedHashSet<>(); s.add(verTopic); s.add(langTopic); String name = topic.getVariant(s); SimpleField field = new SimpleField(name==null ? "" : name); field.setCaretPosition(0); field.setPreferredSize(defaultFieldSize); field.addKeyListener( new KeyAdapter() { @Override public void keyReleased(java.awt.event.KeyEvent evt) { try { if(topicPanel != null && evt.getKeyCode()==KeyEvent.VK_ENTER) { topicPanel.applyChanges(); } } catch(Exception e) {} } }); field.addFocusListener( new FocusAdapter() { private String originalText = null; @Override public void focusGained(FocusEvent e) { originalText = ((SimpleField) e.getComponent()).getText(); e.getComponent().setBackground(UIConstants.editableBackgroundColor); } @Override public void focusLost(FocusEvent e) { try { String modifiedText = ((SimpleField) e.getComponent()).getText(); if(!originalText.equals(modifiedText) && topicPanel != null) { topicPanel.applyChanges(); e.getComponent().setBackground(UIConstants.editableBackgroundColor); } else { if(originalText.length() == 0) { e.getComponent().setBackground(UIConstants.noContentBackgroundColor); } } } catch(Exception ex) {} } }); if(name == null) { field.setBackground(UIConstants.noContentBackgroundColor); } Color c = wandora.topicHilights.getVariantColor(topic,s); if(c != null) field.setForeground(c); nameTable.put(s,field); invNameTable.put(field,s); originalNameTable.put(s,field.getText()); gbc.gridx=x; gbc.gridy=y; gbc.fill=GridBagConstraints.HORIZONTAL; gbc.weightx=1.0; gbc.insets = noGapsInsets; variantPanel.add(field,gbc); x++; } } y++; } } int n = topic.getVariantScopes().size(); if(numberLabel != null) { numberLabel.setText(""+n); } setParentVisibility(variantPanel, n); } catch(Exception e) { System.out.println("Failed to initialize names!"); e.printStackTrace(); } } public void buildAllNamesPanel(JPanel variantPanel, JLabel numberLabel, final Topic topic, final TopicPanel topicPanel, Options options, final Wandora wandora) { if(topic != null) { try { nameTable=new LinkedHashMap<>(); invNameTable=new LinkedHashMap<>(); originalNameTable=new IteratedMap<>(); variantPanel.removeAll(); JPanel myVariantPanel = variantPanel; myVariantPanel.setLayout(new GridBagLayout()); Set<Set<Topic>> scopes = topic.getVariantScopes(); int i = 0; for(Set<Topic> scope : scopes) { JPanel scopeNamePanel = new JPanel(); scopeNamePanel.setLayout(new GridBagLayout()); java.awt.GridBagConstraints gbcs = new java.awt.GridBagConstraints(); gbcs.gridx=0; gbcs.gridy=0; gbcs.fill=GridBagConstraints.HORIZONTAL; gbcs.weightx=1.0; gbcs.insets = new Insets(0,10,0,0); SimpleField nf = new SimpleField(); nf.addKeyListener( new KeyAdapter() { @Override public void keyReleased(KeyEvent evt) { try { if(topicPanel != null && evt.getKeyCode()==KeyEvent.VK_ENTER) { topicPanel.applyChanges(); } } catch(Exception e) {} } }); nf.setPreferredSize(new Dimension(100,27)); nf.setMinimumSize(new Dimension(100,27)); String variant = topic.getVariant(scope); nf.setText(variant); scopeNamePanel.add(nf, gbcs); JPanel buttonPanel = new JPanel(); buttonPanel.setPreferredSize(new Dimension(30, 23)); buttonPanel.setMinimumSize(new Dimension(30, 23)); buttonPanel.setMaximumSize(new Dimension(30, 23)); buttonPanel.setLayout(new FlowLayout(0)); SimpleButton deleteVariantButton = new SimpleButton(UIBox.getIcon("gui/icons/delete_variant.png")); deleteVariantButton.setPreferredSize(new Dimension(16, 16)); deleteVariantButton.setBackground(UIConstants.buttonBarBackgroundColor); deleteVariantButton.setForeground(UIConstants.buttonBarLabelColor); deleteVariantButton.setOpaque(true); deleteVariantButton.setBorderPainted(false); deleteVariantButton.setToolTipText("Delete variant name."); final DeleteVariantName tool = new DeleteVariantName(topic, scope); deleteVariantButton.addActionListener(new ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent e) { try { tool.execute(wandora); } catch(TopicMapException tme) { tme.printStackTrace(); } // TODO EXCEPTION } } ); buttonPanel.add(deleteVariantButton); buttonPanel.setSize(16, 16); gbcs.gridx=1; gbcs.fill=GridBagConstraints.NONE; gbcs.weightx=0.0; gbcs.insets = new Insets(0,0,0,0); scopeNamePanel.add(buttonPanel, gbcs); originalNameTable.put(scope, variant); nameTable.put(scope, nf); invNameTable.put(nf, scope); JPanel scopePanel = new JPanel(); scopePanel.setLayout(new GridBagLayout()); java.awt.GridBagConstraints gbcst=new java.awt.GridBagConstraints(); int j=1; for(Topic scopeTopic : scope) { visibleTopics.addAll(scopeTopic.getSubjectIdentifiers()); gbcst.gridx=0; gbcst.gridy=j; gbcst.fill=GridBagConstraints.HORIZONTAL; gbcst.anchor=GridBagConstraints.EAST; gbcst.weightx=1.0; //gbcst.insets = new Insets(0,20,0,0); JPanel fillerPanel = new JPanel(); fillerPanel.setPreferredSize(new Dimension(30, 16)); fillerPanel.setMinimumSize(new Dimension(30, 16)); fillerPanel.setMaximumSize(new Dimension(30, 16)); scopePanel.add(fillerPanel, gbcst); TopicLink scopeTopicLabel = new TopicLink(scopeTopic, wandora); scopeTopicLabel.setLimitLength(false); scopeTopicLabel.setText(scopeTopic); scopeTopicLabel.setToolTipText(scopeTopic.getOneSubjectIdentifier().toExternalForm()); List<Object> addScopeSubmenu = new ArrayList<>(); addScopeSubmenu.add("Add scope topic..."); addScopeSubmenu.add(new AddScopeTopicToVariantName(topic, scope)); addScopeSubmenu.add("---"); String[] vers=TMBox.getNameVersionSIs(wandora.getTopicMap()); for(int k=0; k<vers.length; k++) { Topic lt = wandora.getTopicMap().getTopic(vers[k]); String ltName = TopicToString.toString(lt); addScopeSubmenu.add("Add scope topic '"+ltName+"'"); addScopeSubmenu.add(new AddScopeTopicToVariantName(topic, scope, lt)); } addScopeSubmenu.add("---"); String[] langs=TMBox.getLanguageSIs(wandora.getTopicMap()); for(int k=0; k<langs.length; k++) { Topic lt = wandora.getTopicMap().getTopic(langs[k]); String ltName = TopicToString.toString(lt); addScopeSubmenu.add("Add scope topic '"+ltName+"'"); addScopeSubmenu.add(new AddScopeTopicToVariantName(topic, scope, lt)); } JPopupMenu scopeTopicPopup = UIBox.makePopupMenu( new Object[] { "Add scope topic", addScopeSubmenu.toArray( new Object[] {} ), "Remove scope topic", new DeleteScopeTopicInVariantName(topic, scope, scopeTopic), "---", "Remove variant name", new DeleteVariantName(topic, scope) }, wandora ); scopeTopicLabel.setComponentPopupMenu(scopeTopicPopup); gbcst.gridx=1; gbcst.gridy=j; gbcst.fill=GridBagConstraints.NONE; gbcst.anchor=GridBagConstraints.EAST; //gbcst.weightx=1.0; //gbcst.insets = new Insets(0,0,0,20); scopePanel.add(scopeTopicLabel, gbcst); j++; } gbcs.gridx=0; gbcs.gridy=1; gbcs.gridwidth=1; gbcs.fill=GridBagConstraints.HORIZONTAL; gbcs.weightx=1.0; scopeNamePanel.add(scopePanel, gbcs); java.awt.GridBagConstraints gbc=new java.awt.GridBagConstraints(); gbc.gridx=0; gbc.gridy=i; gbc.fill=GridBagConstraints.HORIZONTAL; gbc.weightx=1.0; gbc.insets = new Insets(5,0,7,0); myVariantPanel.add(scopeNamePanel, gbc); i++; } GridBagConstraints pgbc = new java.awt.GridBagConstraints(); pgbc.fill=GridBagConstraints.HORIZONTAL; pgbc.weightx=1.0; //variantPanel.add(myVariantPanel, pgbc); int n = topic.getVariantScopes().size(); if(numberLabel != null) { numberLabel.setText(""+n); } setParentVisibility(variantPanel, n); } catch(Exception e) { e.printStackTrace(); } } } protected void setPanelTitle(JPanel panel, String title) { try { if(panel != null) { Border border = panel.getBorder(); if(border == null) { panel = (JPanel) panel.getParent(); if(panel != null) border = panel.getBorder(); } if(border != null && border instanceof TitledBorder) { ((TitledBorder) border).setTitle(title); ((TitledBorder) border).setTitleFont(UIConstants.h2Font.deriveFont(Font.BOLD)); } } } catch(Exception e) { e.printStackTrace(); } } public void refresh(){ needsRefresh=false; visibleTopics.clear(); openTopic.clear(); } @Override public void doRefresh() throws TopicMapException { if(needsRefresh) { refresh(); this.revalidate(); this.repaint(); } } // ------------------------------------------------------------------------- // ------------------------------------------------------- Apply Changes --- // ------------------------------------------------------------------------- public boolean applyChanges(final Topic topic, Wandora wandora) throws TopicMapException { try { boolean changed = false; if(nameTable != null) { Iterator<Map.Entry<Set<Topic>,SimpleField>> iter = nameTable.entrySet().iterator(); String originalText = null; while(iter.hasNext()) { Map.Entry<Set<Topic>,SimpleField> e = iter.next(); final Set<Topic> scope = e.getKey(); SimpleField field = e.getValue(); final String text = field.getText().trim(); originalText = (String) originalNameTable.get(scope); if(originalText != null && originalText.equals(text)){ continue; } if(text.length() > 0) { topic.setVariant(scope, text); } else if(originalText!=null) { topic.removeVariant(scope); } changed = true; } } if(occurrenceTable != null) { if(occurrenceTable.applyChanges(topic,wandora)) { changed = true; } } return changed; } catch(TopicMapReadOnlyException roe) { int button = wandora.displayExceptionYesNo("The layer is read only. You can either discard changes and proceed with current operation or cancel.",null,"Discard changes","Cancel"); if(button==0) return false; else { roe.fillInStackTrace(); throw roe; } } } private void setParentVisibility(JComponent component, int n) { Container parentComponent = component.getParent(); if(parentComponent != null) { if(n == 0) { parentComponent.setVisible(false); } else { parentComponent.setVisible(true); } } } // ------------------------------------------------------------------------- // -------------------------------------------------------------- Popups --- // ------------------------------------------------------------------------- public abstract JPopupMenu getNamesMenu(); public abstract JPopupMenu getClassesMenu(); public abstract JPopupMenu getInstancesMenu(); public abstract JPopupMenu getSIMenu(); public abstract JPopupMenu getOccurrencesMenu(); public abstract JPopupMenu getOccurrenceTypeMenu(Topic occurrenceType); public abstract JPopupMenu getSubjectMenu(); public abstract JPopupMenu getAssociationsMenu(); public abstract JPopupMenu getAssociationTypeMenu(); // ------------------------------------------------------------------------- // ---------------------------------------------------- TopicMapListener --- // ------------------------------------------------------------------------- private <T> boolean collectionsOverlap(Collection<T> a,Collection<T> b){ if(a.size()>b.size()){ Collection<T> c=a; a=b; b=c; } for(T o : a){ if(b.contains(o)) return true; } return false; } @Override public void associationRemoved(Association a) throws TopicMapException { if(needsRefresh) return; for(Topic role : a.getRoles()){ if(collectionsOverlap(role.getSubjectIdentifiers(),visibleTopics)) needsRefresh=true; Topic player=a.getPlayer(role); if(collectionsOverlap(player.getSubjectIdentifiers(),visibleTopics)) needsRefresh=true; } } @Override public void topicSubjectLocatorChanged(Topic t, Locator newLocator, Locator oldLocator) throws TopicMapException { if(needsRefresh) return; if(collectionsOverlap(t.getSubjectIdentifiers(),openTopic)) needsRefresh=true; } @Override public void topicSubjectIdentifierChanged(Topic t, Locator added, Locator removed) throws TopicMapException { if(needsRefresh) return; if(t==null) return; if(collectionsOverlap(t.getSubjectIdentifiers(),visibleTopics)) needsRefresh=true; } @Override public void topicVariantChanged(Topic t, Collection<Topic> scope, String newName, String oldName) throws TopicMapException { if(needsRefresh) return; if(collectionsOverlap(t.getSubjectIdentifiers(),visibleTopics)) needsRefresh=true; } @Override public void topicDataChanged(Topic t, Topic type, Topic version, String newValue, String oldValue) throws TopicMapException { if(needsRefresh) return; if(collectionsOverlap(t.getSubjectIdentifiers(),openTopic)) needsRefresh=true; } @Override public void topicBaseNameChanged(Topic t, String newName, String oldName) throws TopicMapException { if(needsRefresh) return; if(collectionsOverlap(t.getSubjectIdentifiers(),visibleTopics)) needsRefresh=true; } @Override public void topicRemoved(Topic t) throws TopicMapException { if(needsRefresh) return; if(collectionsOverlap(t.getSubjectIdentifiers(),visibleTopics)) needsRefresh=true; } @Override public void topicChanged(Topic t) throws TopicMapException { if(needsRefresh) return; if(collectionsOverlap(t.getSubjectIdentifiers(),visibleTopics)) needsRefresh=true; } @Override public void associationTypeChanged(Association a, Topic newType, Topic oldType) throws TopicMapException { if(needsRefresh) return; for(Topic role : a.getRoles()){ if(collectionsOverlap(role.getSubjectIdentifiers(),openTopic)) needsRefresh=true; Topic player=a.getPlayer(role); if(collectionsOverlap(player.getSubjectIdentifiers(),openTopic)) needsRefresh=true; } } @Override public void associationPlayerChanged(Association a, Topic role, Topic newPlayer, Topic oldPlayer) throws TopicMapException { if(a==null) return; if(needsRefresh) return; if(newPlayer!=null && collectionsOverlap(newPlayer.getSubjectIdentifiers(),openTopic)) needsRefresh=true; if(oldPlayer!=null && collectionsOverlap(oldPlayer.getSubjectIdentifiers(),openTopic)) needsRefresh=true; if(needsRefresh) return; for(Topic r : a.getRoles()){ if(collectionsOverlap(r.getSubjectIdentifiers(),openTopic)) needsRefresh=true; Topic player=a.getPlayer(r); if(collectionsOverlap(player.getSubjectIdentifiers(),openTopic)) needsRefresh=true; } } @Override public void associationChanged(Association a) throws TopicMapException { if(needsRefresh) return; needsRefresh=true; } @Override public void topicTypeChanged(Topic t, Topic added, Topic removed) throws TopicMapException { if(needsRefresh) return; if(collectionsOverlap(t.getSubjectIdentifiers(),openTopic)) needsRefresh=true; if(added!=null && collectionsOverlap(added.getSubjectIdentifiers(),openTopic)) needsRefresh=true; if(removed!=null && collectionsOverlap(removed.getSubjectIdentifiers(),openTopic)) needsRefresh=true; } // ------------------------------------------------------------------------- // ---------------------------------------------------- TransferHandlers --- // ------------------------------------------------------------------------- protected class AssociationTableTransferHandler extends TransferHandler { private static final long serialVersionUID = 1L; private TopicPanel topicPanel = null; private Wandora wandora = null; public AssociationTableTransferHandler(TopicPanel topicPanel) { this.topicPanel = topicPanel; this.wandora = Wandora.getWandora(); } @Override public boolean canImport(TransferSupport support) { if(!support.isDrop()) return false; return support.isDataFlavorSupported(DnDHelper.topicDataFlavor) || support.isDataFlavorSupported(DataFlavor.stringFlavor); } @Override protected Transferable createTransferable(JComponent c) { return null; } @Override public int getSourceActions(JComponent c) { return TransferHandler.COPY_OR_MOVE; } @Override public boolean importData(TransferSupport support) { //System.out.println("Dropped "+support); if(!support.isDrop()) return false; try { TopicMap tm = wandora.getTopicMap(); List<Topic> sourceTopics=DnDHelper.getTopicList(support, tm, true); if(sourceTopics==null || sourceTopics.isEmpty()) return false; Topic schemaContentTypeTopic = tm.getTopic(SchemaBox.CONTENTTYPE_SI); Topic schemaAssociationTypeTopic = tm.getTopic(SchemaBox.ASSOCIATIONTYPE_SI); Topic schemaRoleTypeTopic = tm.getTopic(SchemaBox.ROLE_SI); if(schemaContentTypeTopic == null || schemaAssociationTypeTopic == null || schemaRoleTypeTopic == null) { return false; } Topic targetTopic = topicPanel.getTopic(); if(targetTopic != null && !targetTopic.isRemoved()) { boolean associationAdded = false; Collection<Topic> targetTopicTypes = targetTopic.getTypes(); for(Topic targetTopicType : targetTopicTypes) { if(targetTopicType.isOfType(schemaContentTypeTopic)) { Collection<Association> associationTypes = targetTopicType.getAssociations(schemaAssociationTypeTopic); for(Association associationTypeAssociation : associationTypes) { Topic associationType = associationTypeAssociation.getPlayer(schemaAssociationTypeTopic); if(associationType != null) { Collection<Association> roleAssociations = associationType.getAssociations(schemaRoleTypeTopic); Collection<Association> roleAssociations2 = associationType.getAssociations(schemaRoleTypeTopic); if(roleAssociations.size() == 2) { Topic sourceRole = null; Topic targetRole = null; Topic proposedSourceRole = null; Topic proposedTargetRole = null; Topic selectedSourceTopic = null; for(Association roleAssociation : roleAssociations) { proposedTargetRole = roleAssociation.getPlayer(schemaRoleTypeTopic); if(proposedTargetRole != null && proposedTargetRole.mergesWithTopic(targetTopicType)) { targetRole = proposedTargetRole; for(Association roleAssociation2 : roleAssociations2) { proposedSourceRole = roleAssociation2.getPlayer(schemaRoleTypeTopic); for(Topic sourceTopic : sourceTopics) { if(sourceTopic != null && !sourceTopic.isRemoved()) { Collection<Topic> sourceTopicTypes = sourceTopic.getTypes(); for(Topic sourceTopicType : sourceTopicTypes) { if(sourceTopicType != null && !sourceTopicType.isRemoved()) { if(proposedSourceRole.mergesWithTopic(sourceTopicType)) { sourceRole = proposedSourceRole; selectedSourceTopic = sourceTopic; if(targetRole != null && sourceRole != null && selectedSourceTopic != null) { Association a=tm.createAssociation(associationType); a.addPlayer(selectedSourceTopic, sourceRole); a.addPlayer(targetTopic, targetRole); associationAdded = true; } } } } } } } } } } } } } } if(!associationAdded) { Topic associationType = tm.getTopic(SchemaBox.DEFAULT_ASSOCIATION_SI); Topic role1 = tm.getTopic(SchemaBox.DEFAULT_ROLE_1_SI); Topic role2 = tm.getTopic(SchemaBox.DEFAULT_ROLE_2_SI); if(associationType != null && role1 != null && role2 != null) { for(Topic sourceTopic : sourceTopics) { if(sourceTopic != null && !sourceTopic.isRemoved()) { Association a=tm.createAssociation(associationType); a.addPlayer(sourceTopic, role1); a.addPlayer(targetTopic, role2); associationAdded = true; } } } } } wandora.doRefresh(); return true; } catch(Exception ce){ wandora.handleError(ce); } return false; } } protected class InstancesPanelTransferHandler extends TransferHandler { private static final long serialVersionUID = 1L; private TopicPanel topicPanel = null; private Wandora wandora = null; public InstancesPanelTransferHandler(TopicPanel topicPanel) { this.topicPanel = topicPanel; this.wandora = Wandora.getWandora(); } @Override public boolean canImport(TransferSupport support) { if(!support.isDrop()) return false; return support.isDataFlavorSupported(DnDHelper.topicDataFlavor) || support.isDataFlavorSupported(DataFlavor.stringFlavor); } @Override protected Transferable createTransferable(JComponent c) { // return DnDHelper.makeTopicTableTransferable(data,getSelectedRows(),getSelectedColumns()); return null; } @Override public int getSourceActions(JComponent c) { return TransferHandler.COPY_OR_MOVE; } @Override public boolean importData(TransferSupport support) { if(!support.isDrop()) return false; try{ TopicMap tm = wandora.getTopicMap(); List<Topic> topics = DnDHelper.getTopicList(support, tm, true); if(topics==null) return false; Topic base = topicPanel.getTopic(); if(base==null) return false; for(Topic t : topics) { if(t != null && !t.isRemoved()) { t.addType(base); } } wandora.doRefresh(); return true; } catch(Exception ce){ wandora.handleError(ce); } return false; } } protected class ClassesPanelTransferHandler extends TransferHandler { private static final long serialVersionUID = 1L; private TopicPanel topicPanel = null; private Wandora wandora = null; public ClassesPanelTransferHandler(TopicPanel topicPanel) { this.topicPanel = topicPanel; this.wandora = Wandora.getWandora(); } @Override public boolean canImport(TransferSupport support) { if(!support.isDrop()) return false; return support.isDataFlavorSupported(DnDHelper.topicDataFlavor) || support.isDataFlavorSupported(DataFlavor.stringFlavor); } @Override protected Transferable createTransferable(JComponent c) { // return DnDHelper.makeTopicTableTransferable(data,getSelectedRows(),getSelectedColumns()); return null; } @Override public int getSourceActions(JComponent c) { return TransferHandler.COPY_OR_MOVE; } @Override public boolean importData(TransferSupport support) { if(!support.isDrop()) return false; try{ TopicMap tm = wandora.getTopicMap(); List<Topic> topics=DnDHelper.getTopicList(support, tm, true); if(topics==null) return false; Topic base = topicPanel.getTopic(); if(base==null) return false; for(Topic t : topics) { if(t != null && !t.isRemoved()) { base.addType(t); } } wandora.doRefresh(); return true; } catch(Exception ce){ wandora.handleError(ce); } return false; } } protected class OccurrencesPanelTransferHandler extends TransferHandler { private static final long serialVersionUID = 1L; private TopicPanel topicPanel = null; private Wandora wandora = null; public OccurrencesPanelTransferHandler(TopicPanel topicPanel) { this.topicPanel = topicPanel; this.wandora = Wandora.getWandora(); } @Override public boolean canImport(TransferSupport support) { if(!support.isDrop()) return false; return support.isDataFlavorSupported(DnDHelper.topicDataFlavor) || support.isDataFlavorSupported(DataFlavor.stringFlavor) || support.isDataFlavorSupported(DataFlavor.javaFileListFlavor); } @Override protected Transferable createTransferable(JComponent c) { // return DnDHelper.makeTopicTableTransferable(data,getSelectedRows(),getSelectedColumns()); return null; } @Override public int getSourceActions(JComponent c) { return TransferHandler.COPY_OR_MOVE; } @Override public boolean importData(TransferSupport support) { if(!support.isDrop()) return false; try { Transferable transferable = support.getTransferable(); boolean ready = false; String data = null; if(support.isDataFlavorSupported(DataFlavor.stringFlavor)) { data = transferable.getTransferData(DataFlavor.stringFlavor).toString(); } if(transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { try { java.util.List<File> fileList = (java.util.List<File>) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); if(fileList != null && fileList.size() > 0) { for( File occurrenceFile : fileList ) { Reader inputReader = null; String content = ""; String filename = occurrenceFile.getPath().toLowerCase(); String extension = filename.substring(Math.max(filename.lastIndexOf(".")+1, 0)); // --- handle rtf files --- if("rtf".equals(extension)) { content=Textbox.RTF2PlainText(new FileInputStream(occurrenceFile)); inputReader = new StringReader(content); } // --- handle pdf files --- if("pdf".equals(extension)) { try { PDDocument doc = PDDocument.load(occurrenceFile); PDFTextStripper stripper = new PDFTextStripper(); content = stripper.getText(doc); doc.close(); inputReader = new StringReader(content); } catch(Exception e) { System.out.println("No PDF support!"); } } // --- handle MS office files --- if("doc".equals(extension) || "docx".equals(extension) || "ppt".equals(extension) || "xsl".equals(extension) || "vsd".equals(extension) ) { content = MSOfficeBox.getText(occurrenceFile); if(content != null) { inputReader = new StringReader(content); } } // --- handle everything else --- if(inputReader == null) { inputReader = new FileReader(occurrenceFile); } data = IObox.loadFile(inputReader); } } } catch(Exception ce){ Wandora.getWandora().handleError(ce); } } // IF THE OCCURRENCE TEXT (=DATA) IS AVAILABLE, THEN... if(data != null) { Topic base = topicPanel.getTopic(); if(base==null) return false; TopicMap tm = wandora.getTopicMap(); Topic type = tm.getTopic(SchemaBox.DEFAULT_OCCURRENCE_SI); if(type != null) { Collection<Topic> langs = tm.getTopicsOfType(XTMPSI.LANGUAGE); langs = TMBox.sortTopics(langs, "en"); for(Topic lang : langs) { if(ready) break; if(lang != null && !lang.isRemoved()) { if(base.getData(type, lang) == null) { base.setData(type, lang, data); ready = true; } } } } } if(ready) { wandora.doRefresh(); } return true; } catch(Exception ce){ wandora.handleError(ce); } return false; } } protected class TopicPanelTransferHandler extends TransferHandler { private static final long serialVersionUID = 1L; private TopicPanel topicPanel = null; private Wandora wandora = null; public TopicPanelTransferHandler(TopicPanel topicPanel) { this.topicPanel = topicPanel; this.wandora = Wandora.getWandora(); } @Override public boolean canImport(TransferSupport support) { return false; //if(!support.isDrop()) return false; //return support.isDataFlavorSupported(DnDHelper.topicDataFlavor) || // support.isDataFlavorSupported(DataFlavor.stringFlavor); } @Override protected Transferable createTransferable(JComponent c) { // return DnDHelper.makeTopicTableTransferable(data,getSelectedRows(),getSelectedColumns()); return null; } @Override public int getSourceActions(JComponent c) { return TransferHandler.COPY_OR_MOVE; } @Override public boolean importData(TransferSupport support) { if(!support.isDrop()) return false; try { /* TopicMap tm=parent.getTopicMap(); ArrayList<Topic> topics=DnDHelper.getTopicList(support, tm, true); if(topics==null) return false; Topic base=topic; if(base==null) return false; for(Topic t : topics) { if(t != null && !t.isRemoved()) { base.addType(t); } } */ wandora.doRefresh(); } catch(Exception ce){ wandora.handleError(ce); } return false; } } }
75,262
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
CustomTopicPanelConfiguration.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/custompanel/CustomTopicPanelConfiguration.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * * CustomTopicPanelConfiguration.java * * Created on 11. tammikuuta 2008, 10:28 */ package org.wandora.application.gui.topicpanels.custompanel; import static java.awt.event.KeyEvent.VK_F5; import java.awt.BorderLayout; import java.awt.Font; import java.awt.dnd.DnDConstants; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.List; import javax.swing.Icon; import javax.swing.JMenu; import javax.swing.KeyStroke; import javax.swing.event.TreeExpansionEvent; import javax.swing.event.TreeModelEvent; import javax.swing.event.TreeModelListener; import javax.swing.event.TreeWillExpandListener; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.ExpandVetoException; import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; import javax.swing.tree.TreeSelectionModel; import org.wandora.application.Wandora; import org.wandora.application.WandoraScriptManager; import org.wandora.application.gui.UIBox; import org.wandora.application.gui.WandoraOptionPane; import org.wandora.application.gui.simple.SimpleMenu; import org.wandora.application.gui.texteditor.TextEditor; import org.wandora.application.gui.topicpanels.CustomTopicPanel; import org.wandora.application.gui.topicpanels.CustomTopicPanel.QueryGroupInfo; import org.wandora.application.gui.topicpanels.CustomTopicPanel.QueryInfo; import org.wandora.utils.swing.DragJTree; /** * * @author olli */ public class CustomTopicPanelConfiguration extends javax.swing.JPanel { private static final long serialVersionUID = 1L; private List<QueryGroupInfo> groups; private Object rootNode; private CustomTreeModel treeModel; private Wandora wandora; /** Creates new form CustomTopicPanelConfiguration */ public CustomTopicPanelConfiguration(Wandora wandora) { this.wandora=wandora; initComponents(); groupsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); DefaultTreeCellRenderer cellRenderer=new DefaultTreeCellRenderer(); cellRenderer.setLeafIcon(UIBox.getIcon("gui/icons/topic_panel_custom_script.png")); cellRenderer.setClosedIcon(UIBox.getIcon("gui/icons/topic_panel_custom_group.png")); cellRenderer.setOpenIcon(UIBox.getIcon("gui/icons/topic_panel_custom_group.png")); groupsTree.setCellRenderer(cellRenderer); groupsTree.addTreeWillExpandListener(new TreeWillExpandListener(){ public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException { throw new ExpandVetoException(event); } public void treeWillExpand(TreeExpansionEvent event){ } }); } public List<QueryGroupInfo> getQueryGroups(){ return groups; } public void readQueryGroups(List<QueryGroupInfo> oldGroups){ rootNode="Custom panel"; this.groups=new ArrayList<>(); for(QueryGroupInfo g : oldGroups){ this.groups.add(g.deepCopy()); } treeModel=new CustomTreeModel(); groupsTree.setModel(treeModel); openGroups(); updateButtonStates(); } public void updateButtonStates(){ TreePath selection=groupsTree.getSelectionPath(); boolean groupSelected=false; boolean querySelected=false; if(selection!=null){ Object last=selection.getLastPathComponent(); if(last instanceof QueryGroupInfo) groupSelected=true; else if(last instanceof QueryInfo) querySelected=true; } addGroupButton.setEnabled(true); addQueryButton.setEnabled(groupSelected|querySelected); duplicateQueryButton.setEnabled(querySelected); editButton.setEnabled(querySelected); removeGroupButton.setEnabled(groupSelected); removeQueryButton.setEnabled(querySelected); } public void openGroups(){ for(QueryGroupInfo g : groups){ groupsTree.expandPath(new TreePath(new Object[]{rootNode,g})); } } public void addGroup(){ QueryGroupInfo g=new QueryGroupInfo(); g.name="New Group"; groups.add(g); treeModel.fireNodesInserted(new TreeModelEvent(this,new Object[]{rootNode},new int[]{groups.size()-1},new Object[]{g})); openGroups(); } public void removeGroup(TreePath selection){ if(selection==null) return; Object[] path=selection.getPath(); if(path.length!=2) return; QueryGroupInfo g = (QueryGroupInfo)path[1]; int idx=groups.indexOf(g); if(idx==-1) return; groups.remove(g); treeModel.fireNodesRemoved(new TreeModelEvent(this,new Object[]{rootNode},new int[]{idx},new Object[]{g})); } public void addQuery(TreePath selection){ if(selection==null) return; Object[] path=selection.getPath(); if(path.length<2) return; QueryGroupInfo g = (QueryGroupInfo)path[1]; QueryInfo q=new QueryInfo(); q.name="New Query"; q.scriptEngine=WandoraScriptManager.getDefaultScriptEngine(); g.queries.add(q); treeModel.fireNodesInserted(new TreeModelEvent(this,new Object[]{rootNode,g},new int[]{g.queries.size()-1},new Object[]{q})); groupsTree.expandPath(new TreePath(new Object[]{rootNode,g})); } public void duplicateQuery(TreePath selection){ if(selection==null) return; Object[] path=selection.getPath(); if(path.length<3) return; QueryGroupInfo g = (QueryGroupInfo)path[1]; QueryInfo sourceq = (QueryInfo)path[2]; QueryInfo q=sourceq.copy(); q.name="Copy of "+q.name; g.queries.add(q); treeModel.fireNodesInserted(new TreeModelEvent(this,new Object[]{rootNode,g},new int[]{g.queries.size()-1},new Object[]{q})); groupsTree.expandPath(new TreePath(new Object[]{rootNode,g})); } public void removeQuery(TreePath selection){ if(selection==null) return; Object[] path=selection.getPath(); if(path.length!=3) return; QueryGroupInfo g=(QueryGroupInfo)path[1]; QueryInfo q=(QueryInfo)path[2]; int idx=g.queries.indexOf(q); if(idx==-1) return; g.queries.remove(idx); treeModel.fireNodesRemoved(new TreeModelEvent(this,new Object[]{rootNode,g},new int[]{idx},new Object[]{q})); } public void editQuery(TreePath selection){ if(selection==null) return; Object[] path=selection.getPath(); if(path.length!=3) return; QueryGroupInfo g=(QueryGroupInfo)path[1]; QueryInfo q=(QueryInfo)path[2]; ScriptEditor editor=new ScriptEditor(q); editor.setVisible(true); if(editor.acceptChanges()){ q.script=editor.getText(); q.scriptEngine=engineComboBox.getSelectedItem().toString(); q.name=nameField.getText(); treeModel.fireNodesChanged(new TreeModelEvent(this,new Object[]{rootNode,g},new int[]{g.queries.indexOf(q)},new Object[]{q})); } } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; scriptToolPanel = new javax.swing.JPanel(); checkButton = new org.wandora.application.gui.simple.SimpleButton(); jSeparator1 = new javax.swing.JSeparator(); groupsPanel = new javax.swing.JPanel(); editorToolPanel = new javax.swing.JPanel(); nameLabel = new org.wandora.application.gui.simple.SimpleLabel(); nameField = new org.wandora.application.gui.simple.SimpleField(); engineLabel = new org.wandora.application.gui.simple.SimpleLabel(); engineComboBox = new org.wandora.application.gui.simple.SimpleComboBox(); engineComboBox.setEditable(false); addGroupButton = new org.wandora.application.gui.simple.SimpleButton(); removeGroupButton = new org.wandora.application.gui.simple.SimpleButton(); editButton = new org.wandora.application.gui.simple.SimpleButton(); jScrollPane1 = new javax.swing.JScrollPane(); groupsTree = new DraggableTree(); addQueryButton = new org.wandora.application.gui.simple.SimpleButton(); removeQueryButton = new org.wandora.application.gui.simple.SimpleButton(); duplicateQueryButton = new org.wandora.application.gui.simple.SimpleButton(); scriptToolPanel.setLayout(new java.awt.GridBagLayout()); checkButton.setText("Check script"); checkButton.setMargin(new java.awt.Insets(1, 3, 1, 3)); checkButton.setPreferredSize(new java.awt.Dimension(79, 23)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridwidth = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; scriptToolPanel.add(checkButton, gridBagConstraints); jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL; gridBagConstraints.insets = new java.awt.Insets(4, 10, 4, 0); scriptToolPanel.add(jSeparator1, gridBagConstraints); groupsPanel.setLayout(new java.awt.GridBagLayout()); editorToolPanel.setLayout(new java.awt.GridBagLayout()); nameLabel.setText("Name"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); editorToolPanel.add(nameLabel, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); editorToolPanel.add(nameField, gridBagConstraints); engineLabel.setText("Script engine"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5); editorToolPanel.add(engineLabel, gridBagConstraints); engineComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5); editorToolPanel.add(engineComboBox, gridBagConstraints); setLayout(new java.awt.GridBagLayout()); addGroupButton.setText("Add group"); addGroupButton.setMaximumSize(new java.awt.Dimension(105, 23)); addGroupButton.setPreferredSize(new java.awt.Dimension(105, 23)); addGroupButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { addGroupButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(7, 7, 2, 0); add(addGroupButton, gridBagConstraints); removeGroupButton.setText("Remove group"); removeGroupButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { removeGroupButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(0, 7, 7, 0); add(removeGroupButton, gridBagConstraints); editButton.setText("Modify query"); editButton.setMaximumSize(new java.awt.Dimension(105, 23)); editButton.setPreferredSize(new java.awt.Dimension(105, 23)); editButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { editButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 4; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(0, 7, 2, 0); add(editButton, gridBagConstraints); groupsTree.setEditable(true); groupsTree.setRootVisible(false); groupsTree.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { groupsTreeMouseClicked(evt); } }); groupsTree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() { public void valueChanged(javax.swing.event.TreeSelectionEvent evt) { groupsTreeValueChanged(evt); } }); jScrollPane1.setViewportView(groupsTree); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.gridheight = 6; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(7, 0, 7, 0); add(jScrollPane1, gridBagConstraints); addQueryButton.setText("Add query"); addQueryButton.setMaximumSize(new java.awt.Dimension(105, 23)); addQueryButton.setPreferredSize(new java.awt.Dimension(105, 23)); addQueryButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { addQueryButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(7, 7, 2, 0); add(addQueryButton, gridBagConstraints); removeQueryButton.setText("Remove query"); removeQueryButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { removeQueryButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(0, 7, 2, 0); add(removeQueryButton, gridBagConstraints); duplicateQueryButton.setText("Copy query"); duplicateQueryButton.setMaximumSize(new java.awt.Dimension(105, 23)); duplicateQueryButton.setPreferredSize(new java.awt.Dimension(105, 23)); duplicateQueryButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { duplicateQueryButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 5; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(0, 7, 7, 0); add(duplicateQueryButton, gridBagConstraints); }// </editor-fold>//GEN-END:initComponents private void groupsTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_groupsTreeValueChanged updateButtonStates(); }//GEN-LAST:event_groupsTreeValueChanged private void duplicateQueryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_duplicateQueryButtonActionPerformed duplicateQuery(groupsTree.getSelectionPath()); }//GEN-LAST:event_duplicateQueryButtonActionPerformed private void groupsTreeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_groupsTreeMouseClicked if( evt.getClickCount() == 2){ editQuery(groupsTree.getSelectionPath()); } }//GEN-LAST:event_groupsTreeMouseClicked private void removeQueryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeQueryButtonActionPerformed removeQuery(groupsTree.getSelectionPath()); }//GEN-LAST:event_removeQueryButtonActionPerformed private void addQueryButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addQueryButtonActionPerformed addQuery(groupsTree.getSelectionPath()); }//GEN-LAST:event_addQueryButtonActionPerformed private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editButtonActionPerformed editQuery(groupsTree.getSelectionPath()); }//GEN-LAST:event_editButtonActionPerformed private void removeGroupButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeGroupButtonActionPerformed removeGroup(groupsTree.getSelectionPath()); }//GEN-LAST:event_removeGroupButtonActionPerformed private void addGroupButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addGroupButtonActionPerformed addGroup(); }//GEN-LAST:event_addGroupButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton addGroupButton; private javax.swing.JButton addQueryButton; private javax.swing.JButton checkButton; private javax.swing.JButton duplicateQueryButton; private javax.swing.JButton editButton; private javax.swing.JPanel editorToolPanel; private javax.swing.JComboBox engineComboBox; private javax.swing.JLabel engineLabel; private javax.swing.JPanel groupsPanel; private javax.swing.JTree groupsTree; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JSeparator jSeparator1; private javax.swing.JTextField nameField; private javax.swing.JLabel nameLabel; private javax.swing.JButton removeGroupButton; private javax.swing.JButton removeQueryButton; private javax.swing.JPanel scriptToolPanel; // End of variables declaration//GEN-END:variables public class CustomTreeModel implements TreeModel { public ArrayList<TreeModelListener> listeners; public CustomTreeModel(){ listeners=new ArrayList<TreeModelListener>(); } @Override public Object getRoot() { return rootNode; } public void fireNodesChanged(TreeModelEvent e){ for(TreeModelListener l : listeners) l.treeNodesChanged(e); } public void fireNodesInserted(TreeModelEvent e){ for(TreeModelListener l : listeners) l.treeNodesInserted(e); } public void fireNodesRemoved(TreeModelEvent e){ for(TreeModelListener l : listeners) l.treeNodesRemoved(e); } public void fireStructureChanged(TreeModelEvent e){ for(TreeModelListener l : listeners) l.treeStructureChanged(e); } @Override public int getIndexOfChild(Object parent, Object child) { if(parent==rootNode) return groups.indexOf(child); else if(child instanceof QueryGroupInfo) return ((QueryGroupInfo)child).queries.indexOf(child); else return -1; } @Override public Object getChild(Object parent, int index) { if(parent==rootNode){ return groups.get(index); } if(parent instanceof QueryGroupInfo){ return ((QueryGroupInfo)parent).queries.get(index); } return null; } @Override public boolean isLeaf(Object node) { if(node == rootNode) return false; else if(node instanceof QueryGroupInfo) return false; else return true; } @Override public int getChildCount(Object parent) { if(parent==rootNode) return groups.size(); else if(parent instanceof QueryGroupInfo) return ((QueryGroupInfo)parent).queries.size(); else return 0; } @Override public void removeTreeModelListener(TreeModelListener l) { listeners.remove(l); } @Override public void addTreeModelListener(TreeModelListener l) { listeners.add(l); } @Override public void valueForPathChanged(TreePath path, Object newValue) { Object o=path.getLastPathComponent(); if(o instanceof QueryGroupInfo) { ((QueryGroupInfo)o).name=newValue.toString(); fireNodesChanged(new TreeModelEvent(this,new Object[]{rootNode},new int[]{groups.indexOf(o)},new Object[]{o})); } else if(o instanceof QueryInfo) { ((QueryInfo)o).name=newValue.toString(); Object[] p=path.getPath(); QueryGroupInfo g=(QueryGroupInfo)p[1]; fireNodesChanged(new TreeModelEvent(this,new Object[]{rootNode,g},new int[]{g.queries.indexOf(o)},new Object[]{o})); } } } public class DraggableTree extends DragJTree { @Override public int allowDrop(TreePath destinationParent, TreePath destinationPosition, TreePath source) { Object[] s=source.getPath(); if(destinationParent==null) return DnDConstants.ACTION_NONE; Object[] d=destinationParent.getPath(); if(s.length==3){ if(d.length==2) return DnDConstants.ACTION_MOVE; else return DnDConstants.ACTION_NONE; } else if(s.length==2){ if(d.length==1) return DnDConstants.ACTION_MOVE; else return DnDConstants.ACTION_NONE; } else return DnDConstants.ACTION_NONE; } @Override public void doDrop(TreePath destinationParent, TreePath destinationPosition, TreePath source, int action) { Object[] s=source.getPath(); Object[] d=destinationParent.getPath(); Object[] p=null; if(destinationPosition!=null) p=destinationPosition.getPath(); if(s[s.length-1] instanceof QueryInfo){ if(d[d.length-1] instanceof QueryGroupInfo){ QueryInfo q=(QueryInfo)s[s.length-1]; QueryGroupInfo g=(QueryGroupInfo)d[d.length-1]; QueryGroupInfo oldg=(QueryGroupInfo)s[s.length-2]; int idx=oldg.queries.indexOf(q); oldg.queries.remove(q); CustomTopicPanelConfiguration.this.treeModel.fireNodesRemoved(new TreeModelEvent(this,new Object[]{rootNode,oldg},new int[]{idx},new Object[]{q})); if(p!=null){ QueryInfo pq=(QueryInfo)p[p.length-1]; int idx2=g.queries.indexOf(pq); if(idx2!=-1) idx=idx2+1; } else idx=0; g.queries.add(idx,q); CustomTopicPanelConfiguration.this.treeModel.fireNodesInserted(new TreeModelEvent(this,new Object[]{rootNode,g},new int[]{idx},new Object[]{q})); } } else if(s[s.length-1] instanceof QueryGroupInfo){ if(d.length==1){ QueryGroupInfo g=(QueryGroupInfo)s[s.length-1]; int idx=groups.indexOf(g); groups.remove(g); CustomTopicPanelConfiguration.this.treeModel.fireNodesRemoved(new TreeModelEvent(this,new Object[]{rootNode},new int[]{idx},new Object[]{g})); if(p!=null){ QueryGroupInfo pg=(QueryGroupInfo)p[p.length-1]; int idx2=groups.indexOf(pg); if(idx2!=-1) idx=idx2+1; } else idx=0; groups.add(idx,g); CustomTopicPanelConfiguration.this.treeModel.fireNodesInserted(new TreeModelEvent(this,new Object[]{rootNode},new int[]{idx},new Object[]{g})); openGroups(); } } } } private class ScriptEditor extends TextEditor { private static final long serialVersionUID = 1L; public static final String optionPrefix = "scriptTextEditor."; protected JMenu scriptMenu; public ScriptEditor(QueryInfo queryInfo) { super(CustomTopicPanelConfiguration.this.wandora,true,queryInfo.script); this.setTitle("Edit query script"); this.wrapLines(false); WandoraScriptManager sm=new WandoraScriptManager(); java.util.List<String> engines = WandoraScriptManager.getAvailableEngines(); engineComboBox.removeAllItems(); for (String e : engines) { engineComboBox.addItem(e); } engineComboBox.setSelectedItem( WandoraScriptManager.makeEngineKey( sm.getScriptEngine(queryInfo.scriptEngine).getFactory() ) ); nameField.setText(queryInfo.name); centerPanel.add(editorToolPanel,BorderLayout.NORTH); ActionListener[] ls=checkButton.getActionListeners(); for(ActionListener l : ls) { checkButton.removeActionListener(l); } checkButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ checkScript(); } }); setCustomButtons(scriptToolPanel); this.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); } public void checkScript(){ String message=CustomTopicPanel.checkScript( wandora, engineComboBox.getSelectedItem().toString(), simpleTextPane.getText()); if(message!=null){ WandoraOptionPane.showMessageDialog( wandora, message, "Check syntax", WandoraOptionPane.ERROR_MESSAGE); } else{ WandoraOptionPane.showMessageDialog( wandora, "No errors", "Check syntax", WandoraOptionPane.INFORMATION_MESSAGE); } } @Override public String getOptionsPrefix(){ return optionPrefix; } @Override public void exitTextEditor(boolean acceptingChanges) { if(acceptingChanges){ String message=CustomTopicPanel.checkScript( wandora, engineComboBox.getSelectedItem().toString(), simpleTextPane.getText()); if(message!=null){ int c=WandoraOptionPane.showConfirmDialog( wandora, "Unabled to evaluate script. Do you want continue?<br><br>"+message, "Check syntax."); if(c!=WandoraOptionPane.YES_OPTION) { return; } } } super.exitTextEditor(acceptingChanges); } public JMenu getScriptMenu(){ scriptMenu = new SimpleMenu("Script", (Icon) null); Object[] menuStructure = new Object[] { "Check script", UIBox.getIcon(0xf00c), KeyStroke.getKeyStroke(VK_F5, 0), }; scriptMenu.removeAll(); UIBox.attachMenu( scriptMenu, menuStructure, this ); return scriptMenu; } @Override public void initMenuBar(){ super.initMenuBar(); menuBar.add(getScriptMenu()); } @Override public void actionPerformed(java.awt.event.ActionEvent actionEvent) { String c = actionEvent.getActionCommand(); if("check script".equalsIgnoreCase(c)){ checkScript(); } else super.actionPerformed(actionEvent); } } }
31,379
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
VNode.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/VNode.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * VNode.java * * Created on 4.6.2007, 14:01 * */ package org.wandora.application.gui.topicpanels.graphpanel; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.Shape; import java.awt.Stroke; import java.util.Collection; import java.util.HashSet; import org.wandora.application.gui.topicpanels.graphpanel.projections.Projection; import org.wandora.utils.Tuples.T2; /** * * @author olli */ public class VNode { private int id; private Node node; private VModel model; double x,y; double newx,newy; boolean mouseOver=false; boolean pinned=false; boolean selected=false; int cluster=0; int edgeCount=0; private HashSet<VEdge> edges; private GraphStyle style = null; /** Creates a new instance of VNode */ public VNode(Node node, VModel model, int id) { this.id = id; this.node = node; this.model = model; this.edges = new HashSet<VEdge>(); this.style = model.getGraphStyle(); } public int getID(){ return id; } public VModel getModel(){ return model; } public Node getNode() { return node; } public TopicMapGraphPanel getPanel(){ return model.getPanel(); } public double getX() { return x; } public double getY() { return y; } public void setX(double x) { this.x = x; } public void setY(double y) { this.y = y; } void addEdge(VEdge edge){ edges.add(edge); edgeCount=edges.size(); } void removeEdge(VEdge edge){ edges.remove(edge); edgeCount=edges.size(); } public boolean isPinned() { return pinned; } public void setPinned(boolean b) { pinned=b; } public boolean isSelected() { return selected; } public Collection<VEdge> getEdges(){ return edges; } private boolean getCropNodeBoxes() { if(model != null) { TopicMapGraphPanel p = model.getPanel(); if(p != null) { return p.getCropNodeBoxes(); } } return true; } public void draw(Graphics2D g2, Projection proj){ if(getShape()==NodeShape.invisible && !mouseOver) return; T2<Double,Double> pos=proj.worldToScreen(x,y); if(pos.e1 == Double.NaN || pos.e2 == Double.NaN) return; if(node instanceof AssociationNode) { int posX=(int)pos.e1.doubleValue(); int posY=(int)pos.e2.doubleValue(); double scale=proj.scale(x,y); int w=(int) (12*scale); int h=(int) (12*scale); if(w>0 && h>0){ Color c=getColor(); g2.setColor(c); g2.fillOval(posX-w/2,posY-h/2,w,h); if(h>2 && w>2 && getBorderColor()!=null){ g2.setColor(getBorderColor()); g2.setStroke(getBorderStroke()); g2.drawOval(posX-w/2,posY-h/2,w,h); } } } else { int posX=(int)pos.e1.doubleValue(); int posY=(int)pos.e2.doubleValue(); double scale=proj.scale(x,y); int w=(int)(getWidth()*scale+0.5); int h=(int)(getHeight()*scale+0.5); int labelWidth=-1; String label=node.getLabel(); int fontSize=(int)(getFontSize()*scale); if(label!=null){ if(fontSize<12 && mouseOver) fontSize=12; if(fontSize>2){ Font f=getFont(fontSize); g2.setFont(f); labelWidth=g2.getFontMetrics().stringWidth(label); if((labelWidth>w && mouseOver) || !getCropNodeBoxes()) w=labelWidth; if((int)(fontSize*1.5)>h && mouseOver) h=(int)(fontSize*1.5); } } if(w>0 && h>0){ Color c=getColor(); g2.setColor(c); g2.fillRect(posX-w/2-4,posY-h/2,w+8,h); if(h>2 && w>2 && getBorderColor()!=null){ g2.setColor(getBorderColor()); g2.setStroke(getBorderStroke()); g2.drawRect(posX-w/2-4,posY-h/2,w+8,h); } } if(label!=null && fontSize>2) { if(labelWidth>w){ Shape oldClip=g2.getClip(); Rectangle oldClipRect = oldClip.getBounds(); int newClipX = Math.max( oldClipRect.x, posX-w/2+1); int newClipY = Math.max( oldClipRect.y, posY-h/2+1); int newClipWidth = Math.min(oldClipRect.width, posX+w/2+1) - newClipX; int newClipHeight = Math.min(oldClipRect.height, posY+h/2+1) - newClipY; g2.setClip(newClipX-4, newClipY, newClipWidth+8, newClipHeight); g2.setColor(getTextColor()); g2.drawString(label,posX-w/2+1,posY+g2.getFont().getSize()/2); g2.setClip(oldClip); } else{ g2.setColor(getTextColor()); g2.drawString(label,posX-labelWidth/2,posY+g2.getFont().getSize()/2); } } } } public boolean pointInside(double px,double py){ double ix=x-getWidth()/2; double iy=y-getHeight()/2; double ax=ix+getWidth(); double ay=iy+getHeight(); return (ix<px && px<ax && iy<py && py<ay); } // --------------------------------------------------------- GRAPH STYLE --- public void setGraphStyle(GraphStyle newStyle) { if(newStyle == null) { this.style = model.getGraphStyle(); } else { this.style = newStyle; } } public Color getColor() { return style.getNodeColor(this); } public Color getTextColor() { return style.getNodeTextColor(this); } public Color getBorderColor() { return style.getNodeBorderColor(this); } public Stroke getBorderStroke() { return style.getNodeBorderStroke(this); } public double getWidth() { return style.getNodeWidth(this); } public double getHeight() { return style.getNodeHeight(this); } public NodeShape getShape() { return style.getNodeShape(this); } public int getFontSize() { return style.getNodeFontSize(this); } public Font getFont(int forSize) { return style.getNodeFont(this, forSize); } }
7,643
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
GraphTool.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/GraphTool.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * GraphTool.java * * Created on 6.6.2007, 15:18 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package org.wandora.application.gui.topicpanels.graphpanel; /** * * @author olli */ public abstract class GraphTool { public abstract String getName(); public javax.swing.Icon getIcon(){return null;} public void invokeNode(VNode n,VModel model,TopicMapGraphPanel panel){} public void invokeEdge(VEdge e,VModel model,TopicMapGraphPanel panel){} public void invokeGeneral(VModel model,TopicMapGraphPanel panel){} }
1,402
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
TopicMapModel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/TopicMapModel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * TopicMapModel.java * * Created on 5.6.2007, 15:18 * */ package org.wandora.application.gui.topicpanels.graphpanel; import static org.wandora.utils.Tuples.t2; import java.util.Collection; import java.util.HashMap; import java.util.Map; import org.wandora.topicmap.Association; import org.wandora.topicmap.Topic; import org.wandora.topicmap.TopicHashMap; import org.wandora.topicmap.TopicMap; import org.wandora.topicmap.TopicMapException; import org.wandora.utils.Tuples.T2; /** * * @author olli */ public class TopicMapModel { private TopicHashMap<TopicNode> topicIndex; private Map<AssociationWrapper, AssociationEdge> associationEdgeIndex; private Map<AssociationWrapper, AssociationNode> associationNodeIndex; // type,instance private Map<T2<Node,Node>,InstanceEdge> instanceEdgeIndex; private Map<OccurrenceWrapper, OccurrenceEdge> occurrenceEdgeIndex; private Map<OccurrenceWrapper, OccurrenceNode> occurrenceNodeIndex; private VModel vModel; //private HashMap<TopicNode,Color> typeColors; private TopicMap topicMap; /** Creates a new instance of TopicMapModel */ public TopicMapModel(VModel vModel,TopicMap topicMap) { this.vModel=vModel; this.topicMap=topicMap; topicIndex=new TopicHashMap<>(); associationEdgeIndex=new HashMap<>(); associationNodeIndex=new HashMap<>(); occurrenceEdgeIndex=new HashMap<>(); occurrenceNodeIndex=new HashMap<>(); instanceEdgeIndex=new HashMap<>(); } public TopicMap getTopicMap(){ return topicMap; } public boolean topicIsIndexed(Topic t){ return topicIndex.containsKey(t); } public boolean associationIsIndexed(Association a){ try{ AssociationWrapper wrapper=new AssociationWrapper(a); if(wrapper.type==null || wrapper.roles.length==0) return false; if(wrapper.roles.length==2) return associationEdgeIndex.containsKey(wrapper); else return associationNodeIndex.containsKey(wrapper); } catch(TopicMapException tme){ tme.printStackTrace(); return false; } } public TopicNode getNodeFor(Topic t) { TopicNode ret=topicIndex.get(t); if(ret!=null) return ret; ret=new TopicNode(t,this); topicIndex.put(t,ret); return ret; } public AssociationNode getNodeFor(Association a) { try { AssociationWrapper wrapper=new AssociationWrapper(a); if(wrapper.roles.length!=2){ AssociationNode n=associationNodeIndex.get(wrapper); if(n!=null) return n; else { n=new AssociationNode(a,this); associationNodeIndex.put(wrapper,n); return n; } } else return null; } catch(TopicMapException tme){ tme.printStackTrace(); return null; } } public OccurrenceNode getNodeFor(Topic carrier, Topic type, Topic scope, String str) { try { OccurrenceWrapper wrapper=new OccurrenceWrapper(carrier, type, scope, str); OccurrenceNode n=occurrenceNodeIndex.get(wrapper); if(n!=null) return n; else { n=new OccurrenceNode(carrier, type, scope, str, this); occurrenceNodeIndex.put(wrapper, n); return n; } } catch(TopicMapException tme){ tme.printStackTrace(); return null; } } public Edge getEdgeFor(Association a){ try { AssociationWrapper wrapper=new AssociationWrapper(a); if(wrapper.roles.length==2){ AssociationEdge e=associationEdgeIndex.get(wrapper); if(e!=null) return e; else { e=new AssociationEdge(a,this); associationEdgeIndex.put(wrapper,e); return e; } } else return null; } catch(TopicMapException tme){ tme.printStackTrace(); return null; } } public InstanceEdge getInstanceEdgeFor(Topic type, Topic instance) { Node ntype=getNodeFor(type); Node ninstance=getNodeFor(instance); InstanceEdge e=instanceEdgeIndex.get(t2(ntype,ninstance)); if(e==null){ e=new InstanceEdge(type,instance,this); instanceEdgeIndex.put(t2(ntype,ninstance),e); } return e; } public OccurrenceEdge getOccurrenceEdgeFor(Topic carrier, Topic occurrenceType, Topic occurrenceScope, String occurrence) { try { OccurrenceWrapper wrapper=new OccurrenceWrapper(carrier, occurrenceType, occurrenceScope, occurrence); OccurrenceEdge e=occurrenceEdgeIndex.get(wrapper); if(e!=null) return e; else { e=new OccurrenceEdge(carrier, occurrenceType, occurrenceScope, occurrence, this); occurrenceEdgeIndex.put(wrapper,e); return e; } } catch(TopicMapException tme) { tme.printStackTrace(); return null; } } /* ---------------------------------------------------------------------- */ private class AssociationWrapper { public Node type; public Node[] roles; public Node[] players; public int hashCode; public AssociationWrapper(Association a) throws TopicMapException { Collection<Topic> roles=a.getRoles(); this.roles=new Node[roles.size()]; this.players=new Node[roles.size()]; if(roles.isEmpty() || a.getType()==null) return; this.type=getNodeFor(a.getType()); int counter=0; hashCode=this.type.hashCode(); for(Topic role : roles){ Topic player=a.getPlayer(role); this.roles[counter]=getNodeFor(role); this.players[counter]=getNodeFor(player); hashCode^=this.roles[counter].hashCode()+counter; hashCode^=this.players[counter].hashCode()+counter+roles.size(); counter++; } } @Override public int hashCode(){ return hashCode; } @Override public boolean equals(Object o){ if(!(o instanceof AssociationWrapper)) return false; AssociationWrapper a=(AssociationWrapper)o; if(a.hashCode!=this.hashCode) return false; if(this.roles.length!=a.roles.length) return false; ILoop: for(int i=0;i<this.roles.length;i++){ for(int j=0;j<a.roles.length;j++){ if(this.roles[i].equals(a.roles[j])){ if(this.players[i].equals(a.players[i])) continue ILoop; else return false; } } return false; } return true; } } /* ---------------------------------------------------------------------- */ private class OccurrenceWrapper { public Node carrier; public Node type; public Node scope; public String occurrence; public int hashCode; public OccurrenceWrapper(Topic carrier, Topic type, Topic scope, String occurrence) throws TopicMapException { this.carrier=getNodeFor(carrier); this.type=getNodeFor(type); this.scope=getNodeFor(scope); this.occurrence=occurrence; hashCode=this.type.hashCode(); hashCode^=this.carrier.hashCode()+1; hashCode^=this.scope.hashCode()+2; hashCode^=this.occurrence.hashCode()+3; } @Override public int hashCode(){ return hashCode; } @Override public boolean equals(Object o){ if(!(o instanceof OccurrenceWrapper)) return false; OccurrenceWrapper ow=(OccurrenceWrapper)o; if(ow.hashCode!=this.hashCode) return false; if(!ow.carrier.equals(carrier)) return false; if(!ow.type.equals(type)) return false; if(!ow.scope.equals(scope)) return false; if(!ow.occurrence.equals(occurrence)) return false; return true; } } }
9,679
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
GraphFilter.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/GraphFilter.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * GraphFilter.java * * Created on 6.6.2007, 15:51 * */ package org.wandora.application.gui.topicpanels.graphpanel; import java.util.Collection; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Set; import org.wandora.topicmap.Association; import org.wandora.topicmap.Topic; import org.wandora.topicmap.TopicMapException; /** * * @author olli, akivela */ public class GraphFilter implements NodeFilter, EdgeFilter { private Set<TopicNode> filteredNodes; private Set<TopicNode> filteredTypes; private boolean filterInstances; private boolean filterOccurrences; private HashSet<TopicNode> filteredEdgeTypes; private TopicMapModel model; /** Creates a new instance of GraphFilter */ public GraphFilter(TopicMapModel tmModel) { this.model=tmModel; filteredNodes=new LinkedHashSet<TopicNode>(); filteredTypes=new LinkedHashSet<TopicNode>(); filteredEdgeTypes=new LinkedHashSet<TopicNode>(); filterInstances=false; filterOccurrences=false; } public void setTopicMapModel(TopicMapModel newModel) { this.model=newModel; } public TopicMapModel getTopicMapModel() { return this.model; } public void filterNode(TopicNode tn){ filteredNodes.add(tn); } public void filterNode(VNode vn){ Node n=vn.getNode(); if(n instanceof TopicNode) filterNode((TopicNode)n); } public void filterNode(Topic t){ filterNode(model.getNodeFor(t)); } public void filterNodesOfType(TopicNode type){ filteredTypes.add(type); } public void filterNodesOfType(Topic type){ filterNodesOfType(model.getNodeFor(type)); } public void filterNodesOfType(VNode vn){ Node n=vn.getNode(); if(n instanceof TopicNode) filterNodesOfType((TopicNode)n); } public void releaseNodesOfType(TopicNode type){ filteredTypes.remove(type); } public void releaseNodesOfType(Topic type){ releaseNodesOfType(model.getNodeFor(type)); } public void releaseNodesOfType(VNode vn){ Node n=vn.getNode(); if(n instanceof TopicNode) { releaseNodesOfType((TopicNode) n); } } public void releaseNode(TopicNode tn) { filteredNodes.remove(tn); } public void filterEdgeType(Topic type) { filterEdgeType(model.getNodeFor(type)); } public void filterEdgeType(TopicNode type) { filteredEdgeTypes.add(type); } public void filterEdgeType(VNode vn) { Node n=vn.getNode(); if(n instanceof TopicNode) filterEdgeType((TopicNode)n); } public void releaseEdgeType(Topic type) { releaseEdgeType(model.getNodeFor(type)); } public void releaseEdgeType(TopicNode type) { filteredEdgeTypes.remove(type); } public void releaseEdgeType(VNode vn) { Node n=vn.getNode(); if(n instanceof TopicNode) releaseEdgeType((TopicNode)n); } public Collection<TopicNode> getFilteredNodes(){ return filteredNodes; } public Collection<TopicNode> getFilteredNodeTypes(){ return filteredTypes; } public Collection<TopicNode> getFilteredEdgeTypes(){ return filteredEdgeTypes; } public boolean getFilterInstances(){ return filterInstances; } public void setFilterInstances(boolean b){ filterInstances=b; } public boolean getFilterOccurrences(){ return filterOccurrences; } public void setFilterOccurrences(boolean b){ filterOccurrences=b; } public void clearNodeFilters() { filteredNodes = new HashSet<TopicNode>(); } public void clearNodeTypeFilters() { filteredTypes = new HashSet<TopicNode>(); } public void clearEdgeFilters() { filteredEdgeTypes = new HashSet<TopicNode>(); filterInstances = false; filterOccurrences = false; } /* ---------------------------------------------------------------------- */ public boolean isNodeFiltered(Node n) { if(n == null) return true; if(n instanceof OccurrenceNode) { return filterOccurrences; } else if(filteredNodes.contains(n)) { return true; } else if(n instanceof TopicNode && !filteredTypes.isEmpty()) { TopicNode tn=(TopicNode)n; try { for(Topic type : tn.getTopic().getTypes()) { if(filteredTypes.contains(model.getNodeFor(type))) return true; } } catch(TopicMapException tme){ tme.printStackTrace(); } } return false; } public boolean isEdgeFiltered(Edge e) { if(e == null) return true; if(e instanceof OccurrenceEdge) { return filterOccurrences; } else if(e instanceof AssociationEdge){ AssociationEdge ae=(AssociationEdge)e; Association a=ae.getAssociation(); if(a!=null) { try { if(filteredEdgeTypes.contains(model.getNodeFor(a.getType()))) return true; } catch(TopicMapException tme){ tme.printStackTrace(); } } } else if(e instanceof InstanceEdge){ return filterInstances; } return false; } /* ---------------------------------------------------------------------- */ public String describeFilters() { StringBuilder sb = new StringBuilder(""); if(!filteredNodes.isEmpty()) { sb.append( "Filtered nodes\n" ); for(TopicNode n : filteredNodes) { sb.append(n.getLabel()).append("\n"); } sb.append( "\n"); } else { sb.append("No nodes filtered\n"); } if(!filteredTypes.isEmpty()) { sb.append( "\nFiltered nodes typed as\n"); for(TopicNode n : filteredTypes) { sb.append(n.getLabel()).append( "\n"); } sb.append( "\n"); } else { sb.append("No node types filtered\n"); } if(!filteredEdgeTypes.isEmpty() || filterInstances || filterOccurrences) { sb.append( "\nFiltered edges typed as\n"); if(filterInstances) { sb.append( "Class-Instance\n"); } if(filterOccurrences) { sb.append( "Occurrence\n"); } for(TopicNode n : filteredEdgeTypes) { sb.append(n.getLabel()).append( "\n"); } sb.append( "\n"); } else { sb.append("No edge types filtered\n"); } return sb.toString(); } }
7,984
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
TestEdge.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/TestEdge.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * TestEdge.java * * Created on 4.6.2007, 13:21 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package org.wandora.application.gui.topicpanels.graphpanel; import static org.wandora.utils.Tuples.t2; import org.wandora.utils.Tuples.T2; /** * * @author olli */ public class TestEdge extends AbstractEdge { private T2<Node,Node> nodes; /** Creates a new instance of TestEdge */ public TestEdge(Node a,Node b) { nodes=t2(a,b); } public T2<Node, Node> getNodes() { return nodes; } }
1,400
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
AssociationNode.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/AssociationNode.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * AssociationNode.java * * Created on 6.6.2007, 11:48 * */ package org.wandora.application.gui.topicpanels.graphpanel; import java.util.ArrayList; import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; import org.wandora.application.gui.topicstringify.TopicToString; import org.wandora.topicmap.Association; import org.wandora.topicmap.Topic; import org.wandora.topicmap.TopicMapException; /** * * @author olli */ public class AssociationNode extends AbstractNode { private Association association; private TopicMapModel model; private Collection<Edge> edges; private Map<Node,Edge> edgeMap; /** Creates a new instance of AssociationNode */ public AssociationNode(Association association, TopicMapModel model) throws TopicMapException { this.association=association; this.model=model; edgeMap=new LinkedHashMap<Node,Edge>(); edges=new ArrayList<Edge>(); for(Topic role : association.getRoles()){ Node roleNode=model.getNodeFor(role); Node playerNode=model.getNodeFor(association.getPlayer(role)); AssociationEdge e=new AssociationEdge(this,playerNode,role.getBaseName(),association,model); e.setBaseLength(25.0); edgeMap.put(roleNode,e); edges.add(e); } } public Association getAssociation(){ return association; } @Override public double getMass() { return massMultiplier * defaultMass / 2.0; } @Override public String getLabel() { try { return TopicToString.toString(association.getType()); } catch(Exception e) { return "-AN-"; } } public Edge getEdgeForRole(Node role){ return edgeMap.get(role); } public Collection<Edge> getEdges() { return edges; } @Override public boolean autoOpen(){ return true; } }
2,796
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
TopicNode.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/TopicNode.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * TopicNode.java * * Created on 5.6.2007, 15:18 * */ package org.wandora.application.gui.topicpanels.graphpanel; import java.util.ArrayList; import java.util.Collection; import java.util.Hashtable; import org.wandora.application.gui.topicstringify.TopicToString; import org.wandora.topicmap.Association; import org.wandora.topicmap.Topic; import org.wandora.topicmap.TopicMapException; import org.wandora.utils.Tuples.T2; /** * * @author olli */ public class TopicNode extends AbstractNode { private Topic topic; private TopicMapModel model; private Collection<Edge> edges; public static double edgeMassFactor = 10.0; /** Creates a new instance of TopicNode */ public TopicNode(Topic topic, TopicMapModel model) { this.topic=topic; this.model=model; } @Override public double getMass() { if(edges!=null) return massMultiplier * (defaultMass+edges.size()*edgeMassFactor); else return massMultiplier * defaultMass; } @Override public String getLabel() { return TopicToString.toString(topic); } public Topic getTopic(){ return topic; } @Override public Collection<Edge> getEdges() { if(edges==null) { edges=new ArrayList<>(); try{ for(Association a : topic.getAssociations()) { if(a.getRoles().size()==2) edges.add(model.getEdgeFor(a)); else { AssociationNode n=model.getNodeFor(a); for(Edge e : n.getEdges()){ T2<Node,Node> ns=e.getNodes(); if(ns.e1.equals(this)) edges.add(e); else if(ns.e2.equals(this)) edges.add(e); } } } for(Topic type : topic.getTypes()) { edges.add(model.getInstanceEdgeFor(type,topic)); } for(Topic instance : topic.getTopicMap().getTopicsOfType(topic)) { edges.add(model.getInstanceEdgeFor(topic,instance)); } for(Topic occurrenceType : topic.getDataTypes()) { Hashtable<Topic,String> occurrences = topic.getData(occurrenceType); for(Topic occurrenceScope : occurrences.keySet()) { String occurrence = occurrences.get(occurrenceScope); edges.add(model.getOccurrenceEdgeFor(topic,occurrenceType,occurrenceScope,occurrence)); } } } catch(TopicMapException tme){ tme.printStackTrace(); } } return edges; } @Override public String toString(){ return getLabel(); } }
3,679
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
NodeShape.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/NodeShape.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * NodeShape.java * * Created on 4.6.2007, 14:13 * */ package org.wandora.application.gui.topicpanels.graphpanel; /** * * @author olli */ public enum NodeShape { invisible, circle, triangle, rectangle, roundedRectangle, cutRectangle, skewedRectangle, }
1,086
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
VModel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/VModel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * VModel.java * * Created on 4.6.2007, 14:28 * */ package org.wandora.application.gui.topicpanels.graphpanel; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import org.wandora.utils.Tuples.T2; /** * * @author olli */ public class VModel { private GraphStyle graphStyle = null; private ArrayList<VNode> nodes; private ArrayList<VEdge> edges; private HashMap<Node,VNode> nodeMap; private HashMap<Edge,VEdge> edgeMap; private NodeFilter nodeFilter=null; private EdgeFilter edgeFilter=null; private HashSet<VNode> selectedNodes; private HashSet<VEdge> selectedEdges; private TopicMapGraphPanel panel; private HashMap<T2<VNode,VNode>,ArrayList<VEdge>> edgeClusters; /** Creates a new instance of VModel */ public VModel(TopicMapGraphPanel panel) { this.panel=panel; nodes=new ArrayList<VNode>(); edges=new ArrayList<VEdge>(); nodeMap=new HashMap<Node,VNode>(); edgeMap=new HashMap<Edge,VEdge>(); selectedNodes=new HashSet<VNode>(); selectedEdges=new HashSet<VEdge>(); edgeClusters=new HashMap<T2<VNode,VNode>,ArrayList<VEdge>>(); graphStyle = new DefaultGraphStyle(); } public TopicMapGraphPanel getPanel(){ return panel; } public Set<VNode> getSelectedNodes(){ return selectedNodes; } public Set<VEdge> getSelectedEdges(){ return selectedEdges; } public VNode getSelectedNode(){ if(selectedNodes.isEmpty()) return null; else return selectedNodes.iterator().next(); } public VEdge getSelectedEdge(){ if(selectedEdges.isEmpty()) return null; else return selectedEdges.iterator().next(); } public void deselectAllNodes(){ for(VNode vn : selectedNodes){ vn.selected=false; } selectedNodes.clear(); } public void deselectAllEdges(){ for(VEdge ve : selectedEdges){ ve.selected=false; } selectedEdges.clear(); } public void deselectAll(){ deselectAllNodes(); deselectAllEdges(); } public void addSelection(VEdge vedge){ vedge.selected=true; selectedEdges.add(vedge); } public void addSelection(VNode vnode){ vnode.selected=true; selectedNodes.add(vnode); } public void deselectNode(VNode vnode){ vnode.selected=false; selectedNodes.remove(vnode); } public void deselectEdge(VEdge vedge){ vedge.selected=false; selectedEdges.remove(vedge); } public void deselectNodes(Collection<VNode> vnodes){ for(VNode vn : vnodes) deselectNode(vn); } public void deselectEdges(Collection<VEdge> vedges){ for(VEdge ve : vedges) deselectEdge(ve); } public void setSelection(VNode vnode){ deselectAll(); addSelection(vnode); } public void setSelection(VEdge vedge){ deselectAll(); addSelection(vedge); } public VNode getNode(Node n){ return nodeMap.get(n); } public VEdge getEdge(Edge e){ return edgeMap.get(e); } public ArrayList<VNode> getNodes(){ return nodes; } public ArrayList<VEdge> getEdges(){ return edges; } public Collection<ArrayList<VEdge>> getEdgeClusters(){ return edgeClusters.values(); } public VNode addNode(Node n){ return addNode(n,0.0,0.0); } private void setEdgeClusterCurvatures(ArrayList<VEdge> cluster){ double c=-edgeCurvatureDelta/2.0*(cluster.size()-1); for(VEdge e : cluster){ e.curvature=c; c+=edgeCurvatureDelta; } } private int nodeCounter=0; private static double edgeCurvatureDelta=20.0; public VNode addNode(Node n, double x, double y){ VNode vn=nodeMap.get(n); if(vn!=null) return vn; vn=new VNode(n,this,nodeCounter++); vn.x=x; vn.y=y; nodes.add(vn); nodeMap.put(n,vn); return vn; } public VEdge addEdge(Edge e){ VEdge ve=edgeMap.get(e); if(ve!=null) return ve; ve=new VEdge(e,this); T2<VNode,VNode> ns=ve.getNodes(); ns.e1.addEdge(ve); ns.e2.addEdge(ve); edges.add(ve); edgeMap.put(e,ve); ArrayList<VEdge> cluster=edgeClusters.get(ns); if(cluster!=null){ cluster.add(ve); setEdgeClusterCurvatures(cluster); } else{ for(VEdge ve2 : edges){ if(ve2==ve) continue; if(ve2.getNodes().equals(ns)){ cluster=new ArrayList<VEdge>(); cluster.add(ve2); cluster.add(ve); ve2.curvature=-edgeCurvatureDelta/2.0; ve.curvature=edgeCurvatureDelta/2.0; edgeClusters.put(ns,cluster); break; } } } return ve; } public void removeNode(VNode n){ nodes.remove(n); nodeMap.remove(n.getNode()); ArrayList<VEdge> remove=new ArrayList<VEdge>(); for(VEdge edge : edges){ T2<VNode,VNode> ns=edge.getNodes(); if(ns.e1.equals(n) || ns.e2.equals(n)) remove.add(edge); } for(VEdge edge : remove){ removeEdge(edge); } } public void removeEdge(VEdge e){ ArrayList<VEdge> cluster=edgeClusters.get(e.getNodes()); if(cluster!=null){ if(cluster.size()<=2) { edgeClusters.remove(e.getNodes()); for(VEdge ve : cluster) ve.curvature=0.0; } else { cluster.remove(e); setEdgeClusterCurvatures(cluster); } } edges.remove(e); edgeMap.remove(e.getEdge()); T2<VNode,VNode> ns=e.getNodes(); ns.e1.removeEdge(e); ns.e2.removeEdge(e); } public void connectNode(VNode vn){ for(Edge e : vn.getNode().getEdges()){ T2<Node,Node> ns=e.getNodes(); VNode n1=nodeMap.get(ns.e1); VNode n2=nodeMap.get(ns.e2); if(n1==null || n2==null) continue; if(edgeFilter==null || !edgeFilter.isEdgeFiltered(e)){ addEdge(e); } } } public void connectAllNodes(){ for(VNode n : nodes){ connectNode(n); } } public void collapseNode(VNode vn){ HashSet<VNode> remove=new HashSet<VNode>(); for(VEdge edge : vn.getEdges()){ T2<VNode,VNode> ns=edge.getNodes(); VNode other=null; if(ns.e1.equals(vn)) other=ns.e2; else if(ns.e2.equals(vn)) other=ns.e1; if(other.edgeCount<=1) remove.add(other); } for(VNode n : remove) removeNode(n); } public void openNode(VNode vn){ if(vn==null) return; Node n=vn.getNode(); Collection<Edge> edges=n.getEdges(); for(Edge e : edges){ if(edgeFilter==null || !edgeFilter.isEdgeFiltered(e)){ if(edgeMap.get(e)!=null) continue; T2<Node,Node> nodes=e.getNodes(); Node other=nodes.e1; if(other==n) other=nodes.e2; if(nodeFilter==null || !nodeFilter.isNodeFiltered(other)){ double a=2.0*Math.PI*Math.random(); VNode newNode=addNode(other,vn.x+Math.cos(a)*100.0,vn.y+Math.sin(a)*100.0); addEdge(e); connectNode(newNode); if(newNode.getNode().autoOpen()) openNode(newNode); } } } } public void openNode(Node n){ openNode(nodeMap.get(n)); } public NodeFilter setNodeFilter(NodeFilter f){ NodeFilter old=nodeFilter; nodeFilter=f; return old; } public EdgeFilter setEdgeFilter(EdgeFilter f){ EdgeFilter old=edgeFilter; edgeFilter=f; return old; } // --------------------------------------------------------- GRAPH STYLE --- public GraphStyle getGraphStyle() { return graphStyle; } public void setGraphStyle(GraphStyle style) { if(style == null) { graphStyle = new DefaultGraphStyle(); } else { this.graphStyle = style; } for(Iterator<VNode>iter = nodes.iterator(); iter.hasNext(); ) { iter.next().setGraphStyle(style); } for(Iterator<VEdge>iter = edges.iterator(); iter.hasNext(); ) { iter.next().setGraphStyle(style); } } }
9,851
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
AbstractNode.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/AbstractNode.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * AbstractNode.java * * Created on 6.6.2007, 11:45 * */ package org.wandora.application.gui.topicpanels.graphpanel; /** * * @author olli */ public abstract class AbstractNode implements Node { public static double defaultMass = 100.0; public static double massMultiplier = 1.0; @Override public double getMass() { return massMultiplier * defaultMass; } @Override public String getLabel() { return null; } @Override public boolean autoOpen(){ return false; } }
1,369
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
InstanceEdge.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/InstanceEdge.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * InstanceEdge.java * * Created on 16.7.2007, 10:55 * */ package org.wandora.application.gui.topicpanels.graphpanel; import static org.wandora.utils.Tuples.t2; import org.wandora.topicmap.Topic; import org.wandora.utils.Tuples.T2; /** * * @author olli */ public class InstanceEdge extends AbstractEdge { private TopicMapModel model; private T2<Node,Node> nodes; private T2<String,String> nodeLabels; private Topic type; private Topic instance; private double baseLength=50.0; public InstanceEdge(Topic type, Topic instance, TopicMapModel model) { this.model=model; this.type=type; this.instance=instance; nodeLabels=t2("Class","Instance"); nodes=t2((Node)model.getNodeFor(type), (Node)model.getNodeFor(instance)); } public Topic getType(){ return type; } public Topic getInstance(){ return instance; } @Override public String getLabel(){ return "Class-Instance"; } @Override public T2<String,String> getNodeLabels(){ return nodeLabels; } public T2<Node, Node> getNodes() { return nodes; } public void setBaseLength(double l){ baseLength=l; } @Override public double getLength() { return baseLength+(nodes.e1.getMass()+nodes.e2.getMass())/4.0; } }
2,241
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
MouseToolManager.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/MouseToolManager.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * MouseToolManager.java * * Created on 25.6.2007, 11:24 * */ package org.wandora.application.gui.topicpanels.graphpanel; import java.awt.Cursor; import java.awt.Graphics2D; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.util.ArrayList; /** * * @author olli */ public class MouseToolManager implements MouseListener, MouseMotionListener { public static final int EVENT_LEFTCLICK=1; public static final int EVENT_RIGHTCLICK=2; public static final int EVENT_LEFTDOUBLECLICK=4; public static final int EVENT_RIGHTDOUBLECLICK=8; public static final int EVENT_LEFTPRESS=16; public static final int EVENT_RIGHTPRESS=32; public static final int EVENT_LEFTRELEASE=64; public static final int EVENT_RIGHTRELEASE=128; public static final int EVENT_DRAG=256; public static final int EVENT_MOVE=512; public static final int EVENTS_LEFTDRAG=EVENT_LEFTPRESS|EVENT_DRAG|EVENT_LEFTRELEASE; public static final int EVENTS_RIGHTDRAG=EVENT_RIGHTPRESS|EVENT_DRAG|EVENT_RIGHTRELEASE; public static final int MASK_SHIFT=MouseEvent.SHIFT_MASK; public static final int MASK_CONTROL=MouseEvent.CTRL_MASK; private ArrayList<StackEntry> toolStack; private MouseTool lockedTool; private TopicMapGraphPanel panel; /** Creates a new instance of MouseToolManager */ public MouseToolManager(TopicMapGraphPanel panel) { this.panel=panel; clearToolStack(); } public void addTool(int events,MouseTool tool){ addTool(events,0,tool); } public void addTool(int events,int modifiers,MouseTool tool){ toolStack.add(new StackEntry(events,modifiers,tool)); } public boolean lockTool(MouseTool tool){ if(lockedTool==null){ lockedTool=tool; updateCursor(0,-1,-1); return true; } else { return false; } } public void releaseLockedTool(){ lockedTool=null; updateCursor(0,-1,-1); } public void clearToolStack(){ toolStack=new ArrayList<StackEntry>(); } public void updateCursor(int modifiers,int x,int y){ if(lockedTool!=null){ Cursor cursor=lockedTool.getCursor(panel,x,y); if(cursor!=null) panel.updateCursor(cursor); else panel.updateCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); return; } for(StackEntry tool : toolStack){ if( (modifiers&(MASK_SHIFT)) == tool.modifiers ){ Cursor cursor=tool.tool.getCursor(panel,x,y); if(cursor!=null) { panel.updateCursor(cursor); return; } } } panel.updateCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } public void paint(Graphics2D g2){ for(StackEntry tool : toolStack){ tool.tool.paint(g2,panel); } } private boolean dispatchEvent(MouseEvent e,int event,MouseTool tool){ boolean processed=false; synchronized(panel){ switch(event){ case EVENT_LEFTCLICK: case EVENT_RIGHTCLICK: case EVENT_LEFTDOUBLECLICK: case EVENT_RIGHTDOUBLECLICK: processed=tool.mouseClicked(panel,e.getX(),e.getY()); break; case EVENT_LEFTPRESS: case EVENT_RIGHTPRESS: processed=tool.mousePressed(panel,e.getX(),e.getY()); break; case EVENT_LEFTRELEASE: case EVENT_RIGHTRELEASE: processed=tool.mouseReleased(panel,e.getX(),e.getY()); break; case EVENT_DRAG: processed=tool.mouseDragged(panel,e.getX(),e.getY()); break; case EVENT_MOVE: processed=tool.mouseMoved(panel,e.getX(),e.getY()); break; } } return processed; } public void processEvent(MouseEvent e,int event){ int modifiers=e.getModifiers(); if(lockedTool!=null){ dispatchEvent(e,event,lockedTool); return; } for(StackEntry tool : toolStack){ if( (tool.events&event)!=0 ){ if( (modifiers&(MASK_SHIFT)) == tool.modifiers ){ if(dispatchEvent(e,event,tool.tool)) break; } } } } public void mouseReleased(MouseEvent e) { boolean ctrl=((e.getModifiers()&MouseEvent.CTRL_MASK)!=0); if(e.getButton()==1 && !ctrl) processEvent(e,EVENT_LEFTRELEASE); else if(e.getButton()==3 || ctrl) processEvent(e,EVENT_RIGHTRELEASE); } public void mousePressed(MouseEvent e) { boolean ctrl=((e.getModifiers()&MouseEvent.CTRL_MASK)!=0); if(e.getButton()==1 && !ctrl) processEvent(e,EVENT_LEFTPRESS); else if(e.getButton()==3 || ctrl) processEvent(e,EVENT_RIGHTPRESS); } public void mouseExited(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseClicked(MouseEvent e) { boolean ctrl=((e.getModifiers()&MouseEvent.CTRL_MASK)!=0); if(e.getClickCount()>=2){ if(e.getButton()==1 && !ctrl) processEvent(e,EVENT_LEFTDOUBLECLICK); else if(e.getButton()==3 || ctrl) processEvent(e,EVENT_RIGHTDOUBLECLICK); } else{ if(e.getButton()==1 && !ctrl) processEvent(e,EVENT_LEFTCLICK); else if(e.getButton()==3 || ctrl) processEvent(e,EVENT_RIGHTCLICK); } } public void mouseMoved(MouseEvent e) { processEvent(e,EVENT_MOVE); } public void mouseDragged(MouseEvent e) { processEvent(e,EVENT_DRAG); } private static class StackEntry { public int events; public int modifiers; public MouseTool tool; public int getEvents() { return events; } public StackEntry(int events,int modifiers, MouseTool tool){ this.events=events; this.modifiers=modifiers; this.tool=tool; } } }
7,191
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
Edge.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/Edge.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * Edge.java * * Created on 4.6.2007, 12:29 * */ package org.wandora.application.gui.topicpanels.graphpanel; import org.wandora.utils.Tuples.T2; /** * * @author olli */ public interface Edge { public T2<Node,Node> getNodes(); public T2<String,String> getNodeLabels(); public String getLabel(); public double getLength(); public double getStiffness(); }
1,213
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
NodeFilter.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/NodeFilter.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * NodeFilter.java * * Created on 6.6.2007, 15:49 * */ package org.wandora.application.gui.topicpanels.graphpanel; /** * * @author olli */ public interface NodeFilter { public boolean isNodeFiltered(Node n); }
1,034
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
OccurrenceNode.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/OccurrenceNode.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * OccurrenceNode.java * * Created on 5.6.2007, 15:18 * */ package org.wandora.application.gui.topicpanels.graphpanel; import java.util.ArrayList; import java.util.Collection; import org.wandora.topicmap.Topic; /** * * @author akivela */ public class OccurrenceNode extends AbstractNode { public static int MAX_LABEL_LEN = 60; private Topic carrier; private Topic type; private Topic scope; private String occurrence; private TopicMapModel model; private Collection<Edge> edges; private String label; /** Creates a new instance of OccurrenceNode */ public OccurrenceNode(Topic carrier, Topic type, Topic scope, String occurrence, TopicMapModel model) { this.occurrence = occurrence; this.carrier = carrier; this.type = type; this.scope = scope; this.model = model; if(occurrence != null && occurrence.length() > MAX_LABEL_LEN) { this.label = occurrence.substring(0, MAX_LABEL_LEN)+"..."; } else { this.label = occurrence; } } public Topic getCarrier() { return carrier; } public Topic getType() { return type; } public Topic getScope() { return scope; } public String getOccurrence() { return occurrence; } @Override public double getMass() { return massMultiplier * defaultMass / 4.0; } @Override public String getLabel() { return label; } @Override public Collection<Edge> getEdges() { if(edges == null) { edges = new ArrayList<>(); edges.add(model.getOccurrenceEdgeFor(carrier, type, scope, occurrence)); } return edges; } @Override public String toString(){ return getLabel(); } }
2,684
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
AbstractEdge.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/AbstractEdge.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * AbstractEdge.java * * Created on 6.6.2007, 11:45 * */ package org.wandora.application.gui.topicpanels.graphpanel; import org.wandora.utils.Tuples.T2; /** * * @author olli */ public abstract class AbstractEdge implements Edge { public static double defaultEdgeStiffness = 0.1; public static double defaultEdgeLength = 50.0; public static double defaultEdgeWidth = 2.0; @Override public String getLabel(){ return null; } @Override public T2<String,String> getNodeLabels(){ return null; } @Override public double getStiffness() { return defaultEdgeStiffness; } @Override public double getLength() { return defaultEdgeLength; } public double getEdgeWidth() { return defaultEdgeWidth; } }
1,649
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
Node.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/Node.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * Node.java * * Created on 4.6.2007, 12:28 * */ package org.wandora.application.gui.topicpanels.graphpanel; import java.util.Collection; /** * * @author olli */ public interface Node { public Collection<Edge> getEdges(); public double getMass(); public String getLabel(); public boolean autoOpen(); }
1,165
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
MoveViewMouseTool.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/MoveViewMouseTool.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * MoveViewMouseTool.java * * Created on 25.6.2007, 10:41 * */ package org.wandora.application.gui.topicpanels.graphpanel; import java.awt.Cursor; import org.wandora.utils.Tuples.T2; /** * * @author olli */ public class MoveViewMouseTool extends MouseTool { private boolean draggingView=false; private double dragOffsX,dragOffsY,dragOffsX2,dragOffsY2; /** Creates a new instance of MoveViewMouseTool */ public MoveViewMouseTool() { } public boolean mouseReleased(TopicMapGraphPanel panel, int mousex,int mousey) { if(draggingView){ panel.releaseMouseTool(); draggingView=false; return true; } else return false; } public boolean mousePressed(TopicMapGraphPanel panel, int mousex,int mousey) { if(panel.lockMouseTool(this)){ draggingView=true; T2<Double,Double> m=panel.getMouseWorldCoordinates(); T2<Double,Double> v=panel.getViewCoordinates(); dragOffsX=v.e1; dragOffsY=v.e2; dragOffsX2=m.e1; dragOffsY2=m.e2; return true; } return false; } public boolean mouseDragged(TopicMapGraphPanel panel, int mousex,int mousey) { if(draggingView){ panel.setMouseFollowNode(null); T2<Double,Double> m=panel.getMouseWorldCoordinates(); double viewX=dragOffsX+(dragOffsX2-m.e1); double viewY=dragOffsY+(dragOffsY2-m.e2); panel.setViewCoordinates(viewX,viewY); panel.updateMouseWorldCoordinates(mousex,mousey); m=panel.getMouseWorldCoordinates(); dragOffsX=viewX; dragOffsY=viewY; dragOffsX2=m.e1; dragOffsY2=m.e2; return true; } return false; } public Cursor getCursor(TopicMapGraphPanel panel, int mousex, int mousey){ return Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR); } }
2,832
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
DefaultGraphStyle.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/DefaultGraphStyle.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * DefaultGraphStyle.java * * Created on 12.7.2007, 11:40 * */ package org.wandora.application.gui.topicpanels.graphpanel; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.Stroke; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import org.wandora.topicmap.Association; import org.wandora.topicmap.Topic; import org.wandora.topicmap.TopicMapException; /** * * @author akivela */ public class DefaultGraphStyle implements GraphStyle { private static Color defaultNodeColor = Color.GRAY; private static Color defaultEdgeColor = Color.GRAY; private static Color selectedNodeColor = new Color(200,221,242); private static Color currentNodeColor = new Color(255,255,255); private static Stroke defaultNodeBorderStroke = new BasicStroke(1); private static Stroke defaultPinnedNodeBorderStroke = new BasicStroke(2); private static HashMap<Integer,Font> nodeFonts=new HashMap<Integer,Font>(); private static HashMap<Integer,Font> edgeFonts=new HashMap<Integer,Font>(); private static Stroke defaultEdgeLabelStroke = new BasicStroke(1); private static HashMap<Integer,Stroke> edgeStrokes=new HashMap<Integer,Stroke>(); private static HashMap<Integer,Stroke> occurrenceEdgeStrokes=new HashMap<Integer,Stroke>(); private static Color[] colors; static { int step=64; ArrayList<Color> cs=new ArrayList<>(); int counter=0; for(int r=0;r<=256;r+=step){ for(int g=0;g<=256;g+=step){ for(int b=0;b<=256;b+=step){ double s=Math.sqrt(r*r+g*g+b*b); if(s<300 || s>367) continue; // 0... 368 cs.add(new Color(r==256?255:r,g==256?255:g,b==256?255:b)); } } } colors=cs.toArray(new Color[cs.size()]); } private Map<Topic,Color> topicColors = new LinkedHashMap<Topic,Color>(); /** Creates a new instance of DefaultGraphStyle */ public DefaultGraphStyle() { } // ------------------------------------------------------------------------- /* * public Color getNodeColor(){ if(nodeColor==null){ try{ Collection<Topic> types=topic.getTypes(); if(types.size()==0) nodeColor=Color.GRAY; else nodeColor=model.getTypeColorForTopic(types.iterator().next()); }catch(TopicMapException tme){tme.printStackTrace();} } return nodeColor; } **/ @Override public Color getNodeColor(VNode vn) { Color c = defaultNodeColor; if(vn.selected) c = this.selectedNodeColor; else { c = getNodeColor(vn.getNode()); } if(vn.mouseOver) { c = c.brighter(); } return c; } public Color getNodeColor(Node n) { if(n instanceof TopicNode) { return getNodeColor((TopicNode) n); } else if(n instanceof OccurrenceNode) { return getNodeColor((OccurrenceNode) n); } else { return defaultNodeColor; } } public Color getNodeColor(TopicNode n) { Topic t = n.getTopic(); Color c=topicColors.get(t); if(c==null){ try { c = getTypeTopicColor(t); } catch(TopicMapException tme) { tme.printStackTrace(); return Color.GRAY; } } return c; } public Color getNodeColor(OccurrenceNode n) { try { Topic t = n.getScope(); return getTopicColor(t); } catch(Exception tme) { tme.printStackTrace(); } return Color.GRAY; } private Color getTypeTopicColor(Topic t) throws TopicMapException { Collection<Topic> types=t.getTypes(); if(types.isEmpty()) return Color.GRAY; Topic type=types.iterator().next(); return getTopicColor(type); } private Color getTopicColor(Topic t) throws TopicMapException { if(t==null) return Color.GRAY; int hash=Math.abs(t.hashCode()); Color c=colors[hash%colors.length]; topicColors.put(t, c); return c; } @Override public Color getNodeTextColor(VNode vn) { return getNodeTextColor(vn.getNode()); } public Color getNodeTextColor(Node n) { return Color.BLACK; } @Override public NodeShape getNodeShape(VNode vn) { return getNodeShape(vn.getNode()); } public NodeShape getNodeShape(Node n) { return NodeShape.rectangle; } public NodeShape getNodeShape(AssociationNode n) { return NodeShape.invisible; } @Override public double getNodeWidth(VNode vn) { double w = getNodeWidth(vn.getNode()); if(vn.mouseOver) w *= 1.5; return w; } public double getNodeWidth(Node n) { return 80.0; } @Override public double getNodeHeight(VNode vn) { return getNodeHeight(vn.getNode()); } public double getNodeHeight(Node n) { return 20.0; } @Override public Color getNodeBorderColor(VNode vn) { if(vn.isSelected()) return Color.BLACK; if(vn.isPinned()) return Color.BLACK; return getNodeBorderColor(vn.getNode()); } public Color getNodeBorderColor(Node n) { return Color.GRAY; } @Override public Stroke getNodeBorderStroke(VNode vn) { if(vn.isPinned()) return defaultPinnedNodeBorderStroke; return getNodeBorderStroke(vn.getNode()); } public Stroke getNodeBorderStroke(Node n) { return defaultNodeBorderStroke; } @Override public int getNodeFontSize(VNode vn) { return getNodeFontSize(vn.getNode()); } public int getNodeFontSize(Node n) { if(n instanceof OccurrenceNode) { return 10; } return 12; } @Override public Font getNodeFont(VNode vn, int forSize) { return getNodeFont(vn.getNode(), forSize); } public Font getNodeFont(Node n, int forSize) { Font f=nodeFonts.get(forSize); if(f==null){ f=new Font(Font.SANS_SERIF,Font.PLAIN,forSize); nodeFonts.put(forSize,f); } return f; } @Override public Color getEdgeColor(VEdge ve) { return getEdgeColor(ve.getEdge()); } public Color getEdgeColor(Edge e) { if(e instanceof AssociationEdge) { return getEdgeColor((AssociationEdge) e); } else if(e instanceof OccurrenceEdge) { return getEdgeColor((OccurrenceEdge) e); } else { return defaultEdgeColor; } } public Color getEdgeColor(OccurrenceEdge e) { Color c = defaultEdgeColor; try { Topic t = e.getType(); c = getTopicColor(t); c = c.darker(); c = c.darker(); } catch(Exception ex) { ex.printStackTrace(); } return c; } public Color getEdgeColor(AssociationEdge e) { Color c = defaultEdgeColor; try { Association a = e.getAssociation(); Topic t = a.getType(); c = getTopicColor(t); c = c.darker(); c = c.darker(); } catch(Exception ex) { ex.printStackTrace(); } return c; } @Override public double getEdgeWidth(VEdge ve) { return getEdgeWidth(ve.getEdge()); } public double getEdgeWidth(Edge e) { if(e instanceof OccurrenceEdge) { return 1.5; } return 2.0; } @Override public int getEdgeLabelFontSize(VEdge ve) { return getEdgeLabelFontSize(ve.getEdge()); } public int getEdgeLabelFontSize(Edge n) { return 12; } @Override public Font getEdgeLabelFont(VEdge ve, int forSize) { return getEdgeLabelFont(ve.getEdge(), forSize); } public Font getEdgeLabelFont(Edge n, int forSize) { Font f=edgeFonts.get(forSize); if(f==null){ f=new Font(Font.SANS_SERIF,Font.PLAIN,forSize); edgeFonts.put(forSize,f); } return f; } @Override public Color getEdgeLabelColor(VEdge ve) { return Color.BLACK; } @Override public Stroke getEdgeLabelStroke(VEdge ve) { return defaultEdgeLabelStroke; } @Override public Stroke getEdgeStroke(VEdge ve, int forWidth) { if(forWidth==0) forWidth=1; if(ve.mouseOver) forWidth*=2; Edge e = ve.getEdge(); if(e instanceof OccurrenceEdge) { Stroke stroke = occurrenceEdgeStrokes.get(forWidth); if(stroke == null) { stroke=new BasicStroke(forWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 2f, new float[] { 2f,2f }, 0f ); occurrenceEdgeStrokes.put(forWidth, stroke); } return stroke; } else { Stroke stroke=edgeStrokes.get(forWidth); if(stroke==null){ stroke=new BasicStroke(forWidth); edgeStrokes.put(forWidth,stroke); } return stroke; } } }
10,468
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
EdgeFilter.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/EdgeFilter.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * EdgeFilter.java * * Created on 6.6.2007, 15:50 * */ package org.wandora.application.gui.topicpanels.graphpanel; /** * * @author olli */ public interface EdgeFilter { public boolean isEdgeFiltered(Edge e); }
1,034
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
FilterManagerPanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/FilterManagerPanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * FilterManagerPanel.java * * Created on 29.6.2007, 14:01 */ package org.wandora.application.gui.topicpanels.graphpanel; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.DefaultListModel; import javax.swing.JDialog; import javax.swing.JMenuBar; import javax.swing.JSeparator; import org.wandora.application.Wandora; import org.wandora.application.gui.simple.SimpleButton; import org.wandora.application.gui.simple.SimpleMenu; import org.wandora.application.gui.simple.SimpleMenuItem; /** * * @author olli */ public class FilterManagerPanel extends javax.swing.JPanel implements ActionListener { private static final long serialVersionUID = 1L; private Wandora wandora = null; private DefaultListModel<TopicNode> filteredTopicsModel; private DefaultListModel<TopicNode> filteredTopicTypesModel; private DefaultListModel<Object> filteredAssociationTypesModel; // NEAR <TopicNode> private GraphFilter topicNodeFilter; /** Creates new form FilterManagerPanel */ public FilterManagerPanel(Wandora wandora) { filteredTopicsModel=new DefaultListModel<>(); filteredTopicTypesModel=new DefaultListModel<>(); filteredAssociationTypesModel=new DefaultListModel<>(); initComponents(); } public void refreshAll(){ refreshTopicList(); refreshTopicTypeList(); refreshAssociationTypeList(); } JDialog filterDialog = null; public JDialog getDialogForMe(Wandora wandora) { if(filterDialog == null) { filterDialog = new JDialog(wandora, false); filterDialog.setLayout(new BorderLayout()); filterDialog.setSize(300, 400); filterDialog.setTitle("Graph Filter Manager"); filterDialog.setJMenuBar(getMenuBar(wandora)); if(wandora != null) wandora.centerWindow(filterDialog); } filterDialog.add(this, BorderLayout.CENTER); filterDialog.add(footerPanel, BorderLayout.SOUTH); return filterDialog; } public JMenuBar getMenuBar(Wandora admin) { JMenuBar filterManagerMenuBar = new JMenuBar(); SimpleMenu fileMenu = new SimpleMenu("File"); fileMenu.addActionListener(this); fileMenu.add( new SimpleMenuItem("New set", this ) ); fileMenu.add( new SimpleMenuItem("Load set", this) ); fileMenu.add( new SimpleMenuItem("Save set", this) ); fileMenu.add( new JSeparator(JSeparator.HORIZONTAL) ); fileMenu.add( new SimpleMenuItem("Clear set", this) ); fileMenu.add( new JSeparator(JSeparator.HORIZONTAL) ); fileMenu.add( new SimpleMenuItem("Exit", this) ); filterManagerMenuBar.add(fileMenu); return filterManagerMenuBar; } public void setTopicNodeFilter(GraphFilter topicNodeFilter){ this.topicNodeFilter=topicNodeFilter; refreshAll(); } private void refreshTopicList(){ filteredTopicsModel.clear(); for(TopicNode tn : topicNodeFilter.getFilteredNodes()){ filteredTopicsModel.addElement(tn); } } private void refreshTopicTypeList(){ filteredTopicTypesModel.clear(); for(TopicNode tn : topicNodeFilter.getFilteredNodeTypes()){ filteredTopicTypesModel.addElement(tn); } } private void refreshAssociationTypeList(){ filteredAssociationTypesModel.clear(); for(TopicNode tn : topicNodeFilter.getFilteredEdgeTypes()){ filteredAssociationTypesModel.addElement(tn); } if(topicNodeFilter.getFilterInstances()){ filteredAssociationTypesModel.addElement("Instances"); } if(topicNodeFilter.getFilterOccurrences()){ filteredAssociationTypesModel.addElement("Occurrences"); } } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; footerPanel = new javax.swing.JPanel(); jSeparator2 = new javax.swing.JSeparator(); okButton = new org.wandora.application.gui.simple.SimpleButton(); jPanel4 = new javax.swing.JPanel(); jPanel3 = new javax.swing.JPanel(); jComboBox1 = new org.wandora.application.gui.simple.SimpleComboBox(); jSeparator1 = new javax.swing.JSeparator(); jPanel1 = new javax.swing.JPanel(); jLabel1 = new org.wandora.application.gui.simple.SimpleLabel(); jScrollPane1 = new javax.swing.JScrollPane(); filteredTopicList = new javax.swing.JList(); removeFilteredTopicButton = new SimpleButton(); jPanel2 = new javax.swing.JPanel(); jLabel3 = new org.wandora.application.gui.simple.SimpleLabel(); jScrollPane3 = new javax.swing.JScrollPane(); filteredAssociationTypesList = new javax.swing.JList(); removeFilteredAssociationTypeButton = new SimpleButton(); footerPanel.setLayout(new java.awt.GridBagLayout()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(9, 5, 5, 5); footerPanel.add(jSeparator2, gridBagConstraints); okButton.setText("Ok"); okButton.setMaximumSize(new java.awt.Dimension(70, 21)); okButton.setMinimumSize(new java.awt.Dimension(70, 21)); okButton.setPreferredSize(new java.awt.Dimension(70, 21)); okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { okButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); footerPanel.add(okButton, gridBagConstraints); setLayout(new java.awt.GridBagLayout()); jPanel4.setLayout(new java.awt.GridBagLayout()); jPanel3.setLayout(new java.awt.GridBagLayout()); jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(9, 5, 0, 5); jPanel3.add(jComboBox1, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; jPanel4.add(jPanel3, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(10, 5, 10, 5); jPanel4.add(jSeparator1, gridBagConstraints); jPanel1.setLayout(new java.awt.GridBagLayout()); jLabel1.setText("Filtered nodes"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); jPanel1.add(jLabel1, gridBagConstraints); filteredTopicList.setModel(filteredTopicsModel); jScrollPane1.setViewportView(filteredTopicList); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5); jPanel1.add(jScrollPane1, gridBagConstraints); removeFilteredTopicButton.setText("Unfilter node"); removeFilteredTopicButton.setMargin(new java.awt.Insets(2, 6, 2, 6)); removeFilteredTopicButton.setMaximumSize(new java.awt.Dimension(95, 21)); removeFilteredTopicButton.setMinimumSize(new java.awt.Dimension(95, 21)); removeFilteredTopicButton.setPreferredSize(new java.awt.Dimension(95, 21)); removeFilteredTopicButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { removeFilteredTopicButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5); jPanel1.add(removeFilteredTopicButton, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; jPanel4.add(jPanel1, gridBagConstraints); jPanel2.setLayout(new java.awt.GridBagLayout()); jLabel3.setText("Filtered edge types"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); jPanel2.add(jLabel3, gridBagConstraints); filteredAssociationTypesList.setModel(filteredAssociationTypesModel); jScrollPane3.setViewportView(filteredAssociationTypesList); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5); jPanel2.add(jScrollPane3, gridBagConstraints); removeFilteredAssociationTypeButton.setText("Unfilter type"); removeFilteredAssociationTypeButton.setMargin(new java.awt.Insets(2, 6, 2, 6)); removeFilteredAssociationTypeButton.setMaximumSize(new java.awt.Dimension(95, 21)); removeFilteredAssociationTypeButton.setMinimumSize(new java.awt.Dimension(95, 21)); removeFilteredAssociationTypeButton.setPreferredSize(new java.awt.Dimension(95, 21)); removeFilteredAssociationTypeButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { removeFilteredAssociationTypeButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5); jPanel2.add(removeFilteredAssociationTypeButton, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; jPanel4.add(jPanel2, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0); add(jPanel4, gridBagConstraints); }// </editor-fold>//GEN-END:initComponents private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed if(filterDialog != null) { filterDialog.setVisible(false); } }//GEN-LAST:event_okButtonActionPerformed private void removeFilteredAssociationTypeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeFilteredAssociationTypeButtonActionPerformed Object sel=filteredAssociationTypesList.getSelectedValue(); if(sel!=null){ if(sel instanceof TopicNode){ topicNodeFilter.releaseEdgeType((TopicNode)sel); refreshAssociationTypeList(); } else if(sel.equals("Instances")){ topicNodeFilter.setFilterInstances(false); refreshAssociationTypeList(); } } }//GEN-LAST:event_removeFilteredAssociationTypeButtonActionPerformed private void removeFilteredTopicButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeFilteredTopicButtonActionPerformed Object sel=filteredTopicList.getSelectedValue(); if(sel!=null){ topicNodeFilter.releaseNode((TopicNode)sel); refreshTopicList(); } }//GEN-LAST:event_removeFilteredTopicButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JList filteredAssociationTypesList; private javax.swing.JList filteredTopicList; private javax.swing.JPanel footerPanel; private javax.swing.JComboBox jComboBox1; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel3; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel4; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JSeparator jSeparator1; private javax.swing.JSeparator jSeparator2; private javax.swing.JButton okButton; private javax.swing.JButton removeFilteredAssociationTypeButton; private javax.swing.JButton removeFilteredTopicButton; // End of variables declaration//GEN-END:variables // ----------------------------------------------------- ACTION LISTENER --- public void actionPerformed(ActionEvent actionEvent) { System.out.println("Action preformed in FilterManagerPanel: "+actionEvent.getActionCommand()); String ac = actionEvent.getActionCommand(); if("Exit".equalsIgnoreCase(ac)) { if(filterDialog != null) { filterDialog.setVisible(false); } } } }
16,180
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
GraphOptionsPanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/GraphOptionsPanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * GraphOptionsPanel.java * * Created on Nov 22, 2011, 9:46:15 PM */ package org.wandora.application.gui.topicpanels.graphpanel; /** * * @author akivela */ public class GraphOptionsPanel extends javax.swing.JPanel { private static final long serialVersionUID = 1L; /** Creates new form GraphOptionsPanel */ public GraphOptionsPanel() { initComponents(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; jTabbedPane = new javax.swing.JTabbedPane(); drawTab = new javax.swing.JPanel(); jPanel1 = new javax.swing.JPanel(); animateTab = new javax.swing.JPanel(); buttonPanel = new javax.swing.JPanel(); buttonFillerPanel = new javax.swing.JPanel(); okButton = new javax.swing.JButton(); setLayout(new java.awt.GridBagLayout()); drawTab.setLayout(new java.awt.GridBagLayout()); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 100, Short.MAX_VALUE) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 100, Short.MAX_VALUE) ); drawTab.add(jPanel1, new java.awt.GridBagConstraints()); jTabbedPane.addTab("Draw", drawTab); animateTab.setLayout(new java.awt.GridBagLayout()); jTabbedPane.addTab("Animate", animateTab); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; add(jTabbedPane, gridBagConstraints); buttonPanel.setLayout(new java.awt.GridBagLayout()); buttonFillerPanel.setPreferredSize(new java.awt.Dimension(5, 5)); javax.swing.GroupLayout buttonFillerPanelLayout = new javax.swing.GroupLayout(buttonFillerPanel); buttonFillerPanel.setLayout(buttonFillerPanelLayout); buttonFillerPanelLayout.setHorizontalGroup( buttonFillerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 406, Short.MAX_VALUE) ); buttonFillerPanelLayout.setVerticalGroup( buttonFillerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 5, Short.MAX_VALUE) ); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; buttonPanel.add(buttonFillerPanel, gridBagConstraints); okButton.setText("OK"); okButton.setMinimumSize(new java.awt.Dimension(70, 23)); okButton.setPreferredSize(new java.awt.Dimension(70, 23)); buttonPanel.add(okButton, new java.awt.GridBagConstraints()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; add(buttonPanel, gridBagConstraints); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JPanel animateTab; private javax.swing.JPanel buttonFillerPanel; private javax.swing.JPanel buttonPanel; private javax.swing.JPanel drawTab; private javax.swing.JPanel jPanel1; private javax.swing.JTabbedPane jTabbedPane; private javax.swing.JButton okButton; // End of variables declaration//GEN-END:variables }
4,998
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
MouseTool.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/MouseTool.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * MouseTool.java * * Created on 25.6.2007, 9:34 * */ package org.wandora.application.gui.topicpanels.graphpanel; import java.awt.Cursor; import java.awt.Graphics2D; /** * * @author olli */ public abstract class MouseTool { public boolean mouseMoved(TopicMapGraphPanel panel, int mousex,int mousey){ return false; } public boolean mouseClicked(TopicMapGraphPanel panel, int mousex,int mousey){ return false; } public boolean mouseDragged(TopicMapGraphPanel panel, int mousex,int mousey){ return false; } public boolean mouseReleased(TopicMapGraphPanel panel, int mousex,int mousey){ return false; } public boolean mousePressed(TopicMapGraphPanel panel, int mousex,int mousey){ return false; } public void paint(Graphics2D g2,TopicMapGraphPanel panel){ } public Cursor getCursor(TopicMapGraphPanel panel,int mousex, int mousey){ return null; } }
1,780
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
OccurrenceEdge.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/OccurrenceEdge.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * InstanceEdge.java * * Created on 16.7.2007, 10:55 * */ package org.wandora.application.gui.topicpanels.graphpanel; import static org.wandora.utils.Tuples.t2; import org.wandora.application.gui.topicstringify.TopicToString; import org.wandora.topicmap.Topic; import org.wandora.utils.Tuples.T2; /** * * @author akivela */ public class OccurrenceEdge extends AbstractEdge { private TopicMapModel model; private T2<Node,Node> nodes; private T2<String,String> nodeLabels; private Topic carrier; private Topic type; private Topic scope; private String occurrence; private double baseLength=25.0; public OccurrenceEdge(Topic carrier, Topic type, Topic scope, String occurrence, TopicMapModel model) { this.model=model; this.carrier=carrier; this.type=type; this.scope=scope; this.occurrence=occurrence; nodeLabels=t2("Carrier","Occurrence"); } public Topic getType() { return type; } public Topic getScope() { return scope; } public Topic getCarrier() { return carrier; } @Override public String getLabel() { try { return TopicToString.toString(type); } catch(Exception e) {}; return "Carrier-Occurrence"; } @Override public T2<String,String> getNodeLabels(){ return nodeLabels; } @Override public T2<Node, Node> getNodes() { if(nodes == null) { nodes=t2((Node)model.getNodeFor(carrier), (Node)model.getNodeFor(carrier, type, scope, occurrence)); } return nodes; } public void setBaseLength(double l){ baseLength=l; } @Override public double getLength() { return baseLength+(nodes.e1.getMass()+nodes.e2.getMass())/4.0; } }
2,758
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
VEdge.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/VEdge.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * VEdge.java * * Created on 4.6.2007, 14:02 */ package org.wandora.application.gui.topicpanels.graphpanel; import static org.wandora.utils.Tuples.t2; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.Stroke; import org.wandora.application.gui.topicpanels.graphpanel.projections.Projection; import org.wandora.utils.Tuples.T2; /** * * @author olli */ public class VEdge { private Edge edge; private VModel model; private T2<VNode,VNode> vnodes; private boolean swapped; boolean mouseOver = false; boolean labelEdges = true; boolean selected = false; double curvature = 0.0; private GraphStyle style = null; /** Creates a new instance of VEdge */ public VEdge(Edge edge, VModel model) { this.edge=edge; this.model=model; T2<Node,Node> nodes = edge.getNodes(); vnodes=t2(model.getNode(nodes.e1),model.getNode(nodes.e2)); swapped=false; if(vnodes.e1.getID()>vnodes.e2.getID()) { vnodes=t2(vnodes.e2,vnodes.e1); swapped=true; } style = model.getGraphStyle(); } public boolean isSelected(){ return selected; } public T2<VNode,VNode> getNodes(){ return vnodes; } public VModel getModel(){ return model; } public TopicMapGraphPanel getPanel(){ return model.getPanel(); } public Edge getEdge(){ return edge; } private void drawLabelRect(Graphics2D g2,Projection proj,String label,int posX,int posY,Color c) { drawLabelRect(g2, proj, label, posX, posY, c, false); } private void drawLabelRect(Graphics2D g2,Projection proj,String label,int posX,int posY,Color c, boolean scale){ if(label!=null){ g2.setColor(c); int labelWidth = 100; int labelHeight = 18; if(scale) { double s=proj.scale(posX,posY); g2.setFont(getLabelFont((int) (12*s))); labelWidth=g2.getFontMetrics().stringWidth(label); labelHeight=(int) (16*s); } else { g2.setFont(getLabelFont(12)); labelWidth=g2.getFontMetrics().stringWidth(label); labelHeight=16; } g2.fillRect(posX-labelWidth/2-3,posY-labelHeight/2,labelWidth+6,labelHeight); g2.setStroke(getLabelBorderStroke()); g2.setColor(getLabelColor()); g2.drawString(label,posX-labelWidth/2,posY+g2.getFont().getSize()/2-1); // g2.drawRect(posX-labelWidth/2,posY-labelHeight/2,labelWidth,labelHeight); } } private void drawDetailLabel(Graphics2D g2,Projection proj,String label,int posX,int posY,Color c){ if(label!=null){ double s=proj.scale(posX,posY); int fsize = Math.min(12, (int) (12*s)); if(fsize > 2) { g2.setFont(getLabelFont(fsize)); int labelWidth=g2.getFontMetrics().stringWidth(label); g2.setColor(c); g2.drawString(label,posX-labelWidth/2,posY+g2.getFont().getSize()/2); } } } public void draw(Graphics2D g2, Projection proj){ Color c=getColor(); if(selected){ c=new Color(0,204,255); } g2.setColor(c); T2<Double,Double> p1=proj.worldToScreen(vnodes.e1.x,vnodes.e1.y); T2<Double,Double> p2=proj.worldToScreen(vnodes.e2.x,vnodes.e2.y); if(p1.e1 == Double.NaN || p1.e2 == Double.NaN) return; if(p2.e1 == Double.NaN || p2.e2 == Double.NaN) return; int width=(int)(getWidth()*proj.scale(vnodes.e1.x,vnodes.e1.y)+0.5); Stroke stroke=getStroke(width); g2.setStroke(stroke); /* if(curvature==0.0){ g2.drawLine((int)p1.e1.doubleValue(),(int)p1.e2.doubleValue(), (int)p2.e1.doubleValue(),(int)p2.e2.doubleValue()); } else*/ { double sdx=p2.e1-p1.e1; // delta from p1 to p2, screen coordinates double sdy=p2.e2-p1.e2; double sd2=sdx*sdx+sdy*sdy; if(sd2<=400.0){ g2.drawLine((int)p1.e1.doubleValue(),(int)p1.e2.doubleValue(), (int)p2.e1.doubleValue(),(int)p2.e2.doubleValue()); } else{ double sd=Math.sqrt(sd2); // delta length, screen coordinates int segments=(int)Math.ceil(sd/10.0); // number of segments double dx=vnodes.e2.x-vnodes.e1.x; // delta from node 1 to node 2, world coordinates double dy=vnodes.e2.y-vnodes.e1.y; double d=Math.sqrt(dx*dx+dy*dy); // delta length, world coordinates double ndx=dx/d; // normalized delta, world coordinates double ndy=dy/d; dx/=segments; // delta for each segment on a straight line dy/=segments; // T2<Double,Double> spp=p1; // previous point on a curved line, screen coordinates T2<Double,Double> snp; // next point on a curved line, screen coordinates double nx2,ny2; // next point on a curved line, world coordinates double nx=vnodes.e1.x+dx; // next point on a straight line double ny=vnodes.e1.y+dy; double dr=Math.PI/segments; // angle delta double nr=dr; // angle for next point double f=0.0; // curve function value, Math.sin(cr) int[] x=new int[segments+1]; // points for polyline int[] y=new int[segments+1]; x[0]=(int)p1.e1.doubleValue(); y[0]=(int)p1.e2.doubleValue(); for(int i=0;i<segments;i++){ if(curvature!=0.0) f=Math.sin(nr)*curvature; nx2=nx+f*ndy; ny2=ny-f*ndx; snp=proj.worldToScreen(nx2,ny2); if(snp.e1 == Double.NaN || snp.e2 == Double.NaN) return; // g2.drawLine((int)spp.e1.doubleValue(),(int)spp.e2.doubleValue(), // (int)snp.e1.doubleValue(),(int)snp.e2.doubleValue()); x[i+1]=(int)snp.e1.doubleValue(); y[i+1]=(int)snp.e2.doubleValue(); // spp=snp; nr+=dr; nx+=dx; ny+=dy; } g2.drawPolyline(x,y,x.length); } } if(mouseOver) { String label=edge.getLabel(); double dx=vnodes.e2.x-vnodes.e1.x; double dy=vnodes.e2.y-vnodes.e1.y; double d=Math.sqrt(dx*dx+dy*dy); double ndx=dx/d; double ndy=dy/d; if(label!=null) { T2<Double,Double> p=proj.worldToScreen(vnodes.e1.x+dx*0.5+Math.sin(0.5*Math.PI)*curvature*ndy, vnodes.e1.y+dy*0.5-Math.sin(0.5*Math.PI)*curvature*ndx); if(p.e1 == Double.NaN || p.e2 == Double.NaN) return; drawLabelRect(g2, proj, label,(int)p.e1.doubleValue(),(int)p.e2.doubleValue(),getColor()); } T2<String,String> nodeLabels=edge.getNodeLabels(); if(nodeLabels!=null) { if(swapped) nodeLabels=t2(nodeLabels.e2,nodeLabels.e1); T2<Double,Double> p=proj.worldToScreen(vnodes.e1.x+dx*0.2+Math.sin(0.2*Math.PI)*curvature*ndy, vnodes.e1.y+dy*0.2-Math.sin(0.2*Math.PI)*curvature*ndx); if(p.e1 == Double.NaN || p.e2 == Double.NaN) return; drawLabelRect(g2, proj, nodeLabels.e1,(int)p.e1.doubleValue(),(int)p.e2.doubleValue(),getColor()); p=proj.worldToScreen(vnodes.e1.x+dx*0.8+Math.sin(0.8*Math.PI)*curvature*ndy, vnodes.e1.y+dy*0.8-Math.sin(0.8*Math.PI)*curvature*ndx); drawLabelRect(g2, proj, nodeLabels.e2,(int)p.e1.doubleValue(),(int)p.e2.doubleValue(),getColor()); } } else if(labelEdges) { String label=edge.getLabel(); double dx=vnodes.e2.x-vnodes.e1.x; double dy=vnodes.e2.y-vnodes.e1.y; double d=Math.sqrt(dx*dx+dy*dy); double ndx=dx/d; double ndy=dy/d; if(label!=null) { T2<Double,Double> p=proj.worldToScreen(vnodes.e1.x+dx*0.5+Math.sin(0.5*Math.PI)*curvature*ndy, vnodes.e1.y+dy*0.5-Math.sin(0.5*Math.PI)*curvature*ndx); if(p.e1 == Double.NaN || p.e2 == Double.NaN) return; drawDetailLabel(g2, proj, label,(int)p.e1.doubleValue(),(int)p.e2.doubleValue(),getColor()); } } } // --------------------------------------------------------- GRAPH STYLE --- public void setGraphStyle(GraphStyle newStyle) { if(newStyle == null) { this.style = model.getGraphStyle(); } else { this.style = newStyle; } } public Color getColor() { return style.getEdgeColor(this); } public double getWidth() { return style.getEdgeWidth(this); } public int getLabelFontSize() { return style.getEdgeLabelFontSize(this); } public Font getLabelFont(int forSize) { return style.getEdgeLabelFont(this, forSize); } public Color getLabelColor() { return style.getEdgeLabelColor(this); } public Stroke getLabelBorderStroke() { return style.getEdgeLabelStroke(this); } public Stroke getStroke(int forWidth) { return style.getEdgeStroke(this, forWidth); } }
10,819
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
TopicMapGraphPanel.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/TopicMapGraphPanel.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * TopicMapGraphPanel.java * * Created on 4.6.2007, 11:57 */ package org.wandora.application.gui.topicpanels.graphpanel; import static org.wandora.utils.Tuples.t2; import java.awt.Color; import java.awt.Cursor; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JPopupMenu; import javax.swing.TransferHandler; import javax.swing.event.PopupMenuEvent; import javax.swing.event.PopupMenuListener; import org.wandora.application.RefreshListener; import org.wandora.application.Wandora; import org.wandora.application.WandoraMenuManager; import org.wandora.application.contexts.GraphAllNodesContext; import org.wandora.application.gui.DnDHelper; import org.wandora.application.gui.UIBox; import org.wandora.application.gui.topicpanels.graphpanel.mousetools.DragNodeMouseTool; import org.wandora.application.gui.topicpanels.graphpanel.mousetools.DrawAssociationMouseTool; import org.wandora.application.gui.topicpanels.graphpanel.mousetools.EraserTool; import org.wandora.application.gui.topicpanels.graphpanel.mousetools.ExpandMouseTool; import org.wandora.application.gui.topicpanels.graphpanel.mousetools.MenuMouseTool; import org.wandora.application.gui.topicpanels.graphpanel.mousetools.OpenTopicMouseTool; import org.wandora.application.gui.topicpanels.graphpanel.mousetools.RotateMouseTool; import org.wandora.application.gui.topicpanels.graphpanel.mousetools.SelectMouseTool; import org.wandora.application.gui.topicpanels.graphpanel.projections.HyperbolicProjection; import org.wandora.application.gui.topicpanels.graphpanel.projections.Projection; import org.wandora.application.tools.CopyAsImage; import org.wandora.application.tools.associations.ChangeAssociationRole; import org.wandora.application.tools.associations.ChangeAssociationType; import org.wandora.application.tools.associations.CopyAssociations; import org.wandora.application.tools.associations.DeleteAssociations; import org.wandora.application.tools.associations.ModifySchemalessAssociation; import org.wandora.application.tools.graph.CenterCurrentTopic; import org.wandora.application.tools.graph.CloseTopicNode; import org.wandora.application.tools.graph.CollapseTool; import org.wandora.application.tools.graph.ConnectNodesTool; import org.wandora.application.tools.graph.ExpandNodeTool; import org.wandora.application.tools.graph.ExpandNodesRecursivelyTool; import org.wandora.application.tools.graph.ToggleAnimationTool; import org.wandora.application.tools.graph.ToggleAntialiasTool; import org.wandora.application.tools.graph.ToggleFreezeForMouseOverTool; import org.wandora.application.tools.graph.ToggleLabelEdges; import org.wandora.application.tools.graph.ToggleProjectionSettings; import org.wandora.application.tools.graph.ToggleStaticWidthNodeBoxes; import org.wandora.application.tools.graph.ToggleViewFilterInfo; import org.wandora.application.tools.graph.export.GraphDOTExport; import org.wandora.application.tools.graph.export.GraphGMLExport; import org.wandora.application.tools.graph.export.GraphGraphMLExport; import org.wandora.application.tools.graph.export.GraphGraphXMLExport; import org.wandora.application.tools.graph.filters.ClearEdgeFilters; import org.wandora.application.tools.graph.filters.ClearNodeFilters; import org.wandora.application.tools.graph.filters.FilterEdges; import org.wandora.application.tools.graph.filters.FilterNode; import org.wandora.application.tools.graph.filters.FilterNodesOfType; import org.wandora.application.tools.graph.filters.ReleaseEdges; import org.wandora.application.tools.graph.filters.ReleaseNodesOfType; import org.wandora.application.tools.graph.pinning.ReversePinningTool; import org.wandora.application.tools.graph.pinning.SetPinnedTool; import org.wandora.application.tools.graph.pinning.SetUnpinnedTool; import org.wandora.topicmap.Association; import org.wandora.topicmap.Locator; import org.wandora.topicmap.Topic; import org.wandora.topicmap.TopicMap; import org.wandora.topicmap.TopicMapException; import org.wandora.topicmap.TopicMapListener; import org.wandora.utils.Options; import org.wandora.utils.Tuples.T2; /** * * @author olli */ public class TopicMapGraphPanel extends javax.swing.JPanel implements Runnable, MouseListener, MouseMotionListener, ComponentListener, MouseWheelListener, TopicMapListener, RefreshListener, KeyListener { private static final long serialVersionUID = 1L; private String OPTIONS_PREFIX = "gui.graphTopicPanel."; private String OPTIONS_VIEW_PREFIX = OPTIONS_PREFIX + "view."; //private int viewWidth,viewHeight; private boolean makeLocalSettingsGlobal = true; private VModel model; private TopicMapModel tmModel; private GraphFilter graphFilter; private Thread thread; private double framerate = 25.0; private boolean running; private boolean animation = true; private boolean freeze = false; private boolean labelEdges = false; private boolean cropNodeBoxes = true; private BufferedImage doubleBuffer; private Projection projection; private double mouseX,mouseY; private VNode mouseOverNode; private VEdge mouseOverEdge; private boolean freezeForPopup=false; private boolean freezeForMouseOver=true; // private boolean draggingNode=false; // private boolean draggingView=false; // private boolean drawingSelection=false; // private boolean popupOpen=false; // private double dragOffsX=0.0; // private double dragOffsY=0.0; // private double dragOffsX2=0.0; // private double dragOffsY2=0.0; private double minX=-1.0,maxX=1.0,minY=-1.0,maxY=1.0; private Map renderingHints; private Topic rootTopic; private VNode followNode; public static final int TOOL_OPEN=10; public static final int TOOL_SELECT=11; public static final int TOOL_ASSOCIATION=12; public static final int TOOL_ERASER=13; private int mouseTool; private MouseToolManager mouseToolManager; private java.util.List<T2<Double,Double>> selectPath; private Wandora wandora = null; private Options options = null; private boolean needsRefresh; private FilterManagerPanel filterManagerPanel; private JDialog filterDialog; /** Creates new form TopicMapGraphPanel */ public TopicMapGraphPanel(Wandora w, Options opts) { this.wandora = w; // Notice, the opts coming here is a *copy* of global options. Setting // options doesn't affect global settings. this.options = opts; renderingHints = new LinkedHashMap<>(); this.mouseX=0.0; this.mouseY=0.0; initComponents(); // projection=new DefaultProjection(); projection=new HyperbolicProjection(); projection.initialize(options, OPTIONS_PREFIX+"HyperbolicProjection."); projection.set(Projection.VIEW_WIDTH, this.getWidth()); projection.set(Projection.VIEW_HEIGHT, this.getHeight()); mouseToolManager=new MouseToolManager(this); this.addComponentListener(this); this.addMouseListener(this); this.addMouseMotionListener(this); this.addMouseWheelListener(this); this.addKeyListener(this); if(options != null) { try { this.setMouseTool(options.getInt(OPTIONS_PREFIX+"currentTool", TOOL_OPEN)); this.setAnimationEnabled(options.isTrue(OPTIONS_PREFIX+"animated")); this.setAntialized(options.isTrue(OPTIONS_PREFIX+"antialized")); this.setFreezeForMouseOver(options.isTrue(OPTIONS_PREFIX+"freezeForMouseOver")); this.setLabelEdges(options.isTrue(OPTIONS_PREFIX+"labelEdges")); this.setCropNodeBoxes(options.isTrue(OPTIONS_PREFIX+"cropNodeBoxes")); this.setViewFilterInfo(options.isTrue(OPTIONS_PREFIX+"viewFilterInfo")); } catch(Exception e) { wandora.displayException("Exception occurred while initializing TopicMapGraphPanel", e); } } else { setMouseTool(TOOL_OPEN); } this.setTransferHandler(new TopicPanelTransferHandler()); needsRefresh=false; } public void setFilterManagerPanel(FilterManagerPanel filterManagerPanel){ this.filterManagerPanel=filterManagerPanel; if(filterDialog != null && filterDialog.isVisible()) openFilterManager(); } public void openFilterManager() { if(filterDialog == null) { filterDialog = filterManagerPanel.getDialogForMe(wandora); } filterDialog.setVisible(true); } public void updateMouseWorldCoordinates(int x,int y){ T2<Double,Double> p=projection.screenToWorld(x,y); if(!p.e1.isNaN() && !p.e2.isNaN()){ mouseX=p.e1; mouseY=p.e2; } } public void setMouseFollowNode(VNode node){ followNode=node; } public void setFreezeForPopup(boolean b){ freezeForPopup=b; } public T2<Double,Double> getMouseWorldCoordinates(){ return t2(mouseX,mouseY); } public T2<Double,Double> getViewCoordinates(){ return t2(projection.get(Projection.VIEW_X),projection.get(Projection.VIEW_Y)); } public void setViewCoordinates(T2<Double,Double> p){ setViewCoordinates(p.e1,p.e2); } public void setViewCoordinates(double x,double y){ projection.set(Projection.VIEW_X, x); projection.set(Projection.VIEW_Y, y); } public VNode getMouseOverNode(){ return mouseOverNode; } public Topic getMouseOverTopic(){ if(mouseOverNode==null) return null; Node n=mouseOverNode.getNode(); if(n instanceof TopicNode) return ((TopicNode)n).getTopic(); else return null; } public VEdge getMouseOverEdge(){ return mouseOverEdge; } public Association getMouseOverAssociation(){ if(mouseOverEdge==null) return null; Edge e=mouseOverEdge.getEdge(); if(e instanceof AssociationEdge) return ((AssociationEdge)e).getAssociation(); else return null; } public VModel getModel(){ return model; } public TopicMapModel getTopicMapModel(){ return tmModel; } public int getMouseTool(){ return mouseTool; } public void setMouseTool(int tool) { mouseTool=tool; // updateCursor(); if(tool==TOOL_OPEN){ mouseToolManager.clearToolStack(); mouseToolManager.addTool(MouseToolManager.EVENT_LEFTCLICK,new ExpandMouseTool()); mouseToolManager.addTool(MouseToolManager.EVENT_RIGHTCLICK,new MenuMouseTool()); mouseToolManager.addTool(MouseToolManager.EVENTS_LEFTDRAG,new DragNodeMouseTool()); mouseToolManager.addTool(MouseToolManager.EVENTS_LEFTDRAG,new MoveViewMouseTool()); mouseToolManager.addTool(MouseToolManager.EVENTS_LEFTDRAG,MouseToolManager.MASK_SHIFT,new RotateMouseTool()); mouseToolManager.addTool(MouseToolManager.EVENTS_RIGHTDRAG,new SelectMouseTool()); mouseToolManager.addTool(MouseToolManager.EVENT_LEFTDOUBLECLICK,new OpenTopicMouseTool()); mouseToolManager.addTool(MouseToolManager.EVENT_LEFTCLICK,MouseToolManager.MASK_SHIFT,new SelectMouseTool(false)); } else if(tool==TOOL_SELECT){ mouseToolManager.clearToolStack(); mouseToolManager.addTool(MouseToolManager.EVENTS_LEFTDRAG|MouseToolManager.EVENT_LEFTCLICK,new SelectMouseTool()); mouseToolManager.addTool(MouseToolManager.EVENT_LEFTCLICK,new SelectMouseTool(true)); mouseToolManager.addTool(MouseToolManager.EVENT_LEFTCLICK,MouseToolManager.MASK_SHIFT,new SelectMouseTool(false)); mouseToolManager.addTool(MouseToolManager.EVENTS_RIGHTDRAG,new DragNodeMouseTool()); mouseToolManager.addTool(MouseToolManager.EVENTS_RIGHTDRAG,new MoveViewMouseTool()); mouseToolManager.addTool(MouseToolManager.EVENTS_RIGHTDRAG,MouseToolManager.MASK_SHIFT,new RotateMouseTool()); mouseToolManager.addTool(MouseToolManager.EVENT_RIGHTCLICK,new MenuMouseTool()); } else if(tool==TOOL_ASSOCIATION){ mouseToolManager.clearToolStack(); mouseToolManager.addTool(MouseToolManager.EVENTS_LEFTDRAG,new DrawAssociationMouseTool()); mouseToolManager.addTool(MouseToolManager.EVENTS_LEFTDRAG,new MoveViewMouseTool()); mouseToolManager.addTool(MouseToolManager.EVENTS_LEFTDRAG,MouseToolManager.MASK_SHIFT,new RotateMouseTool()); mouseToolManager.addTool(MouseToolManager.EVENTS_RIGHTDRAG,new DragNodeMouseTool()); mouseToolManager.addTool(MouseToolManager.EVENTS_RIGHTDRAG,new SelectMouseTool()); mouseToolManager.addTool(MouseToolManager.EVENT_RIGHTCLICK,new MenuMouseTool()); } else if(tool==TOOL_ERASER) { mouseToolManager.clearToolStack(); mouseToolManager.addTool(MouseToolManager.EVENT_LEFTCLICK,new EraserTool()); mouseToolManager.addTool(MouseToolManager.EVENTS_LEFTDRAG,new DrawAssociationMouseTool()); mouseToolManager.addTool(MouseToolManager.EVENTS_LEFTDRAG,new MoveViewMouseTool()); mouseToolManager.addTool(MouseToolManager.EVENTS_LEFTDRAG,MouseToolManager.MASK_SHIFT,new RotateMouseTool()); mouseToolManager.addTool(MouseToolManager.EVENTS_RIGHTDRAG,new DragNodeMouseTool()); mouseToolManager.addTool(MouseToolManager.EVENTS_RIGHTDRAG,new SelectMouseTool()); mouseToolManager.addTool(MouseToolManager.EVENT_RIGHTCLICK,new MenuMouseTool()); } if(options != null) { options.put(this.OPTIONS_PREFIX+"currentTool", ""+tool); } } public void updateCursor(Cursor cursor) { if(cursor == null) return; if(!this.getCursor().equals(cursor)) { this.setCursor(cursor); } } public static String getToolName(int toolType) { if(toolType==TOOL_OPEN){ return "Open and move"; } else if(toolType==TOOL_SELECT){ return "Select nodes"; } else if(toolType==TOOL_ASSOCIATION){ return "Draw associations"; } else if(toolType==TOOL_ERASER) { return "Hide nodes and associations"; } return ""; } public static String getToolDescription(int toolType) { if(toolType==TOOL_OPEN){ return "Open and move with mouse"; } else if(toolType==TOOL_SELECT){ return "Select nodes with mouse"; } else if(toolType==TOOL_ASSOCIATION){ return "Draw associations with mouse"; } else if(toolType==TOOL_ERASER) { return "Hide nodes and associations"; } return ""; } /* public void updateCursor() { switch(mouseTool) { case TOOL_OPEN: updateCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); break; case TOOL_SELECT: updateCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); break; } }*/ /* public TopicMapGraphPanel(Topic t) { this(); setRootTopic(t); } */ public Topic getRootTopic(){ return rootTopic; } public VNode getRootNode(){ return model.getNode(tmModel.getNodeFor(rootTopic)); } public Set<VEdge> getSelectedEdges(){ Set<VEdge> ret=model.getSelectedEdges(); if(ret==null) return new HashSet<VEdge>(); else return ret; } public Set<VNode> getSelectedNodes(){ Set<VNode> ret=model.getSelectedNodes(); if(ret==null) { return new HashSet<VNode>(); } else return ret; } public Collection<Topic> getSelectedTopics(){ ArrayList<Topic> ret=new ArrayList<Topic>(); Set<VNode> selection=model.getSelectedNodes(); if(selection==null) return new ArrayList<Topic>(); for(VNode vnode : selection){ Node n=vnode.getNode(); if(n instanceof TopicNode) ret.add(((TopicNode)n).getTopic()); } return ret; } public void clearModel(){ // System.out.println("Clear model"); model=null; tmModel=null; stopThread(); repaint(); } public void remakeModels(TopicMap tm){ // System.out.println("Remake model"); needsRefresh=false; model=new VModel(this); tmModel=new TopicMapModel(model,tm); if(graphFilter == null) { graphFilter=new GraphFilter(tmModel); } else { graphFilter.setTopicMapModel(tmModel); } model.setNodeFilter(graphFilter); model.setEdgeFilter(graphFilter); if(filterManagerPanel!=null) { filterManagerPanel.setTopicNodeFilter(graphFilter); } } public void setRootTopic(Topic t) { if(t == null) return; synchronized(this) { rootTopic=t; if(model==null){ // System.out.println("setRootTopic, remake"); remakeModels(t.getTopicMap()); TopicNode n=tmModel.getNodeFor(t); model.addNode(n); model.openNode(n); if(!running) startThread(); } else { // System.out.println("setRootTopic, reuse"); Node n=tmModel.getNodeFor(t); boolean exists=(model.getNode(n)!=null); VNode vn=null; if(exists) vn=model.addNode(n); else vn=model.addNode(n, projection.get(Projection.VIEW_X)+20.0,projection.get(Projection.VIEW_Y)-20.0); if(!exists) model.connectNode(vn); followNode=vn; } } } public Wandora getWandora(){ return wandora; } public void setViewFilterInfo(boolean b){ viewFilterInfo=b; setOption("viewFilterInfo", ""+b); } public boolean getViewFilterInfo() { return viewFilterInfo; } public void setCropNodeBoxes(boolean b){ cropNodeBoxes=b; setOption("cropNodeBoxes", ""+b); } public boolean getCropNodeBoxes() { return cropNodeBoxes; } public void setFramerate(double fr){ framerate=fr; setOption("framerate", ""+fr); } public double getFramerate() { return framerate; } public void setFreezeForMouseOver(boolean b){ freezeForMouseOver=b; setOption("freezeForMouseOver", ""+b); } public boolean getFreezeForMouseOver() { return freezeForMouseOver; } public void setLabelEdges(boolean b) { labelEdges = b; setOption("labelEdges", ""+b); } public boolean getLabelEdges() { return labelEdges; } public void setAnimationEnabled(boolean b) { animation=b; setOption("animated", ""+b); } public boolean getAnimationEnabled() { return animation; } private void setOption(String optionKey, String optionValue) { if(options != null) { options.put(OPTIONS_PREFIX+optionKey, optionValue); if(makeLocalSettingsGlobal) { Options globalOptions = wandora.getOptions(); if(globalOptions != null) { globalOptions.put(OPTIONS_PREFIX+optionKey, optionValue); } } } } public void setAntialized(boolean b) { if(b) renderingHints.put(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); else renderingHints.put(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF); setOption("antialized", ""+b); } public boolean getAntialized() { Object antialized=renderingHints.get(RenderingHints.KEY_ANTIALIASING); if(antialized==null || antialized==RenderingHints.VALUE_ANTIALIAS_OFF) return false; else return true; } public GraphFilter getGraphFilter() { return graphFilter; } public void startThread() { if(!running) { this.running=true; this.thread=new Thread(this); thread.start(); } } public void stopThread() { this.running=false; } // ------------------------------------------------------------------------- // ------------------------------------------------------------- CLUSTER --- // ------------------------------------------------------------------------- private static class Cluster { public double x,y; public int size; public double radius; public double mass; public double averageDist; public int id; public java.util.List<VNode> nodes; public Cluster(){x=y=0; size=0; radius=0; mass=0; averageDist=0; id=0;} public Cluster(VNode vnode){this(); x=vnode.x;y=vnode.y; } public Cluster(VNode vnode,int id){this(vnode); this.id=id; } public Cluster(int id){this(); this.id=id; } } private ArrayList<Cluster> doClustering(){ // initialize cluster centers int maxClusters=model.getNodes().size()/20+1; ArrayList<Cluster> clusters=new ArrayList<Cluster>(); for(VNode vnode : model.getNodes()){ if(clusters.size()>=maxClusters) break; if(vnode.getEdges().size()>10) clusters.add(new Cluster(vnode,clusters.size())); } // if not enough natural center points, just make some clusters int counter=0; if(!model.getNodes().isEmpty()) { while(clusters.size()<model.getNodes().size()/100+1){ while(model.getNodes().get(counter).getEdges().size()>10) counter++; clusters.add(new Cluster(model.getNodes().get(counter),clusters.size())); counter++; } } // k-means clustering while(true){ for(Cluster cluster : clusters) { cluster.radius=0.0; } boolean changed=false; for(VNode vnode : model.getNodes()){ int old=vnode.cluster; // find closest cluster and put node there double minDist=Double.MAX_VALUE; for(int i=0;i<clusters.size();i++){ Cluster cluster=clusters.get(i); double dx=cluster.x-vnode.x; double dy=cluster.y-vnode.y; double d=dx*dx+dy*dy; if(d<minDist) { vnode.cluster=i; minDist=d; } } Cluster cluster=clusters.get(vnode.cluster); if(cluster.radius<minDist) cluster.radius=minDist; if(old!=vnode.cluster) changed=true; } // if nodes stayed in same clusters, break if(!changed) break; // update cluster centers for(Cluster cluster : clusters) { cluster.x=0; cluster.y=0; cluster.size=0; } for(VNode vnode : model.getNodes()){ Cluster cluster=clusters.get(vnode.cluster); cluster.x+=vnode.x; cluster.y+=vnode.y; cluster.size++; } for(Cluster cluster : clusters) {cluster.x/=cluster.size; cluster.y/=cluster.size;} } // Next we compact clusters by removing nodes that are much further away from cluster // center than most other cluster nodes. We put these nodes in a cluster of their own. Cluster others=new Cluster(clusters.size()); // make array lists for cluster nodes others.nodes=new ArrayList<VNode>(); for(Cluster cluster : clusters) { cluster.nodes=new ArrayList<VNode>(cluster.size); } // put nodes in the cluster ArrayLists, calculate cluster mass and average node distance from // cluster center for(VNode vnode : model.getNodes()){ Cluster cluster=clusters.get(vnode.cluster); cluster.nodes.add(vnode); double dx=cluster.x-vnode.x; double dy=cluster.y-vnode.y; double d=Math.sqrt(dx*dx+dy*dy); cluster.averageDist+=d; cluster.mass+=vnode.getNode().getMass(); } // the compacting itself for(Cluster cluster : clusters) { // finalize average distance and radius cluster.averageDist/=cluster.size; cluster.radius=Math.sqrt(cluster.radius); // only compact if necessary if(cluster.radius>cluster.averageDist*2.0){ cluster.radius=0.0; for(int i=0;i<cluster.nodes.size();i++){ VNode vnode=cluster.nodes.get(i); double dx=cluster.x-vnode.x; double dy=cluster.y-vnode.y; double d=Math.sqrt(dx*dx+dy*dy); if(d>cluster.averageDist*2.0){ // remove node from cluster and move to others cluster.nodes.remove(i); cluster.size--; i--; cluster.mass-=vnode.getNode().getMass(); others.nodes.add(vnode); others.mass+=vnode.getNode().getMass(); others.size++; vnode.cluster=clusters.size(); } else if(d>cluster.radius) cluster.radius=d; } } } // calculate others center and radius for(VNode node : others.nodes){ others.x+=node.x; others.y+=node.y; } others.x=others.size; others.y=others.size; for(VNode vnode : others.nodes){ double dx=others.x-vnode.x; double dy=others.y-vnode.y; double d=Math.sqrt(dx*dx+dy*dy); if(others.radius<d) others.radius=d; } clusters.add(others); return clusters; } private void updateClusters(Cluster c1,Cluster c2){ VNode vin,vjn; VEdge ve; T2<VNode,VNode> vns; Edge e; Node in,jn; double m,dx,dy,d2,d,f,dd,f2; dx=c2.x-c1.x; dy=c2.y-c1.y; d=Math.sqrt(dx*dx+dy*dy); if(d-c2.radius-c1.radius>0){ f=1/(d*d*d); f2=f*c2.mass; for(int i=0;i<c1.nodes.size();i++){ vin=c1.nodes.get(i); in=vin.getNode(); if(!vin.isPinned()){ vin.x-=dx*in.getMass()*f2; vin.y-=dy*in.getMass()*f2; } } f2=f*c1.mass; for(int j=0;j<c2.nodes.size();j++){ vjn=c2.nodes.get(j); jn=vjn.getNode(); if(!vjn.isPinned()){ vjn.x+=dx*jn.getMass()*f2; vjn.y+=dy*jn.getMass()*f2; } } } else{ for(int i=0;i<c1.nodes.size();i++){ vin=c1.nodes.get(i); in=vin.getNode(); if(in.getMass()==0.0) continue; int j=(c1==c2?i+1:0); for(;j<c2.nodes.size();j++){ vjn=c2.nodes.get(j); jn=vjn.getNode(); if(jn.getMass()==0.0) continue; m=in.getMass()*jn.getMass(); dx=vjn.x-vin.x; dy=vjn.y-vin.y; d2=dx*dx+dy*dy; if(d2<100.0) d2=100.0; d=Math.sqrt(d2); f=m/d2; // if(f>10.0) f=10.0; f/=d; if(!vin.isPinned()){ vin.x-=dx*f; vin.y-=dy*f; } if(!vjn.isPinned()){ vjn.x+=dx*f; vjn.y+=dy*f; } } } } } // long t1,t2,t3,t4,t5; public void updateWorld(){ if(model==null) return; VNode vin,vjn; VEdge ve; T2<VNode,VNode> vns; Edge e; Node in,jn; double m,dx,dy,d2,d,f,dd; // t1=System.currentTimeMillis(); ArrayList<Cluster> clusters=doClustering(); // t2=System.currentTimeMillis(); java.util.List<VNode> nodes=model.getNodes(); java.util.List<VEdge> edges=model.getEdges(); if(!freeze && animation) { for(int i=0;i<clusters.size();i++){ Cluster ic=clusters.get(i); for(int j=i+1;j<clusters.size();j++){ Cluster jc=clusters.get(j); updateClusters(ic,jc); } updateClusters(ic,ic); } for(int i=0;i<edges.size();i++){ ve=edges.get(i); e=ve.getEdge(); vns=ve.getNodes(); vin=vns.e1; vjn=vns.e2; dx=vjn.x-vin.x; dy=vjn.y-vin.y; d2=dx*dx+dy*dy; d=Math.sqrt(d2); if(d>e.getLength()) { dd=d-e.getLength(); f=dd*ve.getEdge().getStiffness(); // if(f>10.0) f=10.0; f/=d; if(!vin.isPinned()){ vin.x+=dx*f; vin.y+=dy*f; } if(!vjn.isPinned()){ vjn.x-=dx*f; vjn.y-=dy*f; } } if(labelEdges) { ve.labelEdges = true; } else { ve.labelEdges = false; } } } // t3=System.currentTimeMillis(); if(followNode!=null){ dx=followNode.x-projection.get(Projection.VIEW_X);//viewX; dy=followNode.y-projection.get(Projection.VIEW_Y);//viewY; projection.modify(Projection.VIEW_X, dx*0.3); projection.modify(Projection.VIEW_Y, dy*0.3); } if(!freezeForPopup){ VNode over=null; for(int i=0;i<nodes.size();i++){ vin=nodes.get(i); if(vin.pointInside(mouseX,mouseY)){ if(over!=null) over.mouseOver=false; vin.mouseOver=true; over=vin; } else vin.mouseOver=false; } mouseOverNode=over; if(freezeForMouseOver) freeze = true; if(mouseOverNode==null){ freeze = false; double u,ux,uy,dx2,dy2,md2,ndx,ndy; double minDist=100.0; VEdge minEdge=null; for(int i=0;i<edges.size();i++){ ve=edges.get(i); e=ve.getEdge(); vns=ve.getNodes(); vin=vns.e1; vjn=vns.e2; dx=vjn.x-vin.x; dy=vjn.y-vin.y; d2=dx*dx+dy*dy; if(d2==0) continue; u=((mouseX-vin.x)*dx+(mouseY-vin.y)*dy)/d2; if(u<0.0 || u>1.0) continue; d=Math.sqrt(d2); ndx=dx/d; ndy=dy/d; f=Math.sin(Math.PI*u)*ve.curvature; ux=vin.x+u*dx+f*ndy; uy=vin.y+u*dy-f*ndx; dx2=mouseX-ux; dy2=mouseY-uy; md2=dx2*dx2+dy2*dy2; if(md2<minDist){ minDist=md2; minEdge=ve; } } if(mouseOverEdge!=null) { mouseOverEdge.mouseOver=false; } mouseOverEdge=minEdge; if(minEdge!=null) { minEdge.mouseOver=true; if(freezeForMouseOver) freeze = true; } } else if(mouseOverEdge!=null){ mouseOverEdge.mouseOver=false; mouseOverEdge=null; } } /* if(draggingNode) { mouseOverNode.x=mouseX+dragOffsX; mouseOverNode.y=mouseY+dragOffsY; }*/ minX=-1.0; maxX=1.0; minY=-1.0; maxY=1.0; for(int i=0;i<nodes.size();i++){ vin=nodes.get(i); if(vin.x<minX) minX=vin.x; if(vin.x>maxX) maxX=vin.x; if(vin.y<minY) minY=vin.y; if(vin.y>maxY) maxY=vin.y; } } public Projection getProjection(){ return projection; } @Override public void update(Graphics g){ paint(g); } public Map getRenderingHints(){ return renderingHints; } private Font infoFont=new Font(Font.SANS_SERIF,Font.PLAIN,12); private FontMetrics infoFontMetrics = null; private boolean viewInfo = true; private boolean viewFilterInfo = true; @Override public void paint(Graphics g){ synchronized(this) { int selectedNodes = 0; int nodeCount = 0; int edgeCount = 0; g.setClip(0, 0, this.getWidth(),this.getHeight()); Graphics2D g2=(Graphics2D)g; g2.addRenderingHints(renderingHints); g2.setColor(Color.WHITE); g2.fillRect(0,0,this.getWidth(),this.getHeight()); if(model!=null){ T2<VNode,VNode> nodes; for(VEdge e : model.getEdges()) { nodes=e.getNodes(); if(!nodes.e1.equals(nodes.e2)) { e.draw(g2,projection); edgeCount++; } } for(VNode n : model.getNodes()) { if(n.isSelected()) selectedNodes++; n.draw(g2,projection); nodeCount++; } if(mouseOverEdge!=null) { mouseOverEdge.draw(g2,projection); } if(mouseOverNode!=null) { mouseOverNode.draw(g2,projection); } } mouseToolManager.paint(g2); projection.draw(g2); // ****** INFO AT RIGHT BOTTOM CORNER ****** if(viewInfo) { g2.setColor(Color.LIGHT_GRAY); g2.setFont(infoFont); infoFontMetrics = g.getFontMetrics(); int yloc = getHeight()-10+16; int xloc = getWidth()-10; String str = ""; yloc -= 16; str = edgeCount+" edges"; g2.drawString(str ,xloc-infoFontMetrics.stringWidth(str), yloc); yloc -= 16; if(selectedNodes == 0) { str = nodeCount+" nodes"; } else { str = nodeCount+" nodes, "+selectedNodes+" selected"; } g2.drawString(str ,xloc-infoFontMetrics.stringWidth(str), yloc); yloc -= 16; str = Math.round(fps)+" fps"; g2.drawString(str ,xloc-infoFontMetrics.stringWidth(str), yloc); // g2.drawString(""+(t2-t1),10,32); // g2.drawString(""+(t3-t2),10,44); // g2.drawString(""+(t5-t4),10,56); } if(viewFilterInfo && graphFilter != null) { String filterDescription = graphFilter.describeFilters(); if(filterDescription != null && filterDescription.length() > 0) { String[] filterDescriptions = filterDescription.split("\n"); g2.setColor(Color.LIGHT_GRAY); g2.setFont(infoFont); infoFontMetrics = g.getFontMetrics(); int yloc = 20; int xloc = getWidth()-10; for(String str : filterDescriptions) { g2.drawString(str ,xloc-infoFontMetrics.stringWidth(str), yloc); yloc += 16; } } } } } private volatile double fps=0.0; @Override public void run() { long delay; long timerStart; long timerEnd; long timer; while(running) { delay=(long)(1000/framerate); timerStart = System.currentTimeMillis(); timer = timerStart; timerEnd = timer+delay; synchronized(this){ updateWorld(); } repaint(); timer=System.currentTimeMillis(); while(timer<timerEnd && running) { try{ Thread.sleep(timerEnd-timer); } catch(InterruptedException ie){} timer=System.currentTimeMillis(); } fps=1000.0/(timer-timerStart); } } @Override public void componentShown(ComponentEvent e) { projection.set(Projection.VIEW_WIDTH, TopicMapGraphPanel.this.getWidth()); projection.set(Projection.VIEW_HEIGHT, TopicMapGraphPanel.this.getHeight()); } @Override public void componentResized(ComponentEvent e) { projection.set(Projection.VIEW_WIDTH, TopicMapGraphPanel.this.getWidth()); projection.set(Projection.VIEW_HEIGHT, TopicMapGraphPanel.this.getHeight()); } @Override public void componentHidden(ComponentEvent e) {} @Override public void componentMoved(ComponentEvent e) {} /* public JPopupMenu buildNodePopup(Object[] tools){ JPopupMenu menu=new JPopupMenu(); buildMenu(tools,0,menu,null); return menu; } public JPopupMenu buildEdgePopup(Object[] tools){ JPopupMenu menu=new JPopupMenu(); buildMenu(tools,1,menu,null); return menu; } public JPopupMenu buildGeneralPopup(Object[] tools){ JPopupMenu menu=new JPopupMenu(); buildMenu(tools,2,menu,null); return menu; } public void buildMenu(Object[] tools,final int mode,JPopupMenu popup,JMenu menu){ for(int i=0;i<tools.length;i++){ if(tools[i] instanceof GraphTool){ final GraphTool tool=(GraphTool)tools[i]; JMenuItem item=new JMenuItem(tool.getName(),tool.getIcon()); if(popup!=null) popup.add(item); else menu.add(item); item.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ synchronized(TopicMapGraphPanel.this){ if(mode==0) tool.invokeNode(mouseOverNode,model,TopicMapGraphPanel.this); else if(mode==1) tool.invokeEdge(mouseOverEdge,model,TopicMapGraphPanel.this); else if(mode==2) tool.invokeGeneral(model,TopicMapGraphPanel.this); } } }); } else if(tools[i] instanceof String){ JMenu subMenu=new JMenu((String)tools[i]); i++; if(tools[i] instanceof Object[]) buildMenu((Object[])tools[i],mode,null,subMenu); else if(tools[i] instanceof Collection) buildMenu(((Collection)tools[i]).toArray(),mode,null,subMenu); if(popup!=null) popup.add(subMenu); else menu.add(subMenu); } } if(popup!=null){ popup.addPopupMenuListener(new PopupMenuListener() { public void popupMenuCanceled(PopupMenuEvent e) {} public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { popupOpen=false; } public void popupMenuWillBecomeVisible(PopupMenuEvent e) {} }); } } */ public void selectNodesWithPath(List<T2<Double,Double>> path){ if(!path.get(0).equals(path.get(path.size()-1))) path.add(path.get(0)); List<VNode> nodes=model.getNodes(); int[] counters=new int[nodes.size()]; for(int i=0;i<path.size()-1;i++){ T2<Double,Double> p1=path.get(i); T2<Double,Double> p2=path.get(i+1); double dx=p2.e1-p1.e1; if(dx==0) continue; double dy=p2.e2-p1.e2; for(int j=0;j<nodes.size();j++){ VNode vnode=nodes.get(j); double xpos=(vnode.x-p1.e1)/dx; if(xpos>=0.0 && xpos<=1.0){ if(p1.e2+dy*xpos>=vnode.y) counters[j]++; } } } for(int i=0;i<counters.length;i++){ if( (counters[i]%2)==1 ){ model.addSelection(nodes.get(i)); } } } public boolean lockMouseTool(MouseTool tool){ return mouseToolManager.lockTool(tool); } public void releaseMouseTool(){ mouseToolManager.releaseLockedTool(); } @Override public void mouseDragged(MouseEvent e) { requestFocus(); T2<Double,Double> p=projection.screenToWorld(e.getX(),e.getY()); if(!p.e1.isNaN() && !p.e2.isNaN()){ mouseX=p.e1; mouseY=p.e2; /* if(draggingView){ viewX=dragOffsX+(dragOffsX2-mouseX); viewY=dragOffsY+(dragOffsY2-mouseY); p=projection.screenToWorld(e.getX(),e.getY()); mouseX=p.e1; mouseY=p.e2; dragOffsX=viewX; dragOffsY=viewY; dragOffsX2=mouseX; dragOffsY2=mouseY; } if(drawingSelection){ selectPath.add(t2(mouseX,mouseY)); }*/ } mouseToolManager.mouseDragged(e); } @Override public void mouseExited(MouseEvent e) { } @Override public void mouseClicked(MouseEvent e) { requestFocus(); /* if(e.getButton()==e.BUTTON3){ if(mouseOverNode!=null){ popupOpen=true; if(!mouseOverNode.selected) model.setSelection(mouseOverNode); JPopupMenu menu=getNodeMenu(); menu.show(this,e.getX(),e.getY()); } else if(mouseOverEdge!=null){ popupOpen=true; if(!mouseOverEdge.selected) model.setSelection(mouseOverEdge); JPopupMenu menu=getEdgeMenu(); menu.show(this,e.getX(),e.getY()); } else { popupOpen=true; JPopupMenu menu=getGeneralMenu(); menu.show(this,e.getX(),e.getY()); } } if(e.getButton()==e.BUTTON1){ if(e.getClickCount() == 2 && mouseOverNode!=null) { Node n = mouseOverNode.getNode(); if(n instanceof TopicNode && wandora != null) { Topic t = ((TopicNode) n).getTopic(); wandora.applyChangesAndOpen(t); } } else if(mouseTool==TOOL_SELECT || (e.getModifiersEx()&e.SHIFT_MASK)!=0) { if(mouseOverNode!=null){ if((e.getModifiersEx()&e.SHIFT_MASK)==0) model.setSelection(mouseOverNode); else{ if(mouseOverNode.isSelected()) model.deselectNode(mouseOverNode); else model.addSelection(mouseOverNode); } } else{ if((e.getModifiersEx()&e.SHIFT_MASK)==0) model.deselectAll(); } } else if(mouseTool==TOOL_OPEN && mouseOverNode!=null) model.openNode(mouseOverNode); }*/ mouseToolManager.mouseClicked(e); } @Override public void mouseEntered(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { requestFocus(); /* if(mouseTool==TOOL_SELECT || (e.getModifiersEx()&e.SHIFT_MASK)!=0){ drawingSelection=true; selectPath=new ArrayList<T2<Double,Double>>(); selectPath.add(t2(mouseX,mouseY)); } else if(mouseTool==TOOL_OPEN){ if(mouseOverNode!=null) { draggingNode=true; followNode=null; dragOffsX=mouseOverNode.x-mouseX; dragOffsY=mouseOverNode.y-mouseY; } else{ draggingView=true; followNode=null; dragOffsX=viewX; dragOffsY=viewY; dragOffsX2=mouseX; dragOffsY2=mouseY; } }*/ mouseToolManager.mousePressed(e); } @Override public void mouseReleased(MouseEvent e) { requestFocus(); /* draggingNode=false; draggingView=false; if(drawingSelection){ drawingSelection=false; if(selectPath.size()>10){ if((e.getModifiersEx()&e.SHIFT_MASK)==0) model.deselectAll(); selectNodesWithPath(selectPath); } }*/ mouseToolManager.mouseReleased(e); mouseToolManager.updateCursor(e.getModifiersEx(),e.getX(),e.getY()); } @Override public void mouseMoved(MouseEvent e) { T2<Double,Double> p=projection.screenToWorld(e.getX(),e.getY()); if(!p.e1.isNaN() && !p.e2.isNaN()){ mouseX=p.e1; mouseY=p.e2; } mouseToolManager.mouseMoved(e); mouseToolManager.updateCursor(e.getModifiersEx(),e.getX(),e.getY()); } @Override public void mouseWheelMoved(MouseWheelEvent e) { int notches=e.getWheelRotation(); double multiplier=1.5; if((e.getModifiersEx()&MouseWheelEvent.ALT_DOWN_MASK)!=0) multiplier=1.1; if((e.getModifiersEx()&MouseWheelEvent.SHIFT_DOWN_MASK)!=0){ projection.modify(Projection.MOUSEWHEEL2, notches, multiplier); } else { projection.modify(Projection.MOUSEWHEEL1, notches, multiplier); } } public JPopupMenu getGeneralMenu() { JPopupMenu popup = null; try { Object[] menuStructure = new Object[] { "Center graph", new CenterCurrentTopic(this), "Change projection", new ToggleProjectionSettings(this), "---", "Filter nodes", UIBox.makeMenuStruct(FilterNodesOfType.makeTools(model.getNodes(),graphFilter,null)), "Release node filters", UIBox.makeMenuStruct(ReleaseNodesOfType.makeTools(graphFilter,null)), "Clear all node filters", new ClearNodeFilters(graphFilter), "---", "Filter edges", UIBox.makeMenuStruct(FilterEdges.makeTools(model.getEdges(),graphFilter,null)), "Release edge filters", UIBox.makeMenuStruct(ReleaseEdges.makeTools(model.getEdges(),graphFilter,null)), "Clear all edge filters", new ClearEdgeFilters(graphFilter), "---", /* "Pin nodes", new Object[] { "Set all pinned", new SetPinnedTool(new GraphAllNodesContext()), "Set all unpinned", new SetUnpinnedTool(new GraphAllNodesContext()), "Reverse pinning", new ReversePinningTool(new GraphAllNodesContext()), }, "---", **/ "Select", WandoraMenuManager.getDefaultSelectMenuStruct(wandora, this), "Topics", WandoraMenuManager.getDefaultTopicMenuStruct(wandora, this), "Options", getOptionsMenuStruct(), "---", "Copy as image", new CopyAsImage(), "Export graph as", new Object[] { "Export graph as DOT...", new GraphDOTExport(), "Export graph as GraphML...", new GraphGraphMLExport(), "Export graph as GraphXML...", new GraphGraphXMLExport(), "Export graph as GML...", new GraphGMLExport(), } }; popup=UIBox.makePopupMenu(menuStructure, Wandora.getWandora(this)); popup.addPopupMenuListener(new PopupListener()); } catch(Exception e) { e.printStackTrace(); } return popup; } public JPopupMenu getEdgeMenu() { Object[] menuStructure = new Object[] { "Copy association", new Object[] { "Copy association as tab text", new CopyAssociations(), "Copy association as HTML", new CopyAssociations(CopyAssociations.HTML_OUTPUT), }, /* "Paste associations", new Object[] { "Paste tab text associations", }, */ "Change associations", new Object[] { "Change association type...", new ChangeAssociationType(), "Change association role...", new ChangeAssociationRole(), }, /* "Make players instance of role...", **/ //"Add associations...", new AddAssociations(new ApplicationContext()), "Modify association...", new ModifySchemalessAssociation(), "Delete associations...", new DeleteAssociations(), //"Duplicate associations...", //"---", /* "Refactor", new Object[] { "Break Binary Association Topics", new BinaryAssociationTopicBreaker(), } */ /* "---", "Cut associations", new Object[] { "Copy all associations as tab text", new CopyAssociations(), "Copy all associations as HTML", new CopyAssociations(CopyAssociations.HTML_OUTPUT), }, **/ "---", "Filter nodes", UIBox.makeMenuStruct(FilterNodesOfType.makeTools(model.getNodes(),graphFilter,null)), "Release node filters", UIBox.makeMenuStruct(ReleaseNodesOfType.makeTools(graphFilter,null)), "Clear all node filters", new ClearNodeFilters(graphFilter), "---", "Filter edges", UIBox.makeMenuStruct(FilterEdges.makeTools(model.getEdges(),graphFilter,null)), "Release edge filters", UIBox.makeMenuStruct(ReleaseEdges.makeTools(model.getEdges(),graphFilter,null)), "Clear all edge filters", new ClearEdgeFilters(graphFilter), "---", "Select", WandoraMenuManager.getDefaultSelectMenuStruct(wandora, this), "Options", getOptionsMenuStruct(), "---", "Copy as image", new CopyAsImage(), "Export graph as", new Object[] { "Export graph as DOT...", new GraphDOTExport(), "Export graph as GraphML...", new GraphGraphMLExport(), "Export graph as GraphXML...", new GraphGraphXMLExport(), "Export graph as GML...", new GraphGMLExport(), } }; JPopupMenu popup=UIBox.makePopupMenu(menuStructure, Wandora.getWandora(this)); popup.addPopupMenuListener(new PopupListener()); return popup; } public JPopupMenu getNodeMenu() { Object[] menuStructure = null; try { menuStructure = new Object[] { "Open in", WandoraMenuManager.getOpenInMenu(), "---", "Expand node", new ExpandNodeTool(this), "Expand nodes recusively", new ExpandNodesRecursivelyTool(this), "Connect all visible nodes", new ConnectNodesTool(this), "---", "Close node", new CloseTopicNode(this), "Close all nodes but", new CloseTopicNode(this, true), "Collapse", new Object[] { "Collapse nodes", new CollapseTool(this), "Collapse nodes to 2", new CollapseTool(this, 2), "Collapse nodes to 3", new CollapseTool(this, 3), }, "---", "Pin nodes", new Object[] { "Set selection pinned", new SetPinnedTool(this), "Set selection unpinned", new SetUnpinnedTool(this), "Reverse selection pinning", new ReversePinningTool(this), "---", "Set all pinned", new SetPinnedTool(this, new GraphAllNodesContext()), "Set all unpinned", new SetUnpinnedTool(this, new GraphAllNodesContext()), "Reverse pinning", new ReversePinningTool(this, new GraphAllNodesContext()), }, "---", "Filter node", new FilterNode(graphFilter), "Filter nodes", UIBox.makeMenuStruct(FilterNodesOfType.makeTools(model.getNodes(),graphFilter,null)), "Release node filters", UIBox.makeMenuStruct(ReleaseNodesOfType.makeTools(graphFilter,null)), "Clear all node filters", new ClearNodeFilters(graphFilter), "---", "Filter edges", UIBox.makeMenuStruct(FilterEdges.makeTools(model.getEdges(),graphFilter,null)), "Release edge filters", UIBox.makeMenuStruct(ReleaseEdges.makeTools(model.getEdges(),graphFilter,null)), "Clear all edge filters", new ClearEdgeFilters(graphFilter), "---", "Select", WandoraMenuManager.getDefaultSelectMenuStruct(wandora, this), "Topics", WandoraMenuManager.getDefaultTopicMenuStruct(wandora, this), "Options", getOptionsMenuStruct(), "---", "Copy as image", new CopyAsImage(), "Export graph as", new Object[] { "Export graph as DOT...", new GraphDOTExport(), "Export graph as GraphML...", new GraphGraphMLExport(), "Export graph as GraphXML...", new GraphGraphXMLExport(), "Export graph as GML...", new GraphGMLExport(), } }; } catch(Exception e) { e.printStackTrace(); } JPopupMenu popup=UIBox.makePopupMenu(menuStructure, Wandora.getWandora(this)); popup.addPopupMenuListener(new PopupListener()); return popup; } public Object[] getOptionsMenuStruct() { Map hints=this.getRenderingHints(); Object antialized=hints.get(RenderingHints.KEY_ANTIALIASING); return new Object[] { "Antialised", (antialized==null || antialized==RenderingHints.VALUE_ANTIALIAS_OFF ? UIBox.getIcon("gui/icons/checkbox.png") : UIBox.getIcon("gui/icons/checkbox_selected.png")), new ToggleAntialiasTool(this), "Animate", (this.getAnimationEnabled() ? UIBox.getIcon("gui/icons/checkbox_selected.png") : UIBox.getIcon("gui/icons/checkbox.png")), new ToggleAnimationTool(this), "Freeze while mouse over", (freezeForMouseOver ? UIBox.getIcon("gui/icons/checkbox_selected.png") : UIBox.getIcon("gui/icons/checkbox.png")), new ToggleFreezeForMouseOverTool(this), "Label edges", (this.getLabelEdges() ? UIBox.getIcon("gui/icons/checkbox_selected.png") : UIBox.getIcon("gui/icons/checkbox.png")), new ToggleLabelEdges(this), "Static width node boxes", (getCropNodeBoxes() ? UIBox.getIcon("gui/icons/checkbox_selected.png") : UIBox.getIcon("gui/icons/checkbox.png")), new ToggleStaticWidthNodeBoxes(this), "View filter info", (getViewFilterInfo() ? UIBox.getIcon("gui/icons/checkbox_selected.png") : UIBox.getIcon("gui/icons/checkbox.png")), new ToggleViewFilterInfo(this), }; } private class PopupListener implements PopupMenuListener { @Override public void popupMenuCanceled(PopupMenuEvent e) {} @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { freezeForPopup=false; //popupOpen=false; } @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { freezeForPopup=true; //popupOpen=true; } } private Topic getNewTopicFor(Topic t, TopicMap tm) throws TopicMapException { Topic r=null; if(t != null) { if(t.getSubjectLocator()!=null) { r=tm.getTopicBySubjectLocator(t.getSubjectLocator()); if(r!=null) return r; } for(Locator l : t.getSubjectIdentifiers()){ r=tm.getTopic(l); if(r!=null) return r; } if(t.getBaseName()!=null) { r=tm.getTopicWithBaseName(t.getBaseName()); if(r!=null) return r; } } return null; } private Association getNewAssociationFor(Association a, TopicMap tm) throws TopicMapException { if(a == null) return null; Topic oldType=a.getType(); Topic newType=getNewTopicFor(oldType,tm); if(newType==null) return null; Collection<Topic> oldRoles=a.getRoles(); for(Topic oldRole : oldRoles){ Topic newRole=getNewTopicFor(oldRole,tm); if(newRole==null) continue; Topic oldPlayer=a.getPlayer(oldRole); Topic newPlayer=getNewTopicFor(oldPlayer,tm); if(newPlayer==null) continue; Collection<Association> newAssociations=newPlayer.getAssociations(newType,newRole); NewAssociations: for(Association newAssociation : newAssociations){ if(oldRoles.size()!=newAssociation.getRoles().size()) continue; for(Topic oldRole2 : oldRoles){ Topic newRole2=getNewTopicFor(oldRole2,tm); if(newRole2==null) continue NewAssociations; Topic oldPlayer2=a.getPlayer(oldRole2); Topic newPlayer2=getNewTopicFor(oldPlayer2,tm); if(newPlayer2==null) continue NewAssociations; Topic newPlayer3=newAssociation.getPlayer(newRole2); if(newPlayer3==null) continue NewAssociations; if(!newPlayer3.mergesWithTopic(newPlayer2)) continue NewAssociations; } return newAssociation; } } return null; } public void refreshGraph() { if(model != null && projection != null) { projection.set(Projection.VIEW_WIDTH, this.getWidth()); projection.set(Projection.VIEW_HEIGHT, this.getHeight()); } // System.out.println("Refreshing graph"); synchronized(this){ needsRefresh=false; TopicMap tm=tmModel.getTopicMap(); VModel oldModel=model; TopicMapModel oldTMModel=tmModel; Topic oldRoot=rootTopic; List<VNode> oldNodes=oldModel.getNodes(); List<VEdge> oldEdges=oldModel.getEdges(); remakeModels(tm); try{ for(VNode vnode : oldNodes) { Node node=vnode.getNode(); VNode nn=null; if(node instanceof TopicNode){ TopicNode tn=(TopicNode)node; Topic t=tn.getTopic(); Topic nt=getNewTopicFor(t,tm); if(nt!=null){ nn=model.addNode(tmModel.getNodeFor(nt)); } } else if(node instanceof AssociationNode) { AssociationNode an=(AssociationNode)node; Association a=an.getAssociation(); Association na=getNewAssociationFor(a,tm); if(na!=null){ if(na.getRoles().size()!=2) { nn=model.addNode(tmModel.getNodeFor(na)); } } } else if(node instanceof OccurrenceNode) { OccurrenceNode on=(OccurrenceNode)node; Topic carrier = on.getCarrier(); Topic type = on.getType(); Topic scope = on.getScope(); Topic ncarrier = getNewTopicFor(carrier,tm); Topic ntype = getNewTopicFor(type,tm); Topic nscope = getNewTopicFor(scope,tm); if(ncarrier != null && ntype != null && nscope != null) { String o = ncarrier.getData(ntype, nscope); if(o != null) { nn=model.addNode(tmModel.getNodeFor(ncarrier, ntype, nscope, o)); } } } if(nn!=null) { nn.x=vnode.x; nn.y=vnode.y; nn.pinned=vnode.pinned; if(vnode.selected) model.addSelection(nn); } } for(VEdge vedge : oldEdges) { Edge edge=vedge.getEdge(); VEdge ne = null; if(edge instanceof AssociationEdge) { AssociationEdge ae=(AssociationEdge)edge; Association a=ae.getAssociation(); Association na=getNewAssociationFor(a,tm); if(na!=null){ if(a.getRoles().size()==na.getRoles().size()){ if(a.getRoles().size()==2){ ne = model.addEdge(tmModel.getEdgeFor(na)); } else { AssociationNode an=tmModel.getNodeFor(na); VNode vn=model.addNode(an); model.openNode(vn); // TODO currently opens entire association instead of edges that were previously open } } } } else if(edge instanceof InstanceEdge) { InstanceEdge ie=(InstanceEdge)edge; Topic instance=ie.getInstance(); Topic type=ie.getType(); Topic ninstance=getNewTopicFor(instance,tm); Topic ntype=getNewTopicFor(type,tm); if(ninstance!=null && ntype!=null){ ne = model.addEdge(tmModel.getInstanceEdgeFor(ntype,ninstance)); } } else if(edge instanceof OccurrenceEdge) { OccurrenceEdge oe=(OccurrenceEdge)edge; Topic carrier = oe.getCarrier(); Topic type = oe.getType(); Topic scope = oe.getScope(); Topic ncarrier = getNewTopicFor(carrier,tm); Topic ntype = getNewTopicFor(type,tm); Topic nscope = getNewTopicFor(scope,tm); if(ntype != null && nscope != null && ncarrier != null) { String o = ncarrier.getData(ntype, nscope); if(o != null) { ne = model.addEdge(tmModel.getOccurrenceEdgeFor(ncarrier, ntype, nscope, o)); } } } if(ne != null) { if(vedge.selected) { model.setSelection(ne); } ne.mouseOver = vedge.mouseOver; ne.labelEdges = vedge.labelEdges; ne.curvature = vedge.curvature; } } rootTopic=getNewTopicFor(oldRoot,tm); followNode=null; } catch(TopicMapException tme) { tme.printStackTrace(); } } } @Override public void doRefresh() throws TopicMapException { if(needsRefresh){ refreshGraph(); } } // ------------------------------------------------------------------------- @Override public void topicTypeChanged(Topic t, Topic added, Topic removed) throws TopicMapException { if(needsRefresh) return; if(tmModel.topicIsIndexed(t)) needsRefresh=true; } @Override public void topicSubjectIdentifierChanged(Topic t, Locator added, Locator removed) throws TopicMapException { if(needsRefresh) return; if(tmModel.topicIsIndexed(t)) needsRefresh=true; } @Override public void topicSubjectLocatorChanged(Topic t, Locator newLocator, Locator oldLocator) throws TopicMapException { if(needsRefresh) return; if(tmModel.topicIsIndexed(t)) needsRefresh=true; } @Override public void associationChanged(Association a) throws TopicMapException { if(needsRefresh) return; if(tmModel.associationIsIndexed(a)) needsRefresh=true; } @Override public void associationRemoved(Association a) throws TopicMapException { if(needsRefresh) return; if(tmModel.associationIsIndexed(a)) needsRefresh=true; } @Override public void topicBaseNameChanged(Topic t, String newName, String oldName) throws TopicMapException { if(needsRefresh) return; if(tmModel.topicIsIndexed(t)) needsRefresh=true; } @Override public void topicDataChanged(Topic t, Topic type, Topic version, String newValue, String oldValue) throws TopicMapException { if(needsRefresh) return; if(tmModel.topicIsIndexed(t)) needsRefresh=true; } @Override public void topicVariantChanged(Topic t, Collection<Topic> scope, String newName, String oldName) throws TopicMapException { if(needsRefresh) return; if(tmModel.topicIsIndexed(t)) needsRefresh=true; } @Override public void associationPlayerChanged(Association a, Topic role, Topic newPlayer, Topic oldPlayer) throws TopicMapException { if(needsRefresh) return; if(newPlayer!=null && tmModel.topicIsIndexed(newPlayer)) needsRefresh=true; if(oldPlayer!=null && tmModel.topicIsIndexed(oldPlayer)) needsRefresh=true; if(tmModel.associationIsIndexed(a)) needsRefresh=true; } @Override public void associationTypeChanged(Association a, Topic newType, Topic oldType) throws TopicMapException { if(needsRefresh) return; if(tmModel.associationIsIndexed(a)) needsRefresh=true; } @Override public void topicChanged(Topic t) throws TopicMapException { if(needsRefresh) return; if(tmModel.topicIsIndexed(t)) needsRefresh=true; } @Override public void topicRemoved(Topic t) throws TopicMapException { if(needsRefresh) return; if(tmModel.topicIsIndexed(t)) needsRefresh=true; } // ------------------------------------------------------------------------- @Override public void keyTyped(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { if(e.getKeyCode() == KeyEvent.VK_PLUS) { projection.modify(Projection.MOUSEWHEEL1, -0.5, 1.5); } else if(e.getKeyCode() == KeyEvent.VK_MINUS) { projection.modify(Projection.MOUSEWHEEL1, +0.5, 1.5); } mouseToolManager.updateCursor(e.getModifiersEx(),-1,-1); } @Override public void keyPressed(KeyEvent e) { mouseToolManager.updateCursor(e.getModifiersEx(),-1,-1); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { setLayout(new java.awt.BorderLayout()); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables // End of variables declaration//GEN-END:variables private class TopicPanelTransferHandler extends TransferHandler { @Override public boolean canImport(TransferSupport support) { if(!support.isDrop()) return false; return support.isDataFlavorSupported(DnDHelper.topicDataFlavor) || support.isDataFlavorSupported(DataFlavor.stringFlavor); } @Override protected Transferable createTransferable(JComponent c) { // return DnDHelper.makeTopicTableTransferable(data,getSelectedRows(),getSelectedColumns()); return null; } @Override public int getSourceActions(JComponent c) { return TransferHandler.COPY_OR_MOVE; } @Override public boolean importData(TransferSupport support) { if(!support.isDrop()) return false; try { TopicMap tm=wandora.getTopicMap(); List<Topic> topics=DnDHelper.getTopicList(support, tm, true); if(topics==null) return false; for(Topic t : topics) { if(t != null && !t.isRemoved()) { setRootTopic(t); } } wandora.doRefresh(); } catch(TopicMapException tme){tme.printStackTrace();} catch(Exception ce){} return false; } } }
73,463
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
AssociationEdge.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/AssociationEdge.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * TopicMapEdge.java * * Created on 5.6.2007, 15:18 * */ package org.wandora.application.gui.topicpanels.graphpanel; import static org.wandora.utils.Tuples.t2; import java.util.Iterator; import org.wandora.application.gui.topicstringify.TopicToString; import org.wandora.topicmap.Association; import org.wandora.topicmap.Topic; import org.wandora.topicmap.TopicMapException; import org.wandora.utils.Tuples.T2; /** * * @author olli */ public class AssociationEdge extends AbstractEdge { private Association association; private TopicMapModel model; private T2<Node,Node> nodes; private T2<String,String> nodeLabels; private T2<Topic,Topic> nodeLabelTopics; private double baseLength=50.0; /** Creates a new instance of AssociationEdge */ public AssociationEdge(Association association, TopicMapModel model) { this.association=association; this.model=model; try { Iterator<Topic> iter = association.getRoles().iterator(); Topic role1 = iter.next(); Topic role2 = iter.next(); nodeLabelTopics = t2(role1,role2); nodeLabels = null; nodes = t2((Node)model.getNodeFor(association.getPlayer(role1)), (Node)model.getNodeFor(association.getPlayer(role2))); } catch(TopicMapException tme){ tme.printStackTrace(); } } public AssociationEdge(Node n1,Node n2,String n2Label,Association association,TopicMapModel model){ this.model = model; this.association = association; nodes = t2(n1,n2); if(n2Label != null) { nodeLabels = t2(null, n2Label); nodeLabelTopics = null; } } @Override public String getLabel(){ try { return TopicToString.toString(association.getType()); } catch(Exception tme) { tme.printStackTrace(); return null; } } @Override public T2<String,String> getNodeLabels() { if(nodeLabels != null) { return nodeLabels; } else if(nodeLabelTopics != null) { return t2(TopicToString.toString(nodeLabelTopics.e1),TopicToString.toString(nodeLabelTopics.e2)); } else { return t2( "unknown", "unknown" ); } } public Association getAssociation(){ return association; } @Override public T2<Node, Node> getNodes() { return nodes; } public void setBaseLength(double l){ baseLength=l; } @Override public double getLength() { return baseLength+(nodes.e1.getMass()+nodes.e2.getMass())/4.0; } }
3,596
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
GraphStyle.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/GraphStyle.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * GraphStyle.java * * Created on 12.7.2007, 11:35 * */ package org.wandora.application.gui.topicpanels.graphpanel; import java.awt.Color; import java.awt.Font; import java.awt.Stroke; /** * * @author akivela */ public interface GraphStyle { public Color getNodeColor(VNode vn); public Color getNodeTextColor(VNode vn); public NodeShape getNodeShape(VNode vn); public double getNodeWidth(VNode vn); public double getNodeHeight(VNode vn); public Color getNodeBorderColor(VNode vn); public Stroke getNodeBorderStroke(VNode vn); public int getNodeFontSize(VNode vn); public Font getNodeFont(VNode vn, int forSize); public double getEdgeWidth(VEdge ve); public Color getEdgeColor(VEdge ve); public int getEdgeLabelFontSize(VEdge ve); public Font getEdgeLabelFont(VEdge ve, int forSize); public Color getEdgeLabelColor(VEdge ve); public Stroke getEdgeLabelStroke(VEdge ve); public Stroke getEdgeStroke(VEdge ve, int forWidth); }
1,829
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
TestNode.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/TestNode.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * TestNode.java * * Created on 4.6.2007, 13:21 */ package org.wandora.application.gui.topicpanels.graphpanel; import java.util.ArrayList; import java.util.Collection; import java.util.List; /** * * @author olli */ public class TestNode extends AbstractNode { private List<Edge> edges; private String label; /** Creates a new instance of TestNode */ public TestNode() { this.edges=new ArrayList<>(); } public TestNode(String label) { this(); this.label=label; } public static TestNode makeWithNodes(Collection<Node> nodes){ TestNode tn=new TestNode(); for(Node n : nodes){ tn.addEdge(new TestEdge(tn,n)); } return tn; } public void addEdge(Edge e){ edges.add(e); } public Collection<Edge> getEdges() { return edges; } @Override public String getLabel() { return label; } }
1,763
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
MenuMouseTool.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/mousetools/MenuMouseTool.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * MenuMouseTool.java * * Created on 25.6.2007, 9:39 * */ package org.wandora.application.gui.topicpanels.graphpanel.mousetools; import javax.swing.JPopupMenu; import org.wandora.application.gui.topicpanels.graphpanel.MouseTool; import org.wandora.application.gui.topicpanels.graphpanel.TopicMapGraphPanel; import org.wandora.application.gui.topicpanels.graphpanel.VEdge; import org.wandora.application.gui.topicpanels.graphpanel.VModel; import org.wandora.application.gui.topicpanels.graphpanel.VNode; /** * * @author olli */ public class MenuMouseTool extends MouseTool { /** Creates a new instance of MenuMouseTool */ public MenuMouseTool() { } @Override public boolean mouseClicked(TopicMapGraphPanel panel, int mousex, int mousey) { VNode mouseOverNode=panel.getMouseOverNode(); VEdge mouseOverEdge=panel.getMouseOverEdge(); VModel model=panel.getModel(); if(mouseOverNode!=null){ if(!mouseOverNode.isSelected()) model.setSelection(mouseOverNode); JPopupMenu menu=panel.getNodeMenu(); menu.show(panel,mousex,mousey); } else if(mouseOverEdge!=null){ if(!mouseOverEdge.isSelected()) model.setSelection(mouseOverEdge); JPopupMenu menu=panel.getEdgeMenu(); menu.show(panel,mousex,mousey); } else { JPopupMenu menu=panel.getGeneralMenu(); menu.show(panel,mousex,mousey); } return true; } }
2,334
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
ExpandMouseTool.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/mousetools/ExpandMouseTool.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * ExpandMouseTool.java * * Created on 25.6.2007, 9:39 * */ package org.wandora.application.gui.topicpanels.graphpanel.mousetools; import java.awt.Cursor; import org.wandora.application.gui.topicpanels.graphpanel.MouseTool; import org.wandora.application.gui.topicpanels.graphpanel.TopicMapGraphPanel; import org.wandora.application.gui.topicpanels.graphpanel.VModel; import org.wandora.application.gui.topicpanels.graphpanel.VNode; /** * * @author olli */ public class ExpandMouseTool extends MouseTool { /** Creates a new instance of ExpandMouseTool */ public ExpandMouseTool() { } @Override public boolean mouseClicked(TopicMapGraphPanel panel, int mousex,int mousey) { VNode mouseOverNode=panel.getMouseOverNode(); VModel model=panel.getModel(); if(mouseOverNode != null && model != null) { model.openNode(mouseOverNode); return true; } else return false; } @Override public Cursor getCursor(TopicMapGraphPanel panel, int mousex, int mousey){ VNode mouseOverNode=panel.getMouseOverNode(); if(mouseOverNode!=null) return Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); else return null; } }
2,059
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
OpenTopicMouseTool.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/mousetools/OpenTopicMouseTool.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * OpenTopicMouseTool.java * * Created on 25.6.2007, 10:14 * */ package org.wandora.application.gui.topicpanels.graphpanel.mousetools; import java.awt.Cursor; import org.wandora.application.Wandora; import org.wandora.application.gui.topicpanels.graphpanel.MouseTool; import org.wandora.application.gui.topicpanels.graphpanel.Node; import org.wandora.application.gui.topicpanels.graphpanel.TopicMapGraphPanel; import org.wandora.application.gui.topicpanels.graphpanel.TopicNode; import org.wandora.application.gui.topicpanels.graphpanel.VNode; import org.wandora.topicmap.Topic; /** * * @author olli */ public class OpenTopicMouseTool extends MouseTool { /** Creates a new instance of OpenTopicMouseTool */ public OpenTopicMouseTool() { } @Override public boolean mouseClicked(TopicMapGraphPanel panel, int mousex,int mousey) { VNode mouseOverNode = panel.getMouseOverNode(); if(mouseOverNode==null) return false; Node n = mouseOverNode.getNode(); Wandora wandora=panel.getWandora(); if(n instanceof TopicNode && wandora != null) { Topic t = ((TopicNode) n).getTopic(); wandora.applyChangesAndOpen(t); return true; } return false; } @Override public Cursor getCursor(TopicMapGraphPanel panel, int mousex, int mousey){ VNode mouseOverNode=panel.getMouseOverNode(); if(mouseOverNode!=null) return Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); else return null; } }
2,358
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
EraserTool.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/mousetools/EraserTool.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * EraserTool.java * * Created on 16.7.2007, 16:55 * */ package org.wandora.application.gui.topicpanels.graphpanel.mousetools; import java.awt.Cursor; import org.wandora.application.gui.topicpanels.graphpanel.MouseTool; import org.wandora.application.gui.topicpanels.graphpanel.TopicMapGraphPanel; import org.wandora.application.gui.topicpanels.graphpanel.VModel; import org.wandora.application.gui.topicpanels.graphpanel.VNode; /** * * @author akivela */ public class EraserTool extends MouseTool { /** Creates a new instance of EraserTool */ public EraserTool() { } @Override public boolean mouseClicked(TopicMapGraphPanel panel, int mousex,int mousey) { VNode mouseOverNode=panel.getMouseOverNode(); VModel model=panel.getModel(); if(mouseOverNode != null && model != null) { model.openNode(mouseOverNode); return true; } else return false; } @Override public Cursor getCursor(TopicMapGraphPanel panel, int mousex, int mousey){ VNode mouseOverNode=panel.getMouseOverNode(); if(mouseOverNode!=null) return Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); else return null; } }
2,045
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
RotateMouseTool.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/mousetools/RotateMouseTool.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * RotateMouseTool.java * * Created on 12.7.2007, 12:02 * */ package org.wandora.application.gui.topicpanels.graphpanel.mousetools; import java.awt.Cursor; import java.util.Set; import org.wandora.application.gui.topicpanels.graphpanel.MouseTool; import org.wandora.application.gui.topicpanels.graphpanel.TopicMapGraphPanel; import org.wandora.application.gui.topicpanels.graphpanel.VModel; import org.wandora.application.gui.topicpanels.graphpanel.VNode; import org.wandora.application.gui.topicpanels.graphpanel.projections.Projection; import org.wandora.utils.Tuples.T2; /** * * @author olli */ public class RotateMouseTool extends MouseTool { private boolean draggingView=false; private double dragAngle; public RotateMouseTool() { } @Override public boolean mouseReleased(TopicMapGraphPanel panel, int mousex,int mousey) { if(draggingView) { panel.releaseMouseTool(); draggingView=false; return true; } else return false; } @Override public boolean mousePressed(TopicMapGraphPanel panel, int mousex,int mousey) { if(panel.lockMouseTool(this)) { draggingView=true; T2<Double,Double> center = getRotationCenter(panel); T2<Double,Double> m = panel.getMouseWorldCoordinates(); dragAngle=Math.atan2(m.e2-center.e2, m.e1-center.e1); return true; } return false; } @Override public boolean mouseDragged(TopicMapGraphPanel panel, int mousex,int mousey) { if(draggingView && panel != null) { VModel model = panel.getModel(); if(model != null) { panel.setMouseFollowNode(null); T2<Double,Double> center = getRotationCenter(panel); T2<Double,Double> m = panel.getMouseWorldCoordinates(); double angle=Math.atan2(m.e2-center.e2, m.e1-center.e1); double d=angle-dragAngle; for(VNode vnode : model.getNodes()) { double dx=vnode.getX()-center.e1; double dy=vnode.getY()-center.e2; double l=Math.sqrt(dx*dx+dy*dy); double a=Math.atan2(dy,dx); vnode.setX(center.e1+l*Math.cos(a+d)); vnode.setY(center.e2+l*Math.sin(a+d)); } dragAngle=angle; } return true; } return false; } @Override public Cursor getCursor(TopicMapGraphPanel panel, int mousex, int mousey){ return Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR); } private T2<Double,Double> getRotationCenter(TopicMapGraphPanel panel) { double centerX = 0; double centerY = 0; VNode rootNode = panel.getRootNode(); if(rootNode != null) { centerX = rootNode.getX(); centerY = rootNode.getY(); } else { Set<VNode> selectedNodes = panel.getSelectedNodes(); if(selectedNodes != null && !selectedNodes.isEmpty()) { VNode selectedNode = selectedNodes.iterator().next(); if(selectedNode != null) { centerX = selectedNode.getX(); centerY = selectedNode.getY(); } } else { Projection projection = panel.getProjection(); if(projection != null) { T2<Double,Double> leftUpper = projection.screenToWorld(0, 0); T2<Double,Double> rightLower = projection.screenToWorld(panel.getWidth(), panel.getHeight()); centerX = leftUpper.e1 + ((rightLower.e1 - leftUpper.e1) / 2); centerY = leftUpper.e2 + ((rightLower.e2 - leftUpper.e2) / 2); } } } return new T2<>(centerX, centerY); } }
4,774
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
SelectMouseTool.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/mousetools/SelectMouseTool.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * SelectMouseTool.java * * Created on 25.6.2007, 10:18 * */ package org.wandora.application.gui.topicpanels.graphpanel.mousetools; import static org.wandora.utils.Tuples.t2; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Cursor; import java.awt.Graphics2D; import java.util.ArrayList; import java.util.List; import org.wandora.application.gui.topicpanels.graphpanel.MouseTool; import org.wandora.application.gui.topicpanels.graphpanel.TopicMapGraphPanel; import org.wandora.application.gui.topicpanels.graphpanel.VEdge; import org.wandora.application.gui.topicpanels.graphpanel.VModel; import org.wandora.application.gui.topicpanels.graphpanel.VNode; import org.wandora.application.gui.topicpanels.graphpanel.projections.Projection; import org.wandora.utils.Tuples.T2; /** * * @author olli */ public class SelectMouseTool extends MouseTool { private boolean drawingSelection=false; private List<T2<Double,Double>> selectPath; private boolean clearSelection; private boolean selectNodes; private boolean selectEdges; /** Creates a new instance of SelectMouseTool */ public SelectMouseTool(boolean selectNodes, boolean selectEdges, boolean clearSelection) { this.clearSelection=clearSelection; this.selectNodes=selectNodes; this.selectEdges=selectEdges; } public SelectMouseTool(boolean clearSelection) { this(true,true,clearSelection); } public SelectMouseTool() { this(true,true,true); } @Override public boolean mouseReleased(TopicMapGraphPanel panel, int mousex,int mousey) { if(drawingSelection){ panel.releaseMouseTool(); drawingSelection=false; VModel model=panel.getModel(); if(selectPath.size()>10){ if(clearSelection) model.deselectAll(); panel.selectNodesWithPath(selectPath); } return true; } else return false; } @Override public boolean mousePressed(TopicMapGraphPanel panel, int mousex,int mousey) { if(panel.lockMouseTool(this)){ drawingSelection=true; T2<Double,Double> m=panel.getMouseWorldCoordinates(); selectPath=new ArrayList<T2<Double,Double>>(); selectPath.add(t2(m.e1,m.e2)); return true; } return false; } @Override public boolean mouseDragged(TopicMapGraphPanel panel, int mousex,int mousey) { if(drawingSelection){ selectPath.add(panel.getMouseWorldCoordinates()); return true; } else return false; } @Override public boolean mouseClicked(TopicMapGraphPanel panel, int mousex,int mousey) { VNode mouseOverNode=panel.getMouseOverNode(); VEdge mouseOverEdge=panel.getMouseOverEdge(); VModel model=panel.getModel(); if(selectNodes && mouseOverNode!=null){ if(clearSelection) panel.getModel().deselectAll(); if(mouseOverNode.isSelected()) model.deselectNode(mouseOverNode); else model.addSelection(mouseOverNode); } else if(selectEdges && mouseOverEdge!=null){ if(clearSelection) panel.getModel().deselectAll(); if(mouseOverEdge.isSelected()) model.deselectEdge(mouseOverEdge); else model.addSelection(mouseOverEdge); } else{ model.deselectAll(); } return true; } @Override public void paint(Graphics2D g2,TopicMapGraphPanel panel){ if(drawingSelection){ g2.setColor(Color.LIGHT_GRAY); g2.setStroke(new BasicStroke(1)); Projection projection=panel.getProjection(); for(int i=0;i<selectPath.size()-1;i++){ T2<Double,Double> p1=selectPath.get(i); T2<Double,Double> p2=selectPath.get(i+1); p1=projection.worldToScreen(p1.e1,p1.e2); p2=projection.worldToScreen(p2.e1,p2.e2); g2.drawLine((int)p1.e1.doubleValue(),(int)p1.e2.doubleValue(), (int)p2.e1.doubleValue(),(int)p2.e2.doubleValue()); } } } @Override public Cursor getCursor(TopicMapGraphPanel panel, int mousex, int mousey){ VNode mouseOverNode=panel.getMouseOverNode(); if(mouseOverNode==null) return Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR); else return Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); } }
5,438
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
DrawAssociationMouseTool.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/mousetools/DrawAssociationMouseTool.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * DrawAssociationMouseTool.java * * Created on 6.7.2007, 12:38 * */ package org.wandora.application.gui.topicpanels.graphpanel.mousetools; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Cursor; import java.awt.Graphics2D; import java.util.Vector; import org.wandora.application.gui.FreeAssociationPrompt; import org.wandora.application.gui.topicpanels.graphpanel.Edge; import org.wandora.application.gui.topicpanels.graphpanel.MouseTool; import org.wandora.application.gui.topicpanels.graphpanel.Node; import org.wandora.application.gui.topicpanels.graphpanel.TopicMapGraphPanel; import org.wandora.application.gui.topicpanels.graphpanel.TopicMapModel; import org.wandora.application.gui.topicpanels.graphpanel.TopicNode; import org.wandora.application.gui.topicpanels.graphpanel.VModel; import org.wandora.application.gui.topicpanels.graphpanel.VNode; import org.wandora.application.gui.topicpanels.graphpanel.projections.Projection; import org.wandora.topicmap.Association; import org.wandora.topicmap.Topic; import org.wandora.topicmap.TopicMapException; import org.wandora.utils.Tuples.T2; /** * * @author olli */ public class DrawAssociationMouseTool extends MouseTool { private VNode startNode=null; private VNode endNode=null; /** Creates a new instance of DrawAssociationMouseTool */ public DrawAssociationMouseTool() { } @Override public boolean mouseReleased(TopicMapGraphPanel panel, int mousex,int mousey) { if(startNode!=null){ panel.releaseMouseTool(); if(endNode!=null){ Node sn=startNode.getNode(); Node en=endNode.getNode(); if(sn instanceof TopicNode && en instanceof TopicNode){ Vector<Topic> v=new Vector<>(); v.add(((TopicNode)sn).getTopic()); v.add(((TopicNode)en).getTopic()); try{ FreeAssociationPrompt d=new FreeAssociationPrompt(panel.getWandora(),v); d.prefill(false); d.setVisible(true); Association a=d.getCreatedAssociation(); if(a!=null) { TopicMapModel tmModel=panel.getTopicMapModel(); VModel vModel=panel.getModel(); Edge e=tmModel.getEdgeFor(a); if(e!=null) vModel.addEdge(e); else { Node n=tmModel.getNodeFor(a); if(n!=null){ VNode vn=vModel.addNode(n); vModel.openNode(vn); } } } } catch(TopicMapException tme){ tme.printStackTrace(); } } } startNode=null; endNode=null; return true; } else return false; } @Override public boolean mousePressed(TopicMapGraphPanel panel, int mousex,int mousey) { VNode mouseOverNode=panel.getMouseOverNode(); if(mouseOverNode!=null && panel.lockMouseTool(this)){ startNode=mouseOverNode; endNode=null; return true; } return false; } @Override public boolean mouseDragged(TopicMapGraphPanel panel, int mousex,int mousey) { if(startNode!=null){ VNode mouseOverNode=panel.getMouseOverNode(); if(mouseOverNode!=null && mouseOverNode!=startNode) endNode=mouseOverNode; else endNode=null; return true; } return false; } @Override public Cursor getCursor(TopicMapGraphPanel panel, int mousex, int mousey){ VNode mouseOverNode=panel.getMouseOverNode(); if(mouseOverNode!=null) return Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); else return null; } @Override public void paint(Graphics2D g2,TopicMapGraphPanel panel){ if(startNode!=null){ g2.setColor(Color.GRAY); g2.setStroke(new BasicStroke(2)); Projection proj=panel.getProjection(); T2<Double,Double> sp=proj.worldToScreen(startNode.getX(),startNode.getY()); if(endNode!=null){ T2<Double,Double> ep=proj.worldToScreen(endNode.getX(),endNode.getY()); g2.drawLine((int)sp.e1.doubleValue(),(int)sp.e2.doubleValue(), (int)ep.e1.doubleValue(),(int)ep.e2.doubleValue()); } else{ T2<Double,Double> m=panel.getMouseWorldCoordinates(); T2<Double,Double> ep=proj.worldToScreen(m.e1,m.e2); g2.drawLine((int)sp.e1.doubleValue(),(int)sp.e2.doubleValue(), (int)ep.e1.doubleValue(),(int)ep.e2.doubleValue()); } } } }
5,924
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
DragNodeMouseTool.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/mousetools/DragNodeMouseTool.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * DragNodeMouseTool.java * * Created on 25.6.2007, 12:12 * */ package org.wandora.application.gui.topicpanels.graphpanel.mousetools; import java.awt.Cursor; import org.wandora.application.gui.topicpanels.graphpanel.MouseTool; import org.wandora.application.gui.topicpanels.graphpanel.TopicMapGraphPanel; import org.wandora.application.gui.topicpanels.graphpanel.VNode; import org.wandora.utils.Tuples.T2; /** * * @author olli */ public class DragNodeMouseTool extends MouseTool { private boolean pinned=false; private VNode draggingNode=null; private double dragOffsX, dragOffsY, dragOffsX2, dragOffsY2; /** Creates a new instance of DragNodeMouseTool */ public DragNodeMouseTool() { } @Override public boolean mouseReleased(TopicMapGraphPanel panel, int mousex, int mousey) { if(draggingNode!=null) { draggingNode.setPinned(pinned); panel.releaseMouseTool(); draggingNode=null; return true; } else return false; } @Override public boolean mousePressed(TopicMapGraphPanel panel, int mousex, int mousey) { VNode mouseOverNode=panel.getMouseOverNode(); if(mouseOverNode!=null && panel.lockMouseTool(this)) { T2<Double,Double> m=panel.getMouseWorldCoordinates(); draggingNode=mouseOverNode; pinned=mouseOverNode.isPinned(); mouseOverNode.setPinned(true); dragOffsX=mouseOverNode.getX()-m.e1; dragOffsY=mouseOverNode.getY()-m.e2; return true; } return false; } @Override public boolean mouseDragged(TopicMapGraphPanel panel, int mousex, int mousey) { if(draggingNode!=null) { panel.setMouseFollowNode(null); T2<Double,Double> m=panel.getMouseWorldCoordinates(); draggingNode.setX(m.e1); draggingNode.setY(m.e2); return true; } return false; } @Override public Cursor getCursor(TopicMapGraphPanel panel, int mousex, int mousey){ VNode mouseOverNode=panel.getMouseOverNode(); if(mouseOverNode!=null) return Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR); else return null; } }
3,133
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
DefaultProjection.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/projections/DefaultProjection.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * DefaultProjection.java * * Created on 18.7.2007, 15:25 * */ package org.wandora.application.gui.topicpanels.graphpanel.projections; import static org.wandora.utils.Tuples.t2; import java.awt.Graphics2D; import javax.swing.Icon; import org.wandora.application.gui.UIBox; import org.wandora.utils.Options; import org.wandora.utils.Tuples.T2; /** * * @author olli, akivela */ public class DefaultProjection implements Projection { private double scale = 1.0; private double viewWidth = 0; private double viewHeight = 0; private double viewX = 0; private double viewY = 0; private double projectionSettings[][] = new double[][] { { 0.8 }, { 1.0 }, { 2.0 }, // scale { 4.0 }, { 8.0 }, { 16.0 } }; private int nextProjectionSettings = 0; public void useNextProjectionSettings() { if(nextProjectionSettings >= projectionSettings.length) nextProjectionSettings = 0; scale = projectionSettings[nextProjectionSettings][0]; nextProjectionSettings++; } public void modify(int param, double delta) { modify(param, delta, 1.5); } public void modify(int param, double delta, double multiplier) { switch(param) { case SCALE: { if(delta<0) scale*=Math.pow(multiplier,-delta); else scale/=Math.pow(multiplier,delta); break; } } } public void set(int param, double value) { switch(param) { case VIEW_X: viewX = value; case VIEW_Y: viewY = value; case VIEW_WIDTH: viewWidth = value; case VIEW_HEIGHT: viewHeight = value; case SCALE: scale = value; } } public double get(int param) { switch(param) { case VIEW_X: return viewX; case VIEW_Y: return viewY; case VIEW_WIDTH: return viewWidth; case VIEW_HEIGHT: return viewHeight; case SCALE: return scale; } return 0.0; } public double scale(double x, double y) { return scale; } public T2<Double,Double> worldToScreen(double x,double y){ return t2(viewWidth/2+(x-viewX)*scale,viewHeight/2-(y-viewY)*scale); } public T2<Double,Double> screenToWorld(double x,double y){ return t2((x-viewWidth/2)/scale+viewX,-(y-viewHeight/2)/scale+viewY); } public void draw(Graphics2D g){} public void initialize(Options options, String prefix) { scale=options.getDouble(prefix+"scale", 1.0); viewX=options.getDouble(prefix+"viewx", 0.0); viewY=options.getDouble(prefix+"viewy", 0.0); } public String getName() { return "Default projection"; } public String getDescription() { return getName(); } public Icon getIcon() { return UIBox.getIcon("gui/icons/empty.png"); } }
3,773
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
Projection.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/projections/Projection.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * Projection.java * * Created on 5.6.2007, 10:37 * */ package org.wandora.application.gui.topicpanels.graphpanel.projections; import javax.swing.Icon; import org.wandora.utils.Options; import org.wandora.utils.Tuples.T2; /** * * @author olli */ public interface Projection { public static final int VIEW_X = 10; public static final int VIEW_Y = 11; public static final int VIEW_WIDTH = 12; public static final int VIEW_HEIGHT = 13; public static final int MOUSEWHEEL1 = 100; public static final int MOUSEWHEEL2 = 200; public static final int SCALE = 100; public String getName(); public String getDescription(); public Icon getIcon(); public T2<Double,Double> worldToScreen(double x,double y); public T2<Double,Double> screenToWorld(double x,double y); public double scale(double x,double y); public void draw(java.awt.Graphics2D g); public void modify(int param, double delta, double multiplier); public void modify(int param, double delta); public void set(int param, double value); public double get(int param); public void initialize(Options options, String prefix); public void useNextProjectionSettings(); }
2,035
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
HyperbolicProjection.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/topicpanels/graphpanel/projections/HyperbolicProjection.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * HyperbolicProjection.java * * Created on 18.7.2007, 15:17 * */ package org.wandora.application.gui.topicpanels.graphpanel.projections; import static org.wandora.utils.Tuples.t2; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; import javax.swing.Icon; import org.wandora.application.gui.UIBox; import org.wandora.utils.Options; import org.wandora.utils.Tuples.T2; /** * * @author olli, akivela */ public class HyperbolicProjection implements Projection { public static final double MAX_SCALE_VALUE = 5.0; public static final double MIN_SCALE_VALUE = 0.05; public static final double MAX_CURVATURE_VALUE = 10.0; public static final double MIN_CURVATURE_VALUE = 0.5; private double scale = 1.0; private double curvature = 1.0; private double viewWidth = 0; private double viewHeight = 0; private double viewX = 0; private double viewY = 0; private Options options = null; private String optionsPrefix = ""; public static final int CURVATURE = 200; private double projectionSettings[][] = new double[][] { { 0.9, 0.8 }, { 1.0, 1.0 }, { 1.2, 2.0 }, // scale, curvature { 1.5, 4.0 }, { 1.7, 8.0 }, { 2.0, 16.0 } }; private int nextProjectionSettings = 0; @Override public void useNextProjectionSettings() { if(nextProjectionSettings >= projectionSettings.length) nextProjectionSettings = 0; scale = projectionSettings[nextProjectionSettings][0]; storeValue("scale", scale); curvature = projectionSettings[nextProjectionSettings][1]; storeValue("curvature", curvature); nextProjectionSettings++; precalc(); } @Override public void modify(int param, double delta) { modify(param, delta, 1.0); } @Override public void modify(int param, double delta, double multiplier) { switch(param) { case VIEW_X: { viewX += delta*multiplier; storeValue("viewx", viewX); break; } case VIEW_Y: { viewY += delta*multiplier; storeValue("viewy", viewY); break; } case VIEW_WIDTH: { viewWidth += delta; break; } case VIEW_HEIGHT: { viewHeight += delta; break; } case SCALE: { if(delta<0) scale*=Math.pow(multiplier,-delta); else scale/=Math.pow(multiplier,delta); if(scale > MAX_SCALE_VALUE) scale = MAX_SCALE_VALUE; if(scale < MIN_SCALE_VALUE) scale = MIN_SCALE_VALUE; storeValue("scale", scale); break; } case CURVATURE: { if(delta<0) curvature*=Math.pow(multiplier,-delta); else curvature/=Math.pow(multiplier,delta); if(curvature > MAX_CURVATURE_VALUE) curvature = MAX_CURVATURE_VALUE; if(curvature < MIN_CURVATURE_VALUE) curvature = MIN_CURVATURE_VALUE; storeValue("curvature", curvature); break; } } precalc(); } @Override public void set(int param, double value) { switch(param) { case VIEW_X: { viewX = value; storeValue("viewx", value); break; } case VIEW_Y: { viewY = value; storeValue("viewy", value); break; } case VIEW_WIDTH: { viewWidth = value; break; } case VIEW_HEIGHT: { viewHeight = value; break; } case SCALE: { scale = value; storeValue("scale", value); break; } case CURVATURE: { curvature = value; storeValue("curvature", value); break; } } precalc(); } @Override public double get(int param) { switch(param) { case VIEW_X: return viewX; case VIEW_Y: return viewY; case VIEW_WIDTH: return viewWidth; case VIEW_HEIGHT: return viewHeight; case SCALE: return scale; case CURVATURE: return curvature; } return 0.0; } private void precalc(){ viewR=viewWidth; if(viewHeight<viewWidth) viewR=viewHeight; viewR/=2.0/curvature; A=viewR*viewR/scale; ApViewR=A/viewR; } private double viewR=0.0; private double A=0.0; private double ApViewR=0.0; @Override public double scale(double x, double y) { double dx=x-viewX; double dy=y-viewY; double worldR=Math.sqrt(dx*dx+dy*dy); double screenR1=worldR*viewR/(worldR+ApViewR); double screenR2=(worldR+1.0)*viewR/(worldR+1.0+ApViewR); // return (screenR2-screenR1)*getScale(); return screenR2-screenR1; } @Override public T2<Double,Double> worldToScreen(double x,double y){ double dx=x-viewX; double dy=y-viewY; double worldR=Math.sqrt(dx*dx+dy*dy); double screenR=worldR*viewR/(worldR+ApViewR); return t2(viewWidth/2.0+dx/worldR*screenR,viewHeight/2.0-dy/worldR*screenR); } @Override public T2<Double,Double> screenToWorld(double x,double y){ double dx=x-viewWidth/2.0; double dy=viewHeight/2.0-y; double screenR=Math.sqrt(dx*dx+dy*dy); double worldR=0; if(screenR>=viewR) return t2(Double.NaN,Double.NaN); else worldR=A/(viewR-screenR)-ApViewR; return t2(viewX+dx/screenR*worldR,viewY+dy/screenR*worldR); } @Override public void draw(Graphics2D g) { g.setColor(Color.LIGHT_GRAY); g.setStroke(new BasicStroke(1)); g.drawOval((int)(viewWidth/2.0-viewR),(int)(viewHeight/2.0-viewR), (int)(viewR*2.0),(int)(viewR*2.0)); } @Override public void initialize(Options options, String prefix) { this.options = options; this.optionsPrefix = prefix; scale=options.getDouble(prefix+"scale", 1.0); curvature=options.getDouble(prefix+"curvature", 1.0); viewX=options.getDouble(prefix+"viewx", 0.0); viewY=options.getDouble(prefix+"viewy", 0.0); precalc(); } private synchronized void storeValue(String key, double value) { if(options != null) { options.put(optionsPrefix+key, value); } } @Override public String getName() { return "Hyperbolic projection"; } @Override public String getDescription() { return getName(); } @Override public Icon getIcon() { return UIBox.getIcon("gui/icons/empty.png"); } }
8,014
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z
TextEditor.java
/FileExtraction/Java_unseen/wandora-team_wandora/src/main/java/org/wandora/application/gui/texteditor/TextEditor.java
/* * WANDORA * Knowledge Extraction, Management, and Publishing Application * http://wandora.org * * Copyright (C) 2004-2023 Wandora Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * TextEditor.java * * Created on 5. toukokuuta 2006, 20:29 */ package org.wandora.application.gui.texteditor; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Point; import java.awt.event.ActionListener; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import javax.swing.Icon; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JMenu; import javax.swing.KeyStroke; import org.wandora.application.Wandora; import org.wandora.application.gui.UIBox; import org.wandora.application.gui.WandoraOptionPane; import org.wandora.application.gui.simple.SimpleMenu; import org.wandora.application.gui.simple.SimpleScrollPane; import org.wandora.application.gui.simple.SimpleTextPane; import org.wandora.utils.HTMLEntitiesCoder; import org.wandora.utils.Options; import org.wandora.utils.XMLbox; import com.fasterxml.jackson.databind.ObjectMapper; /** * * @author akivela */ public class TextEditor extends javax.swing.JDialog implements ActionListener { private static final long serialVersionUID = 1L; public static final int MAX_TEXT_SIZE = 999999; public static final String optionPrefix = "textEditor."; protected boolean acceptChanges; private boolean shouldWrapLines = true; private String fontFace = "Sans Serif"; private int fontSize = 12; private boolean inverseColors = false; protected SimpleTextPane simpleTextPane = null; protected Wandora wandora = null; protected JMenu fileMenu; protected JMenu editMenu; protected JMenu formatMenu; protected JDialog replaceDialog= null; public TextEditor(Wandora wandora, boolean modal, String initText) { this(wandora,modal,initText,null); } public TextEditor(Wandora wandora, boolean modal, String initText, String contentType) { super(wandora, modal); this.wandora = wandora; initComponents(); simpleTextPane = (SimpleTextPane) textPane; if(contentType!=null) simpleTextPane.setContentType(contentType); simpleTextPane.setForeground(Color.BLACK); simpleTextPane.setBackground(Color.WHITE); simpleTextPane.setSuperText(initText); simpleTextPane.setCaretPosition(0); simpleTextPane.setFocusTraversalKeysEnabled(false); initWindow(wandora); infoLabel.setText("Editing text"); } /** Creates new form TextEditor */ public TextEditor(Wandora wandora, boolean modal) { super(wandora, modal); this.wandora = wandora; initComponents(); initWindow(wandora); } public void setCancelButtonVisible(boolean v){ cancelButton.setVisible(v); } public String getOptionsPrefix(){ return optionPrefix; } public void initMenuBar(){ menuBar.add(getFileMenu()); menuBar.add(getEditMenu()); menuBar.add(getFormatMenu()); JMenu[] userMenus = getUserMenus(); if(userMenus != null) { for (JMenu m : userMenus) { if (m != null) { menuBar.add(m); } } } } public JMenu[] getUserMenus() { return null; } public void initWindow(Wandora wandora) { findPanel.setVisible(false); replacePanel.setVisible(false); Options options = wandora.options; if(options != null) { try { fontFace = options.get(getOptionsPrefix()+"font.face", "Sans Serif"); fontSize = options.getInt(getOptionsPrefix()+"font.size", 12); inverseColors = options.getBoolean(getOptionsPrefix()+"inverseColors", false); updateEditorFont(); updateEditorColors(); } catch(Exception e) {} } initMenuBar(); placeWindow(); } public void placeWindow() { boolean placedSuccessfully = false; Options options = wandora.options; if(options != null) { try { int x = Integer.parseInt(options.get(getOptionsPrefix()+"window.x")); int y = Integer.parseInt(options.get(getOptionsPrefix()+"window.y")); int width = Integer.parseInt(options.get(getOptionsPrefix()+"window.width")); int height = Integer.parseInt(options.get(getOptionsPrefix()+"window.height")); if(x > 0 && y > 0 && width > 0 && height > 0) { super.setSize(width, height); super.setLocation(x, y); placedSuccessfully = true; } } catch (Exception e) { System.out.println("No options for text editor. Using defaults!"); } } if(!placedSuccessfully) { Dimension preferred = new Dimension(700,400); String initText = textPane.getText(); if(initText != null) { if(initText.length() > 1000) preferred = new Dimension(900,500); else if(initText.length() > 500) preferred = new Dimension(800,400); } this.setSize(preferred); wandora.centerWindow(this); } } public void exitTextEditor(boolean acceptingChanges) { this.acceptChanges=acceptingChanges; try { Dimension d = super.getSize(); Point l = super.getLocation(); Options options = wandora.options; if(options != null) { options.put(getOptionsPrefix()+"window.width", d.width); options.put(getOptionsPrefix()+"window.height", d.height); options.put(getOptionsPrefix()+"window.x", this.getX()); options.put(getOptionsPrefix()+"window.y", this.getY()); options.put(getOptionsPrefix()+"font.face", this.fontFace); options.put(getOptionsPrefix()+"font.size", this.fontSize); options.put(getOptionsPrefix()+"inverseColors", inverseColors ? 1 : 0); } } catch (Exception e) { e.printStackTrace(); } this.setVisible(false); } public boolean acceptChanges() { return acceptChanges; } public JMenu getFileMenu() { fileMenu = new SimpleMenu("File", (Icon) null); Object[] menuStructure = new Object[] { "Open...", KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_DOWN_MASK), UIBox.getIcon("gui/icons/file_open.png"), "Save...", KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_DOWN_MASK), UIBox.getIcon("gui/icons/file_save.png"), "---", "Print...", KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P, java.awt.event.InputEvent.CTRL_DOWN_MASK), UIBox.getIcon("gui/icons/print.png"), "---", "Close", KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.CTRL_DOWN_MASK), UIBox.getIcon("gui/icons/exit.png"), }; fileMenu.removeAll(); UIBox.attachMenu( fileMenu, menuStructure, this ); return fileMenu; } public JMenu getEditMenu() { editMenu = new SimpleMenu("Edit", (Icon) null); Object[] menuStructure = new Object[] { "Undo", KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Z, java.awt.event.InputEvent.CTRL_DOWN_MASK), UIBox.getIcon("gui/icons/undo_undo.png"), "Redo", KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Y, java.awt.event.InputEvent.CTRL_DOWN_MASK), UIBox.getIcon("gui/icons/undo_redo.png"), "---", "Cut", KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_DOWN_MASK), UIBox.getIcon("gui/icons/cut.png"), "Copy", KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_DOWN_MASK), UIBox.getIcon("gui/icons/copy.png"), "Paste", KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_DOWN_MASK), UIBox.getIcon("gui/icons/paste.png"), "Clear", UIBox.getIcon("gui/icons/clear.png"), "Trim", KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_DOWN_MASK), UIBox.getIcon("gui/icons/trim.png"), "---", "Select all", KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_DOWN_MASK), UIBox.getIcon("gui/icons/select_all.png"), "---", "Find...", KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.CTRL_DOWN_MASK), UIBox.getIcon("gui/icons/find_generic.png"), "Replace...", KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_DOWN_MASK), UIBox.getIcon("gui/icons/replace.png"), "---", "Encode HTML entities", "Decode HTML entities", "Strip HTML tags", "Make HTML clean up", "Make XML clean up", "Prettyprint JSON", "---", "Uppercase", "Lowercase", }; editMenu.removeAll(); UIBox.attachMenu( editMenu, menuStructure, this ); return editMenu; } public JMenu getFormatMenu() { formatMenu = new SimpleMenu("Format", (Icon) null); updateFormatMenu(); return formatMenu; } public void updateFormatMenu() { Object[] menuStructure = new Object[] { (shouldWrapLines ? "X " : "") + "Wrap lines", KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L, java.awt.event.InputEvent.CTRL_DOWN_MASK), "---", "Font", new Object[] { ("Sans Serif".equalsIgnoreCase(fontFace) ? "X " : "") + "Sans Serif", ("Serif".equalsIgnoreCase(fontFace) ? "X " : "") + "Serif", ("Monospaced".equalsIgnoreCase(fontFace) ? "X " : "") + "Monospaced" }, "Font size", new Object[] { (fontSize == 9 ? "X " : "") + "9 px", (fontSize == 10 ? "X " : "") + "10 px", (fontSize == 12 ? "X " : "") + "12 px", (fontSize == 14 ? "X " : "") + "14 px", (fontSize == 16 ? "X " : "") + "16 px", (fontSize == 18 ? "X " : "") + "18 px", (fontSize == 20 ? "X " : "") + "20 px", (fontSize == 30 ? "X " : "") + "30 px" }, "---", "Inverse colors" }; formatMenu.removeAll(); UIBox.attachMenu( formatMenu, menuStructure, this ); } public String getText() { return textPane.getText(); } public String getSelectedText() { return this.textPane.getSelectedText(); } public void setText(String text) { textPane.setText(text); } public void setSuperText(String text) { ((SimpleTextPane) textPane).setSuperText(text); } public void setContentType(String contentType) { textPane.setContentType(contentType); } // ------------------------------------------------------------------------- // ----------------------------------------------------- EXECUTE ACTIONS --- // ------------------------------------------------------------------------- @Override public void actionPerformed(java.awt.event.ActionEvent actionEvent) { if(actionEvent == null) return; String c = actionEvent.getActionCommand(); if(c == null) return; try { // --- Edit ------------------------------- if("Trim".equalsIgnoreCase(c)) { String changeThis = simpleTextPane.getText(); simpleTextPane.setText(changeThis.trim()); } else if("Uppercase".equalsIgnoreCase(c)) { String changeThis = simpleTextPane.getSelectedOrAllText(); simpleTextPane.replaceSelectedOrAllText(changeThis.toUpperCase()); } else if("Lowercase".equalsIgnoreCase(c)) { String changeThis = simpleTextPane.getSelectedOrAllText(); simpleTextPane.replaceSelectedOrAllText(changeThis.toLowerCase()); } else if("Encode HTML entities".equalsIgnoreCase(c)) { String changeThis = simpleTextPane.getSelectedOrAllText(); simpleTextPane.replaceSelectedOrAllText(HTMLEntitiesCoder.encode(changeThis)); } else if("Decade HTML entities".equalsIgnoreCase(c)) { String changeThis = simpleTextPane.getSelectedOrAllText(); simpleTextPane.replaceSelectedOrAllText(HTMLEntitiesCoder.decode(changeThis)); } else if("Make HTML clean up".equalsIgnoreCase(c)) { String changeThis = simpleTextPane.getText(); org.w3c.tidy.Tidy tidy = new org.w3c.tidy.Tidy(); tidy.setTidyMark(false); ByteArrayOutputStream tidyOutput = null; tidyOutput = new ByteArrayOutputStream(); tidy.parse(new ByteArrayInputStream(changeThis.getBytes()), tidyOutput); simpleTextPane.setText(tidyOutput.toString()); } else if("Strip HTML tags".equalsIgnoreCase(c)) { String changeThis = simpleTextPane.getText(); simpleTextPane.setText(XMLbox.naiveGetAsText(changeThis)); } else if("Make XML clean up".equalsIgnoreCase(c)) { String changeThis = simpleTextPane.getText(); org.w3c.tidy.Tidy tidy = new org.w3c.tidy.Tidy(); tidy.setTidyMark(false); tidy.setXmlOut(true); tidy.setXmlPi(true); ByteArrayOutputStream tidyOutput = null; tidyOutput = new ByteArrayOutputStream(); tidy.parse(new ByteArrayInputStream(changeThis.getBytes()), tidyOutput); simpleTextPane.setText(tidyOutput.toString()); } else if("Prettyprint JSON".equalsIgnoreCase(c)) { String changeThis = simpleTextPane.getText(); String prettyOutput; try { ObjectMapper mapper = new ObjectMapper(); Object json = mapper.readValue(changeThis, Object.class); prettyOutput = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json); simpleTextPane.setText(prettyOutput); } catch (Exception objEx) { // Not a JSON Object WandoraOptionPane.showMessageDialog(Wandora.getWandora(), "Couldn't parse given text as JSON", "JSON parse error", WandoraOptionPane.INFORMATION_MESSAGE); } } else if("undo".equalsIgnoreCase(c)) { try { simpleTextPane.undo.undo(); infoLabel.setText("Undo OK!"); } catch(Exception e) { infoLabel.setText("Unable to undo!"); } } else if("redo".equalsIgnoreCase(c)) { try { simpleTextPane.undo.redo(); infoLabel.setText("Redo OK!"); } catch(Exception e) { infoLabel.setText("Unable to redo!"); } } else if("cut".equalsIgnoreCase(c)) { simpleTextPane.cut(); infoLabel.setText("Cut OK!"); } else if("copy".equalsIgnoreCase(c)) { simpleTextPane.copy(); infoLabel.setText("Copy OK!"); } else if("paste".equalsIgnoreCase(c)) { simpleTextPane.paste(); infoLabel.setText("Paste OK!"); } else if("clear".equalsIgnoreCase(c)) { simpleTextPane.setText(""); infoLabel.setText("Clear OK!"); } else if("find...".equalsIgnoreCase(c)) { findPanel.setVisible(true); replacePanel.setVisible(false); findTextField.requestFocus(); } else if("replace...".equalsIgnoreCase(c)) { findPanel.setVisible(true); replacePanel.setVisible(true); findTextField.requestFocus(); } else if("select all".equalsIgnoreCase(c)) { simpleTextPane.selectAll(); infoLabel.setText("Select all OK!"); } // --- File ------------------------------- else if("open...".equalsIgnoreCase(c)) { infoLabel.setText("Reading text from file!"); simpleTextPane.load(); infoLabel.setText("OK!"); } else if("save...".equalsIgnoreCase(c)) { infoLabel.setText("Saving text to file!"); simpleTextPane.save(); infoLabel.setText("OK!"); } else if("print...".equalsIgnoreCase(c)) { infoLabel.setText("Printing text!"); try{ simpleTextPane.print(); } catch(java.awt.print.PrinterException pe){ wandora.handleError(pe); } } else if("close".equalsIgnoreCase(c)) { //int a = WandoraOptionPane.showConfirmDialog(wandora, "Accept changes?", "Accept changes?", WandoraOptionPane.OK_CANCEL_OPTION); JDialog acceptDialog = new JDialog(this, true); acceptDialog.setTitle("Accept changes?"); acceptDialog.add(acceptPanel); acceptDialog.setSize(350, 180); wandora.centerWindow(acceptDialog, this); acceptDialog.setVisible(true); } // --- Format ------------------------- else if("wrap lines".equalsIgnoreCase(c)) { wrapLines(); } else if("Sans Serif".equalsIgnoreCase(c)) { fontFace = "Sans Serif"; updateEditorFont(); } else if("Serif".equalsIgnoreCase(c)) { fontFace = "Serif"; updateEditorFont(); } else if("Monospaced".equalsIgnoreCase(c)) { fontFace = "Monospaced"; updateEditorFont(); } else if(c.endsWith(" px")) { String[] parts = c.split(" "); String size = parts[0]; try { fontSize = Integer.parseInt(size); } catch(Exception e) {} updateEditorFont(); } else if("Inverse colors".equalsIgnoreCase(c)) { inverseColors = !inverseColors; updateEditorColors(); } else { System.out.println("Passing actionEvent '"+c+"' to SimpleTextPane."); simpleTextPane.actionPerformed(actionEvent); } } catch(Exception e) { e.printStackTrace(); } } private void updateEditorFont() { simpleTextPane.setFont(new Font(fontFace, Font.PLAIN, fontSize)); updateFormatMenu(); } private void updateEditorColors() { Color background = Color.WHITE; Color foreground = Color.BLACK; if(inverseColors) { background = Color.BLACK; foreground = Color.WHITE; } simpleTextPane.setForeground(foreground); simpleTextPane.setBackground(background); } public void setCustomButtons(JComponent custom) { this.customButtons.add(custom); } public void wrapLines() { wrapLines(!shouldWrapLines); } public void wrapLines(boolean shouldWrap) { shouldWrapLines = shouldWrap; updateFormatMenu(); simpleTextPane.setLineWrap(shouldWrapLines); if(shouldWrapLines) infoLabel.setText("Line wrap set ON"); else infoLabel.setText("Line wrap set OFF"); } public void refreshCaretInfo() { try { int pos = simpleTextPane.getCaretPosition(); int len = simpleTextPane.getDocument().getLength(); infoLabel.setText("" + pos + "/" + len); } catch(Exception e) { e.printStackTrace(); } } // ------------------------------------------------------------------------- /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; acceptPanel = new javax.swing.JPanel(); acceptLabel = new org.wandora.application.gui.simple.SimpleLabel(); jPanel1 = new javax.swing.JPanel(); acceptButton = new org.wandora.application.gui.simple.SimpleButton(); rejectButton = new org.wandora.application.gui.simple.SimpleButton(); editorPanel = new javax.swing.JPanel(); toolPanel = new javax.swing.JPanel(); findPanel = new javax.swing.JPanel(); findTextField = new org.wandora.application.gui.simple.SimpleField(); findButton = new org.wandora.application.gui.simple.SimpleButton(); replacePanel = new javax.swing.JPanel(); replaceLabel = new org.wandora.application.gui.simple.SimpleLabel(); replaceTextField = new org.wandora.application.gui.simple.SimpleField(); replaceButton = new org.wandora.application.gui.simple.SimpleButton(); replaceAllButton = new org.wandora.application.gui.simple.SimpleButton(); jSeparator1 = new javax.swing.JSeparator(); findCloseButton = new org.wandora.application.gui.simple.SimpleButton(); centerPanel = new javax.swing.JPanel(); scrollPane = new SimpleScrollPane(); textPane = new SimpleTextPane(); buttonPanel = new javax.swing.JPanel(); infoLabel = new org.wandora.application.gui.simple.SimpleLabel(); customButtons = new javax.swing.JPanel(); okButton = new org.wandora.application.gui.simple.SimpleButton(); cancelButton = new org.wandora.application.gui.simple.SimpleButton(); menuBar = new javax.swing.JMenuBar(); acceptPanel.setLayout(new java.awt.GridBagLayout()); acceptLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); acceptLabel.setText("Do you accept text changes?"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridwidth = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); acceptPanel.add(acceptLabel, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; acceptPanel.add(jPanel1, gridBagConstraints); acceptButton.setText("Accept"); acceptButton.setMargin(new java.awt.Insets(1, 14, 1, 14)); acceptButton.setPreferredSize(new java.awt.Dimension(70, 21)); acceptButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { acceptButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridy = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(0, 4, 4, 2); acceptPanel.add(acceptButton, gridBagConstraints); rejectButton.setText("Reject"); rejectButton.setMargin(new java.awt.Insets(1, 14, 1, 14)); rejectButton.setPreferredSize(new java.awt.Dimension(70, 21)); rejectButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { rejectButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridy = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 4); acceptPanel.add(rejectButton, gridBagConstraints); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Edit text"); setName("textEditorDialog"); // NOI18N editorPanel.setLayout(new java.awt.BorderLayout()); toolPanel.setLayout(new java.awt.BorderLayout()); findPanel.setLayout(new java.awt.GridBagLayout()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 3); findPanel.add(findTextField, gridBagConstraints); findButton.setFont(org.wandora.application.gui.UIConstants.smallButtonLabelFont); findButton.setText("Find"); findButton.setMargin(new java.awt.Insets(2, 2, 2, 2)); findButton.setMaximumSize(new java.awt.Dimension(50, 23)); findButton.setMinimumSize(new java.awt.Dimension(50, 20)); findButton.setPreferredSize(new java.awt.Dimension(50, 20)); findButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { findActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.insets = new java.awt.Insets(4, 0, 4, 4); findPanel.add(findButton, gridBagConstraints); replacePanel.setLayout(new java.awt.GridBagLayout()); replaceLabel.setFont(org.wandora.application.gui.UIConstants.smallButtonLabelFont); replaceLabel.setText("replace with"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 3); replacePanel.add(replaceLabel, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 3); replacePanel.add(replaceTextField, gridBagConstraints); replaceButton.setFont(org.wandora.application.gui.UIConstants.smallButtonLabelFont); replaceButton.setText("Replace"); replaceButton.setMargin(new java.awt.Insets(2, 2, 2, 2)); replaceButton.setMaximumSize(new java.awt.Dimension(60, 23)); replaceButton.setMinimumSize(new java.awt.Dimension(60, 20)); replaceButton.setPreferredSize(new java.awt.Dimension(60, 20)); replaceButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { replaceButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 3); replacePanel.add(replaceButton, gridBagConstraints); replaceAllButton.setFont(org.wandora.application.gui.UIConstants.smallButtonLabelFont); replaceAllButton.setText("All"); replaceAllButton.setToolTipText("Replace All"); replaceAllButton.setMargin(new java.awt.Insets(2, 2, 2, 2)); replaceAllButton.setMaximumSize(new java.awt.Dimension(50, 23)); replaceAllButton.setMinimumSize(new java.awt.Dimension(50, 20)); replaceAllButton.setPreferredSize(new java.awt.Dimension(50, 20)); replaceAllButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { replaceAllButtonActionPerformed(evt); } }); replacePanel.add(replaceAllButton, new java.awt.GridBagConstraints()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 0); findPanel.add(replacePanel, gridBagConstraints); jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL; gridBagConstraints.insets = new java.awt.Insets(7, 3, 7, 3); findPanel.add(jSeparator1, gridBagConstraints); findCloseButton.setFont(org.wandora.application.gui.UIConstants.smallButtonLabelFont); findCloseButton.setActionCommand("Close"); findCloseButton.setLabel("Hide"); findCloseButton.setMargin(new java.awt.Insets(2, 2, 2, 2)); findCloseButton.setMaximumSize(new java.awt.Dimension(50, 23)); findCloseButton.setMinimumSize(new java.awt.Dimension(50, 20)); findCloseButton.setPreferredSize(new java.awt.Dimension(50, 20)); findCloseButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { findCloseButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.insets = new java.awt.Insets(4, 0, 4, 4); findPanel.add(findCloseButton, gridBagConstraints); toolPanel.add(findPanel, java.awt.BorderLayout.CENTER); editorPanel.add(toolPanel, java.awt.BorderLayout.NORTH); centerPanel.setLayout(new java.awt.BorderLayout()); scrollPane.setBackground(new java.awt.Color(255, 255, 255)); textPane.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { textChangeRegistered(evt); } }); textPane.addCaretListener(new javax.swing.event.CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent evt) { refreshCaretPositionInfo(evt); } }); scrollPane.setViewportView(textPane); centerPanel.add(scrollPane, java.awt.BorderLayout.CENTER); editorPanel.add(centerPanel, java.awt.BorderLayout.CENTER); getContentPane().add(editorPanel, java.awt.BorderLayout.CENTER); buttonPanel.setLayout(new java.awt.GridBagLayout()); infoLabel.setFont(org.wandora.application.gui.UIConstants.smallButtonLabelFont); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(3, 5, 0, 5); buttonPanel.add(infoLabel, gridBagConstraints); customButtons.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT, 5, 0)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); buttonPanel.add(customButtons, gridBagConstraints); okButton.setText("OK"); okButton.setMargin(new java.awt.Insets(2, 2, 2, 2)); okButton.setMaximumSize(new java.awt.Dimension(70, 23)); okButton.setMinimumSize(new java.awt.Dimension(70, 23)); okButton.setPreferredSize(new java.awt.Dimension(70, 23)); okButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseReleased(java.awt.event.MouseEvent evt) { acceptEditedText(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.insets = new java.awt.Insets(4, 0, 4, 0); buttonPanel.add(okButton, gridBagConstraints); cancelButton.setText("Cancel"); cancelButton.setMargin(new java.awt.Insets(2, 2, 2, 2)); cancelButton.setMaximumSize(new java.awt.Dimension(70, 23)); cancelButton.setMinimumSize(new java.awt.Dimension(70, 23)); cancelButton.setPreferredSize(new java.awt.Dimension(70, 23)); cancelButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseReleased(java.awt.event.MouseEvent evt) { cancelEdit(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.insets = new java.awt.Insets(4, 3, 4, 4); buttonPanel.add(cancelButton, gridBagConstraints); getContentPane().add(buttonPanel, java.awt.BorderLayout.SOUTH); setJMenuBar(menuBar); pack(); }// </editor-fold>//GEN-END:initComponents private void rejectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rejectButtonActionPerformed exitTextEditor(false); }//GEN-LAST:event_rejectButtonActionPerformed private void acceptButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_acceptButtonActionPerformed exitTextEditor(true); }//GEN-LAST:event_acceptButtonActionPerformed private void replaceAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_replaceAllButtonActionPerformed int replaceCount = ((SimpleTextPane) textPane).findAndReplaceAll(findTextField.getText(), replaceTextField.getText()); infoLabel.setText("Replaced "+replaceCount+ " OK!"); }//GEN-LAST:event_replaceAllButtonActionPerformed private void replaceButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_replaceButtonActionPerformed boolean found = ((SimpleTextPane) textPane).findAndReplaceNext(findTextField.getText(), replaceTextField.getText()); if(found) infoLabel.setText("Replace OK!"); else infoLabel.setText("No text replaced!"); }//GEN-LAST:event_replaceButtonActionPerformed private void findCloseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findCloseButtonActionPerformed findPanel.setVisible(false); replacePanel.setVisible(false); }//GEN-LAST:event_findCloseButtonActionPerformed private void findActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findActionPerformed boolean found = ((SimpleTextPane) textPane).findAndSelectNext(findTextField.getText()); if(found) infoLabel.setText("Found next!"); else infoLabel.setText("No text found!"); }//GEN-LAST:event_findActionPerformed private void refreshCaretPositionInfo(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_refreshCaretPositionInfo refreshCaretInfo(); }//GEN-LAST:event_refreshCaretPositionInfo private void textChangeRegistered(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textChangeRegistered refreshCaretInfo(); }//GEN-LAST:event_textChangeRegistered private void cancelEdit(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cancelEdit exitTextEditor(false); }//GEN-LAST:event_cancelEdit private void acceptEditedText(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_acceptEditedText exitTextEditor(true); }//GEN-LAST:event_acceptEditedText // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton acceptButton; private javax.swing.JLabel acceptLabel; private javax.swing.JPanel acceptPanel; protected javax.swing.JPanel buttonPanel; protected javax.swing.JButton cancelButton; protected javax.swing.JPanel centerPanel; protected javax.swing.JPanel customButtons; protected javax.swing.JPanel editorPanel; protected javax.swing.JButton findButton; protected javax.swing.JButton findCloseButton; protected javax.swing.JPanel findPanel; protected javax.swing.JTextField findTextField; protected javax.swing.JLabel infoLabel; private javax.swing.JPanel jPanel1; private javax.swing.JSeparator jSeparator1; protected javax.swing.JMenuBar menuBar; protected javax.swing.JButton okButton; private javax.swing.JButton rejectButton; protected javax.swing.JButton replaceAllButton; protected javax.swing.JButton replaceButton; protected javax.swing.JLabel replaceLabel; protected javax.swing.JPanel replacePanel; protected javax.swing.JTextField replaceTextField; protected javax.swing.JScrollPane scrollPane; private javax.swing.JTextPane textPane; protected javax.swing.JPanel toolPanel; // End of variables declaration//GEN-END:variables }
38,921
Java
.java
wandora-team/wandora
126
26
0
2014-06-30T10:25:42Z
2023-09-09T07:13:29Z