Status tab made

This commit is contained in:
Akarshit Wal
2015-07-12 21:50:03 +05:30
parent 2ffa83ff77
commit 4f588aadcc
4 changed files with 382 additions and 16 deletions
@@ -23,14 +23,20 @@ package processing.app.contrib;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.*;
import java.util.*;
import java.util.List;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import java.awt.*;
import javax.swing.border.*;
import processing.app.*;
import processing.app.ui.Editor;
import processing.app.ui.Toolkit;
@@ -86,13 +92,14 @@ public class ContributionTab {
filter = type.createFilter();
}
this.statusPanel = new StatusPanel(450,this);
this.contributionType = type;
this.contributionManagerDialog = contributionManagerDialog;
contribListing = ContributionListing.getInstance();
if (contributionType == null) {
contributionListPanel = new UpdateContribListingPanel(this, filter);
statusPanel = new UpdateStatusPanel(450, this);
} else {
statusPanel = new StatusPanel(450,this);
contributionListPanel = new ContributionListPanel(this, filter);
}
contribListing.addContributionListener(contributionListPanel);
@@ -199,14 +206,20 @@ public class ContributionTab {
layout.setAutoCreateGaps(true);
layout.setHorizontalGroup(layout
.createParallelGroup(GroupLayout.Alignment.CENTER)
.addGroup(layout.createSequentialGroup().addComponent(categoryLabel)
.addComponent(categoryChooser).addComponent(filterField))
.addGroup(layout.createSequentialGroup()
.addComponent(filterField)
.addComponent(categoryChooser, GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addComponent(loaderLabel).addComponent(contributionListPanel)
.addComponent(errorPanel).addComponent(statusPanel));
layout.setVerticalGroup(layout
.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER)
.addComponent(categoryLabel).addComponent(categoryChooser)
.addGroup(layout
.createParallelGroup(GroupLayout.Alignment.CENTER)
.addComponent(categoryChooser, GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE)
.addComponent(filterField))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER)
.addComponent(loaderLabel)
@@ -214,6 +227,7 @@ public class ContributionTab {
.addComponent(errorPanel)
.addComponent(statusPanel, GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE));
layout.linkSize(SwingConstants.VERTICAL, categoryChooser, filterField);
layout.setHonorsVisibility(contributionListPanel, false);
}
@@ -319,8 +333,7 @@ public class ContributionTab {
categoriesFound = true;
}
}
//TODO: a really ugly hack to solve focus problem
// categoryChooser.setEnabled(categoriesFound);
categoryChooser.setEnabled(categoriesFound);
}
}
@@ -395,15 +408,27 @@ public class ContributionTab {
// }
//TODO: this is causing a lot of bugs as the hint is wrongly firing applyFilter()
class FilterField extends JTextField {
class FilterField extends JPanel {
JTextField searchField;
JButton searchButton;
String filterHint;
boolean showingHint;
List<String> filters;
public FilterField () {
super(Language.text("contrib.filter_your_search"));
filterHint = Language.text("contrib.filter_your_search");
searchField = new JTextField(Language.text("contrib.filter_your_search"));
filterHint = Language.text("contrib.filter_your_search");
searchButton = new JButton("S");
ComponentBorder cb = new ComponentBorder(searchButton,"LEFT");
cb.install( searchField);
GroupLayout layout = new GroupLayout(this);
setLayout(layout);
layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(searchField));
layout.setVerticalGroup(layout.createParallelGroup().addComponent(searchField));
showingHint = true;
filters = new ArrayList<String>();
updateStyle();
@@ -425,7 +450,7 @@ public class ContributionTab {
}
});
getDocument().addDocumentListener(new DocumentListener() {
searchField.getDocument().addDocumentListener(new DocumentListener() {
public void removeUpdate(DocumentEvent e) {
applyFilter();
}
@@ -439,7 +464,7 @@ public class ContributionTab {
}
});
}
public void applyFilter() {
String filter = filterField.getFilterText();
filter = filter.toLowerCase();
@@ -456,6 +481,14 @@ public class ContributionTab {
return showingHint ? "" : getText();
}
public String getText() {
return searchField.getText();
}
public void setText(String text) {
searchField.setText(text);
}
public void updateStyle() {
if (showingHint) {
setText(filterHint);
@@ -477,4 +510,293 @@ public class ContributionTab {
public void updateStatusPanel(ContributionPanel contributionPanel) {
statusPanel.update(contributionPanel);
}
/**
* The ComponentBorder class allows you to place a real component in
* the space reserved for painting the Border of a component.
*
* This class takes advantage of the knowledge that all Swing components are
* also Containers. By default the layout manager is null, so we should be
* able to place a child component anywhere in the parent component. In order
* to prevent the child component from painting over top of the parent
* component a Border is added to the parent componet such that the insets of
* the Border will reserve space for the child component to be painted without
* affecting the parent component.
*/
public class ComponentBorder implements Border
{
static final String TOP = "TOP";
static final String LEFT = "LEFT";
static final String BOTTOM = "BOTTOM";
static final String RIGHT = "RIGHT";
public static final float LEADING = 0.0f;
public static final float CENTER = 0.5f;
public static final float TRAILING = 1.0f;
private JComponent parent;
private JComponent component;
private String edge;
private float alignment;
private int gap = 5;
private boolean adjustInsets = true;
private Insets borderInsets = new Insets(0, 0, 0, 0);
/**
* Convenience constructor that uses the default edge (Edge.RIGHT) and
* alignment (CENTER).
*
* @param component the component to be added in the Border area
*/
public ComponentBorder(JComponent component)
{
this(component, RIGHT);
}
/**
* Convenience constructor that uses the default alignment (CENTER).
*
* @param component the component to be added in the Border area
* @param edge a valid Edge enum of TOP, LEFT, BOTTOM, RIGHT
*/
public ComponentBorder(JComponent component, String edge)
{
this(component, edge, CENTER);
}
/**
* Main constructor to create a ComponentBorder.
*
* @param component the component to be added in the Border area
* @param edge a valid Edge enum of TOP, LEFT, BOTTOM, RIGHT
* @param alignment the alignment of the component along the
* specified Edge. Must be in the range 0 - 1.0.
*/
public ComponentBorder(JComponent component, String edge, float alignment )
{
this.component = component;
component.setSize( component.getPreferredSize() );
component.setCursor(Cursor.getDefaultCursor());
setEdge( edge );
setAlignment( alignment );
}
public boolean isAdjustInsets()
{
return adjustInsets;
}
public void setAdjustInsets(boolean adjustInsets)
{
this.adjustInsets = adjustInsets;
}
/**
* Get the component alignment along the Border Edge
*
* @return the alignment
*/
public float getAlignment()
{
return alignment;
}
/**
* Set the component alignment along the Border Edge
*
* @param alignment a value in the range 0 - 1.0. Standard values would be
* CENTER (default), LEFT and RIGHT.
*/
public void setAlignment(float alignment)
{
this.alignment = alignment > 1.0f ? 1.0f : alignment < 0.0f ? 0.0f : alignment;
}
/**
* Get the Edge the component is positioned along
*
* @return the Edge
*/
public String getEdge()
{
return edge;
}
/**
* Set the Edge the component is positioned along
*
* @param edge the Edge the component is position on.
*/
public void setEdge(String edge)
{
this.edge = edge;
}
/**
* Get the gap between the border component and the parent component
*
* @return the gap in pixels.
*/
public int getGap()
{
return gap;
}
/**
* Set the gap between the border component and the parent component
*
* @param gap the gap in pixels (default is 5)
*/
public void setGap(int gap)
{
this.gap = gap;
}
//
// Implement the Border interface
//
public Insets getBorderInsets(Component c)
{
return borderInsets;
}
public boolean isBorderOpaque()
{
return false;
}
/**
* In this case a real component is to be painted. Setting the location
* of the component will cause it to be painted at that location.
*/
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
{
float x2 = (width - component.getWidth()) * component.getAlignmentX() + x;
float y2 = (height - component.getHeight()) * component.getAlignmentY() + y;
component.setLocation((int)x2, (int)y2);
}
/*
* Install this Border on the specified component by replacing the
* existing Border with a CompoundBorder containing the original Border
* and our ComponentBorder
*
* This method should only be invoked once all the properties of this
* class have been set. Installing the Border more than once will cause
* unpredictable results.
*/
public void install(JComponent parent)
{
this.parent = parent;
determineInsetsAndAlignment();
// Add this Border to the parent
Border current = parent.getBorder();
if (current == null)
{
parent.setBorder(this);
}
else
{
CompoundBorder compound = new CompoundBorder(current, this);
parent.setBorder(compound);
}
// Add component to the parent
parent.add(component);
}
/**
* The insets need to be determined so they are included in the preferred
* size of the component the Border is attached to.
*
* The alignment of the component is determined here so it doesn't need
* to be recalculated every time the Border is painted.
*/
private void determineInsetsAndAlignment()
{
borderInsets = new Insets(0, 0, 0, 0);
// The insets will only be updated for the edge the component will be
// diplayed on.
//
// The X, Y alignment of the component is controlled by both the edge
// and alignment parameters
if (edge.equals("TOP"))
{
borderInsets.top = component.getPreferredSize().height + gap;
component.setAlignmentX(alignment);
component.setAlignmentY(0.0f);
}
else if (edge.equals("BOTTOM"))
{
borderInsets.bottom = component.getPreferredSize().height + gap;
component.setAlignmentX(alignment);
component.setAlignmentY(1.0f);
}
else if (edge.equals("LEFT"))
{
borderInsets.left = component.getPreferredSize().width + gap;
component.setAlignmentX(0.0f);
component.setAlignmentY(alignment);
}
else if (edge.equals("RIGHT"))
{
borderInsets.right = component.getPreferredSize().width + gap;
component.setAlignmentX(1.0f);
component.setAlignmentY(alignment);
}
if (adjustInsets)
adjustBorderInsets();
}
/*
* The complimentary edges of the Border may need to be adjusted to allow
* the component to fit completely in the bounds of the parent component.
*/
private void adjustBorderInsets()
{
Insets parentInsets = parent.getInsets();
// May need to adust the height of the parent component to fit
// the component in the Border
if (edge.equals("RIGHT") || edge.equals("LEFT"))
{
int parentHeight = parent.getPreferredSize().height - parentInsets.top - parentInsets.bottom;
int diff = component.getHeight() - parentHeight;
if (diff > 0)
{
int topDiff = (int)(diff * alignment);
int bottomDiff = diff - topDiff;
borderInsets.top += topDiff;
borderInsets.bottom += bottomDiff;
}
}
// May need to adust the width of the parent component to fit
// the component in the Border
if (edge.equals("TOP") || edge.equals("BOTTOM"))
{
int parentWidth = parent.getPreferredSize().width - parentInsets.left - parentInsets.right;
int diff = component.getWidth() - parentWidth;
if (diff > 0)
{
int leftDiff = (int)(diff * alignment);
int rightDiff = diff - leftDiff;
borderInsets.left += leftDiff;
borderInsets.right += rightDiff;
}
}
}
}
}
@@ -41,7 +41,7 @@ import processing.app.Base;
class StatusPanel extends JPanel {
final int BUTTON_WIDTH = 20;
final int BUTTON_WIDTH = 150;
JTextPane label;
JButton installButton;
@@ -55,7 +55,6 @@ class StatusPanel extends JPanel {
ContributionTab contributionTab;
public StatusPanel(int width, final ContributionTab contributionTab) {
final int BUTTON_WIDTH = 150;
this.contributionTab = contributionTab;
label = new JTextPane();
label.setEditable(false);
@@ -154,6 +153,10 @@ class StatusPanel extends JPanel {
}
public StatusPanel() {
// TODO Auto-generated constructor stub
}
void setMessage(String message) {
label.setForeground(Color.BLACK);
label.setText(message);
@@ -13,8 +13,6 @@ import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
@@ -0,0 +1,43 @@
package processing.app.contrib;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.LayoutStyle;
public class UpdateStatusPanel extends StatusPanel {
public UpdateStatusPanel(int width, final ContributionTab contributionTab) {
super();
updateButton = new JButton("Update All");
updateButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
for(ContributionPanel contributionPanel : contributionTab.contributionListPanel.panelByContribution.values()){
contributionPanel.update();
}
}
});
layout = new GroupLayout(this);
this.setLayout(layout);
layout.setAutoCreateContainerGaps(true);
layout.setAutoCreateGaps(true);
layout.setHorizontalGroup(layout
.createSequentialGroup()
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED,
GroupLayout.PREFERRED_SIZE, Short.MAX_VALUE)
.addComponent(updateButton));
layout.setVerticalGroup(layout.createParallelGroup()
.addComponent(updateButton));
updateButton.setVisible(true);
}
@Override
public void update(ContributionPanel panel) {
}
}