public void createArrow(ActionListener listener) { setMargin(new Insets(0, 0, 0, 0)); BasicArrowButton arrowButton = new BasicArrowButton(SwingConstants.SOUTH, null, null, Color.BLACK, null); arrowButton.setBorder(BorderFactory.createEmptyBorder()); add(arrowButton, BorderLayout.EAST); arrowButton.addActionListener(listener); }
@Override protected JButton createArrowButton() { JButton button = super.createArrowButton(); if (button instanceof BasicArrowButton) { ((BasicArrowButton) button).setDirection(SwingConstants.EAST); } return button; }
private JPanel getRow(final ZoneUnit zoneUnit) { JPanel rowPanel = new JPanel(); rowPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 5)); JLabel label = new JLabel(zoneUnit.toString()); rowPanel.add(label); JPanel buttonPane = new JPanel(); BasicArrowButton btnUpButton = new BasicArrowButton(BasicArrowButton.NORTH); btnUpButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub int idx = units.indexOf(zoneUnit); if (idx == 0) return; ZoneUnit z = units.get(idx); units.set(idx, units.set(idx - 1, z)); mainPanelUpdate(); } }); buttonPane.add(btnUpButton); BasicArrowButton btnDownButton = new BasicArrowButton(BasicArrowButton.SOUTH); btnDownButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub int idx = units.indexOf(zoneUnit); if (idx == units.size() - 1) return; ZoneUnit z = units.get(idx); units.set(idx, units.set(idx + 1, z)); mainPanelUpdate(); } }); buttonPane.add(btnDownButton); rowPanel.add(buttonPane); return rowPanel; }
/** * Constructs a new <code>RecentRelationsAction</code>. * * @param editButton edit button */ public RecentRelationsAction(SideButton editButton) { this.editButton = editButton; arrow = editButton.createArrow(this); arrow.setToolTipText(tr("List of recent relations")); Main.main.undoRedo.addCommandQueueListener(this); Main.getLayerManager().addLayerChangeListener(this); Main.getLayerManager().addActiveLayerChangeListener(this); enableArrow(); shortcut = Shortcut.registerShortcut( "relationeditor:editrecentrelation", tr("Relation Editor: {0}", tr("Open recent relation")), KeyEvent.VK_ESCAPE, Shortcut.SHIFT); Main.registerActionShortcut(new LaunchEditorAction(), shortcut); }
/** * Constructs a new <code>RecentRelationsAction</code>. * * @param editButton edit button */ public RecentRelationsAction(SideButton editButton) { this.editButton = editButton; arrow = editButton.createArrow(this); arrow.setToolTipText(tr("List of recent relations")); Main.main.undoRedo.addCommandQueueListener(this); MapView.addLayerChangeListener(this); enableArrow(); shortcut = Shortcut.registerShortcut( "relationeditor:editrecentrelation", tr("Relation Editor: {0}", tr("Open recent relation")), KeyEvent.VK_ESCAPE, Shortcut.SHIFT); Main.registerActionShortcut( new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { EditRelationAction.launchEditor(getLastRelation()); } }, shortcut); }
/** Enables arrow button. */ public void enableArrow() { arrow.setEnabled(getLastRelation() != null); }
// Tasks UI void drawTaskPanel() { if (processId != null) { Collection<Task> tasks = CurrentProject.getProcessList().getProcess(processId).getTasks(); taskIds = new ArrayList<>(); List<Task> taskList = new ArrayList<>(tasks); DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); GridBagConstraints gc = new GridBagConstraints(); gc.ipadx = 3; gc.ipady = 3; gc.gridy = 0; gc.weightx = 1; gc.weighty = 1; gc.anchor = GridBagConstraints.WEST; taskInnerPanel = new JPanel(new GridBagLayout()); { JLabel title = new JLabel(Local.getString("Task")); JLabel status = new JLabel(Local.getString("Status")); JLabel priority = new JLabel(Local.getString("Priority")); gc.gridx = 1; taskInnerPanel.add(title, gc); gc.gridx = 2; taskInnerPanel.add(status, gc); gc.gridx = 3; taskInnerPanel.add(priority, gc); } for (Task task : taskList) { Util.debug("Adding task: " + task.getText()); BasicArrowButton up = new BasicArrowButton(BasicArrowButton.NORTH); BasicArrowButton dn = new BasicArrowButton(BasicArrowButton.SOUTH); JLabel title = new JLabel(task.getText()); JLabel status = new JLabel(task.getStatusString()); JLabel priority = new JLabel(task.getPriorityString()); gc.gridy = gc.gridy + 1; gc.gridx = 0; gc.gridx = 1; gc.anchor = GridBagConstraints.WEST; taskInnerPanel.add(title, gc); gc.gridx = 2; taskInnerPanel.add(status, gc); gc.gridx = 3; taskInnerPanel.add(priority, gc); gc.gridx = 4; gc.anchor = GridBagConstraints.CENTER; taskInnerPanel.add(up, gc); gc.gridx = 5; gc.anchor = GridBagConstraints.CENTER; taskInnerPanel.add(dn, gc); up.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent action) { int index = taskList.indexOf(task); if (index > 0) { Collections.swap(taskList, index, index - 1); Collections.swap(taskIds, index, index - 1); sortTasks(taskIds); } } }); dn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent action) { int index = taskList.indexOf(task); if (index < taskList.size() - 1) { Collections.swap(taskList, index, index + 1); Collections.swap(taskIds, index, index + 1); sortTasks(taskIds); } } }); taskIds.add(task.getID()); } taskScrollPane = new JScrollPane(taskInnerPanel); taskPanel = new JPanel(new BorderLayout()); taskPanel.setPreferredSize(new Dimension(400, 300)); taskPanel.setBorder(defaultBorder); taskPanel.add(taskScrollPane, BorderLayout.CENTER); this.getContentPane().add(taskPanel, BorderLayout.CENTER); } }
public MokumFrame() { setTitle("Heuristieken 2014 - Mokum Airlines! - Group 4 \"De Vliegende Hollanders\""); setLayout(new BorderLayout()); setSize(1024, 768); frame = this; Dienstregeling dienstregeling = maakDienstregeling(); schaal = new Scrollbar(); schaal.setMaximum(100); schaal.setMinimum(1); schaal.setOrientation(Scrollbar.HORIZONTAL); schaal.setValue(45); schaal.setPreferredSize(new Dimension(250, 20)); redrawButton = new Button("Redraw!"); left = new BasicArrowButton(BasicArrowButton.WEST); right = new BasicArrowButton(BasicArrowButton.EAST); traffic = new GlobalTraffic(dienstregeling); dienst = new DienstregelingCanvas(dienstregeling); schaal.addAdjustmentListener( new AdjustmentListener() { // Houdt bij of er aan de scrollbar gezet is of niet public void adjustmentValueChanged(AdjustmentEvent e) { double scaleFactor = (double) schaal.getValue() / 100; dienst.setScaleFactor(scaleFactor); frame.redraw(200); } }); redrawButton.addActionListener( new ActionListener() { // Houdt bij of er op de knop gedrukt is public void actionPerformed(ActionEvent evt) { if (evt.getSource() == redrawButton) { Dienstregeling dienstregeling = maakDienstregeling(); traffic.setDienstregeling(dienstregeling); dienst.setDienstregeling(dienstregeling); frame.redraw(200); } } }); left.addActionListener( new ActionListener() { // Houdt bij of er op de knop gedrukt is public void actionPerformed(ActionEvent evt) { if (evt.getSource() == left) { int val = schaal.getValue(); schaal.setValue(val - 1); double scaleFactor = (double) schaal.getValue() / 100; dienst.setScaleFactor(scaleFactor); frame.redraw(200); } } }); right.addActionListener( new ActionListener() { // Houdt bij of er op de knop gedrukt is public void actionPerformed(ActionEvent evt) { if (evt.getSource() == right) { int val = schaal.getValue(); schaal.setValue(val + 1); double scaleFactor = (double) schaal.getValue() / 100; dienst.setScaleFactor(scaleFactor); frame.redraw(200); } } }); Panel buttonPane = new Panel(); buttonPane.setLayout(new FlowLayout()); buttonPane.add(left); buttonPane.add(schaal); buttonPane.add(right); buttonPane.add(redrawButton); buttonPane.setPreferredSize(new Dimension(1024, 40)); this.add(buttonPane, BorderLayout.SOUTH); JPanel topPanel = new JPanel(); topPanel.add(traffic, BorderLayout.CENTER); traffic.setLocation(frame.getWidth() / 2, 0); this.add(topPanel, BorderLayout.NORTH); this.add(dienst, BorderLayout.CENTER); // Exit the program when the window is closed frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Close the window when escape is pressed this.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { super.keyPressed(e); if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { System.exit(0); } } }); mouseX = 0; mouseY = 0; this.addMouseMotionListener( new MouseMotionAdapter() { @Override public void mouseMoved(MouseEvent e) { super.mouseMoved(e); mouseX = (e.getX()); mouseY = (e.getY()) - 25; // offset the 25px top bar mouseposition.setText(String.format("Mouse: %d, %d", mouseX, mouseY)); } }); mouseposition = new JLabel("Mouse:"); buttonPane.add(mouseposition); // Resize the window pack(); setVisible(true); frame.redraw(200); }
/** Enables arrow button. */ public void enableArrow() { arrow.setVisible(getLastRelation() != null); }
/** Create panel at the bottom with differents consoles to report injection process. */ public PanelBottom() { // Object creation after customization this.consoleTab.getProxy().setEditable(false); SwingAppender.register(this.consoleTab); this.chunkTab = new JPopupTextArea().getProxy(); this.chunkTab.setEditable(false); this.binaryTab = new JPopupTextArea().getProxy(); this.binaryTab.setEditable(false); this.javaTab.getProxy().setEditable(false); SwingAppender.register(this.javaTab); this.network = new JSplitPaneWithZeroSizeDivider(); this.network.setResizeWeight(1); this.network.setDividerSize(0); this.network.setDividerLocation(600); this.network.setBorder(BorderFactory.createMatteBorder(1, 1, 0, 0, HelperGUI.COMPONENT_BORDER)); this.networkTable = new JTable(0, 4) { @Override public boolean isCellEditable(int row, int column) { return false; } @Override public String getToolTipText(MouseEvent e) { String tip = null; java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); int colIndex = columnAtPoint(p); try { // comment row, exclude heading if (rowIndex != 0 && colIndex == 1) { tip = getValueAt(rowIndex, colIndex).toString(); } } catch (RuntimeException e1) { // catch null pointer exception if mouse is over an empty line } return "<html><p width=\"1024\">" + tip + "</p></html>"; } }; new TableFilterHeader(this.networkTable, AutoChoices.ENABLED); this.networkTable.setComponentPopupMenu(new JPopupMenuTable(this.networkTable)); this.networkTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN); this.networkTable.setRowSelectionAllowed(true); this.networkTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); this.networkTable.setRowHeight(20); this.networkTable.setGridColor(Color.LIGHT_GRAY); this.networkTable.getTableHeader().setReorderingAllowed(false); this.networkTable.addMouseListener( new MouseAdapter() { public void mousePressed(MouseEvent e) { PanelBottom.this.networkTable.requestFocusInWindow(); // move selected row and place cursor on focused cell if (SwingUtilities.isRightMouseButton(e)) { Point p = e.getPoint(); // get the row index that contains that coordinate int rowNumber = PanelBottom.this.networkTable.rowAtPoint(p); int colNumber = PanelBottom.this.networkTable.columnAtPoint(p); // Get the ListSelectionModel of the JTable DefaultListSelectionModel model = (DefaultListSelectionModel) PanelBottom.this.networkTable.getSelectionModel(); DefaultListSelectionModel model2 = (DefaultListSelectionModel) PanelBottom.this.networkTable.getColumnModel().getSelectionModel(); PanelBottom.this.networkTable.setRowSelectionInterval(rowNumber, rowNumber); model.moveLeadSelectionIndex(rowNumber); model2.moveLeadSelectionIndex(colNumber); } } }); this.networkTable.setModel( new DefaultTableModel() { private String[] columns = { I18n.NETWORK_TAB_METHOD_COLUMN, I18n.NETWORK_TAB_URL_COLUMN, I18n.NETWORK_TAB_SIZE_COLUMN, I18n.NETWORK_TAB_TYPE_COLUMN }; @Override public int getColumnCount() { return this.columns.length; } @Override public String getColumnName(int index) { return this.columns[index]; } }); class CenterRenderer extends DefaultTableCellRenderer { public CenterRenderer() { this.setHorizontalAlignment(JLabel.CENTER); } } DefaultTableCellRenderer centerHorizontalAlignment = new CenterRenderer(); this.networkTable.getColumnModel().getColumn(2).setCellRenderer(centerHorizontalAlignment); this.networkTable.getColumnModel().getColumn(3).setCellRenderer(centerHorizontalAlignment); this.networkTable .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), null); this.networkTable .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_DOWN_MASK), null); Set<AWTKeyStroke> forward = new HashSet<AWTKeyStroke>( this.networkTable.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS)); forward.add(KeyStroke.getKeyStroke("TAB")); this.networkTable.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forward); Set<AWTKeyStroke> backward = new HashSet<AWTKeyStroke>( this.networkTable.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS)); backward.add(KeyStroke.getKeyStroke("shift TAB")); this.networkTable.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, backward); final TableCellRenderer tcrOs = this.networkTable.getTableHeader().getDefaultRenderer(); this.networkTable .getTableHeader() .setDefaultRenderer( new TableCellRenderer() { @Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel lbl = (JLabel) tcrOs.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column); lbl.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createMatteBorder(0, 0, 1, 1, Color.LIGHT_GRAY), BorderFactory.createEmptyBorder(0, 5, 0, 5))); return lbl; } }); JScrollIndicator scroller = new JScrollIndicator(this.networkTable); scroller.scrollPane.setBorder(BorderFactory.createEmptyBorder(0, 0, -1, -1)); scroller.scrollPane.setViewportBorder(BorderFactory.createEmptyBorder(0, 0, -1, -1)); this.network.setLeftComponent(scroller); MouseTabbedPane networkDetailTabs = new MouseTabbedPane(); networkDetailTabs.addTab( I18n.NETWORK_TAB_RESPONSE_LABEL, new LightScrollPane(1, 1, 0, 0, networkTabResponse)); networkDetailTabs.addTab( I18n.NETWORK_TAB_SOURCE_LABEL, new LightScrollPane(1, 1, 0, 0, networkTabSource)); networkDetailTabs.addTab( I18n.NETWORK_TAB_PREVIEW_LABEL, new LightScrollPane(1, 1, 0, 0, networkTabPreview)); networkDetailTabs.addTab( I18n.NETWORK_TAB_HEADERS_LABEL, new LightScrollPane(1, 1, 0, 0, networkTabHeader)); networkDetailTabs.addTab( I18n.NETWORK_TAB_COOKIES_LABEL, new LightScrollPane(1, 1, 0, 0, networkTabCookie)); networkDetailTabs.addTab( I18n.NETWORK_TAB_PARAMS_LABEL, new LightScrollPane(1, 1, 0, 0, networkTabParam)); networkDetailTabs.addTab( I18n.NETWORK_TAB_TIMING_LABEL, new LightScrollPane(1, 1, 0, 0, networkTabTiming)); DefaultCaret caret = (DefaultCaret) networkTabResponse.getCaret(); caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); caret = (DefaultCaret) networkTabSource.getCaret(); caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); caret = (DefaultCaret) networkTabPreview.getCaret(); caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); caret = (DefaultCaret) networkTabHeader.getCaret(); caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); caret = (DefaultCaret) networkTabCookie.getCaret(); caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); caret = (DefaultCaret) networkTabParam.getCaret(); caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); caret = (DefaultCaret) networkTabTiming.getCaret(); caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); networkTabHeader.setLineWrap(true); networkTabCookie.setLineWrap(true); networkTabParam.setLineWrap(true); networkTabResponse.setLineWrap(true); networkTabTiming.setLineWrap(true); networkTabSource.setLineWrap(true); networkTabPreview.setContentType("text/html"); networkTabPreview.setEditable(false); this.networkTable.getColumnModel().getColumn(0).setResizable(false); this.networkTable.getColumnModel().getColumn(0).setPreferredWidth(120); this.networkTable.getColumnModel().getColumn(0).setMinWidth(120); this.networkTable.getColumnModel().getColumn(0).setMaxWidth(120); this.networkTable.getColumnModel().getColumn(2).setResizable(false); this.networkTable.getColumnModel().getColumn(2).setPreferredWidth(45); this.networkTable.getColumnModel().getColumn(2).setMinWidth(45); this.networkTable.getColumnModel().getColumn(2).setMaxWidth(45); this.networkTable.getColumnModel().getColumn(3).setResizable(false); this.networkTable.getColumnModel().getColumn(3).setPreferredWidth(85); this.networkTable.getColumnModel().getColumn(3).setMinWidth(85); this.networkTable.getColumnModel().getColumn(3).setMaxWidth(85); this.networkTable .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent event) { // prevent double event if (!event.getValueIsAdjusting() && PanelBottom.this.networkTable.getSelectedRow() > -1) { networkTabHeader.setText( listHTTPHeader .get(PanelBottom.this.networkTable.getSelectedRow()) .getHeader()); networkTabCookie.setText( listHTTPHeader .get(PanelBottom.this.networkTable.getSelectedRow()) .getCookie()); networkTabParam.setText( listHTTPHeader.get(PanelBottom.this.networkTable.getSelectedRow()).getPost()); networkTabResponse.setText(""); for (String key : listHTTPHeader .get(PanelBottom.this.networkTable.getSelectedRow()) .getResponse() .keySet()) { networkTabResponse.append( key + ": " + listHTTPHeader .get(PanelBottom.this.networkTable.getSelectedRow()) .getResponse() .get(key)); networkTabResponse.append("\n"); } networkTabTiming.setText("?"); networkTabSource.setText( listHTTPHeader.get(PanelBottom.this.networkTable.getSelectedRow()).source); networkTabPreview.setText( "<html>" + listHTTPHeader.get(PanelBottom.this.networkTable.getSelectedRow()) .source + "</html>"); } } }); this.network.setRightComponent(networkDetailTabs); MediatorGUI.register(new AdapterBottomTabbedPane()); MediatorGUI.bottom().setBorder(BorderFactory.createEmptyBorder(1, 1, 0, 0)); MediatorGUI.bottom().setMinimumSize(new Dimension()); MediatorGUI.bottom() .addTab( "Console", new ImageIcon(getClass().getResource("/com/jsql/view/swing/images/console.gif")), new LightScrollPane(1, 1, 0, 0, this.consoleTab.getProxy()), I18n.CONSOLE_TAB_TOOLTIP); MediatorGUI.bottom() .setTabComponentAt( MediatorGUI.bottom().indexOfTab("Console"), new JLabel( I18n.CONSOLE_TAB_LABEL, new ImageIcon(getClass().getResource("/com/jsql/view/swing/images/console.gif")), SwingConstants.CENTER)); // Order is important Preferences prefs = Preferences.userRoot().node(InjectionModel.class.getName()); if (prefs.getBoolean(HelperGUI.JAVA_VISIBLE, false)) { this.insertJavaDebugTab(); } if (prefs.getBoolean(HelperGUI.NETWORK_VISIBLE, true)) { this.insertNetworkTab(); } if (prefs.getBoolean(HelperGUI.CHUNK_VISIBLE, true)) { this.insertChunkTab(); } if (prefs.getBoolean(HelperGUI.BINARY_VISIBLE, true)) { this.insertBinaryTab(); } MediatorGUI.bottom() .addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent arg0) { JTabbedPane tabs = MediatorGUI.bottom(); if (tabs.getSelectedIndex() > -1) { Component currentTabHeader = tabs.getTabComponentAt(tabs.getSelectedIndex()); if (currentTabHeader != null) { currentTabHeader.setFont(currentTabHeader.getFont().deriveFont(Font.PLAIN)); } } } }); this.setLayout(new OverlayLayout(this)); BasicArrowButton showBottomButton = new BasicArrowButton(BasicArrowButton.SOUTH); showBottomButton.setBorderPainted(false); showBottomButton.setPreferredSize(showBottomButton.getPreferredSize()); showBottomButton.setMaximumSize(showBottomButton.getPreferredSize()); showBottomButton.addActionListener(PanelLeftRightBottom.HIDESHOWPANEL); JPanel arrowDownPanel = new JPanel(); arrowDownPanel.setLayout(new BoxLayout(arrowDownPanel, BoxLayout.PAGE_AXIS)); arrowDownPanel.setOpaque(false); showBottomButton.setOpaque(false); // Disable overlap with zerosizesplitter arrowDownPanel.setBorder(BorderFactory.createEmptyBorder(1, 0, 0, 0)); arrowDownPanel.setPreferredSize(new Dimension(17, 27)); arrowDownPanel.setMaximumSize(new Dimension(17, 27)); arrowDownPanel.add(showBottomButton); this.add(arrowDownPanel); this.add(MediatorGUI.bottom()); // Do Overlay arrowDownPanel.setAlignmentX(1.0f); arrowDownPanel.setAlignmentY(0.0f); MediatorGUI.bottom().setAlignmentX(1.0f); MediatorGUI.bottom().setAlignmentY(0.0f); this.chunkTab.setLineWrap(true); this.binaryTab.setLineWrap(true); }